Skip to content

Instantly share code, notes, and snippets.

@scruss
Created February 12, 2021 01:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scruss/ba3d3b33b99850c322f5b6e301591aff to your computer and use it in GitHub Desktop.
Save scruss/ba3d3b33b99850c322f5b6e301591aff to your computer and use it in GitHub Desktop.
# 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)
@Proberdude
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.

scruss_potentiometer.mp4

@scruss
Copy link
Author

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