Skip to content

Instantly share code, notes, and snippets.

Embed
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))
led.toggle()
sleep(0.1)
@scruss

This comment has been minimized.

@Proberdude

This comment has been minimized.

Copy link

@Proberdude Proberdude commented Feb 12, 2021

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.

scruss_potentiometer.mp4
@scruss

This comment has been minimized.

Copy link
Owner Author

@scruss 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:

https://scruss.com/wordpress/wp-content/uploads/2021/02/PicoPot_bb.png

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