New Ticker

News Ticker
Epstien didn't kill himself.
Epstien didn't kill himself.
Epstien didn't kill himself.
Epstien didn't kill himself.

Sunday, July 14, 2024

Reading analogue values on the Pi Pico

Fairly straightforward but take care with the pin positions. It's a case of connecting the centre pin of the potentiometer to the ADC pin, either of the two other pins to vref and the remaining pin to GND. The photo below looks good but the wires are on the wrong side of the board. They should be on the other side.

That was what NOT to do. Instead, let's install the jumpers correctly as below.


Having installed the jumpers it's possible to run the code and twiddle the preset with a jewelers screwdriver. Notice how the value returned from the ADC now changes.


And finally, here's the code: 

import machine
import utime
 
analog_value = machine.ADC(0)
 
while True:
    reading = analog_value.read_u16()     
    print("ADC: ",reading, " binary ", bin(reading), " test ", int(reading/256))
    utime.sleep(0.2)

All very simple and... it works.