Raspberry Pi Pico
Analog IN - Potentiometer
A potentiometer is a simple way to check how to read analog components. I have connected this one 3V3, GND and the middle pin to GP26.
Here is the Fritzing diagram showing that,
In the first program, I just get and print a simple reading from the ADC.
import board from time import sleep from analogio import AnalogIn pot = AnalogIn(board.GP26) while True: print(pot.value) sleep(1)
This program converts that to a voltage level.
import board from time import sleep from analogio import AnalogIn pot = AnalogIn(board.GP26) voltage_converter = 3.3 / 65535 while True: volts = round(pot.value * voltage_converter,1) print(str(volts) + "V") sleep(1)
In this final program, I just want to have a byte representing the reading.
import board from time import sleep from analogio import AnalogIn pot = AnalogIn(board.GP26) while True: reading = pot.value // 256 print(reading) sleep(1)
Most potentiometers are not going to give you guite the full range of values that an ADC could theoretically read. The rounding in the last program might give you a value that you can make more use of in your project.