Pico W GPIO & PWM Cheatsheet

Pico W GPIO & PWM Cheatsheet

Pin modes, ADC, PWM duty cycles, and interrupts at a glance.

Digital I/O
Pin(n, Pin.OUT) Create output pin on GPIO n
Pin(n, Pin.IN, Pin.PULL_UP) Input with internal pull-up (reads 1 when open)
pin.on() / pin.off() Set pin HIGH or LOW
pin.toggle() Flip the current output state
pin.value() Read current pin state (0 or 1)
ADC
ADC(26) Create ADC on GPIO 26 (ADC0)
adc.read_u16() Read ADC ߀” returns 0 to 65535 (16-bit)
raw * (3.3 / 65535) Convert to voltage
ADC(4) ߀” internal temp sensor Reads CPU die temperature via formula
PWM
PWM(Pin(15)) Create PWM on GPIO 15
pwm.freq(1000) Set PWM frequency in Hz
pwm.duty_u16(32768) 50% duty cycle (0 = off, 65535 = full on)
pwm.deinit() Release the PWM channel and free the pin
Interrupts
pin.irq(trigger=Pin.IRQ_FALLING, handler=fn) Attach interrupt on falling edge
Pin.IRQ_RISING Trigger on LOW ߆’ HIGH transition
Pin.IRQ_FALLING Trigger on HIGH ߆’ LOW transition
Keep ISRs short Do minimal work in ISR ߀” set a flag and handle in main loop