Skip to content

Instantly share code, notes, and snippets.

Created February 12, 2021 01:27
What would you like to do?
# micropython for raspberry pi pico
# potentiometer between AGND and 3V3, with the wiper going to ADC pin 2
# prints 0-100 depending on how far potentiometer is turned
# 3 columns so the Thonny plotter will scale correctly
from machine import Pin, ADC
from time import sleep
led = Pin(25, Pin.OUT)
adc = ADC(2)
while True:
v = adc.read_u16()
print('0.0 %10.5f 100.0' % (100 * float(v)/65535))
Copy link

Thanks Scruss,
It worked. I used a B100k digikey and the printed result varied from ~ 0.45 to 1.68 turning the nub all the way around.


Copy link

scruss commented Feb 13, 2021

You've only got two wires, so your potentiometer is a only variable resistor. It should give output from 0–100 when turned the full range
The wiring should look like this:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment