Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8035

MicroPython • Re: asyncio and bluetooth on pico

$
0
0
I tried directly sending the reading from the function which measures the voltage, but it still only appears to be sent when a button is pressed.

Logically if you can place the battery reading in a queue, and when the queue is read (in your code snippet the queue is only read when a button is pressed`) then the read message is sent, it seems you should be able to use the same send logic on the very same message in your battery function.

Of course you could also remove the sending of 'stuff' in the queue to a separate function as also suggested and separate the send_data_task from the button reading tasks.

But a peruse of the read_voltage function, and sorry I did not really read the code in my earlier reply, I see many flaws. You should not continually set the ADC pins etc in a while loop, this should be done only once and program startup. You should not be reading the ADC VREF pin, which is used to set a reference voltage, but the battery should be read via an ADC pin to which the battery is connected by a voltage divider to ensure you never exceed connecting more than 3.3v to a pin, or puff goes your pico. I'm not sure what you were intending with the
machine.Pin(29, machine.Pin.IN)
To use an AOC pin then something like bat_pin = machine.ADC(26) is the sort of thing thats required.
As for machine.Pin(25 ..... were you intending to flash the onboard LED ? Of course pin 25 wont work with a picoW. But whatever, don't put this sort of set up logic in a while loop.

I suggest step at a time. Just get a battery read going with print statements to start with. Confirm its working by connecting up something that drains your battery in a quick time to check your battery read logic is actually working correctly, perhaps by comparing with a multimeter, though don't expect the ADC reading to be anywhere close to accurate. (reading the ADC VREF pin as you are will give a reading, but don't expect it to be the referencing the battery voltage.). Once thats working properly the next step is to send this voltage data via bluetooth. I would not complicate this with getting it to work with your main quiz button press until it works on its own.

Anyway, just some observations and suggestions which I hope may be of some help and good luck with your program, just a bit more tweaking and I'm sure it will end up a gem.

Statistics: Posted by SirFico — Tue Feb 24, 2026 11:17 pm



Viewing all articles
Browse latest Browse all 8035

Trending Articles