Let's read an analog signal!
For this, we'll use a small 10k trim pot to set up a voltage divider. Here's the wiring diagram:
And here's the code:
import time
import board
import analogio
knob = analogio.AnalogIn(board.ADC0)
def get_voltage(raw):
return (raw * 3.3) / 65536
while True:
raw = knob.value
volts = get_voltage(raw)
print("raw = {:5d} volts = {:5.2f}".format(raw, volts))
time.sleep(0.5)
Spin the knob and the values should change.
Note that even though the Pico's ADC is 12 bits, the value is scaled to 16 bits to comply with the CircuitPython API.
Page last edited March 08, 2024
Text editor powered by tinymce.