Raspberry Pi Pico - Demo
- If you want to know how to solder the pins on a Raspberry Pi Pico just scroll down to the video section. One of the videos shows how we acheived that.
- Most/all of the code snippets on this page are either copied from or based on the official Raspberry Pi website ( see the link in the references section ).
Onboard LED
Enable onboard LED (pin 25):
from machine import Pin
led = Pin(25, Pin.OUT)
led.value(1)
This is what the onboard LED looks like when lit / blinking:
Toggle it:
from machine import Pin
led = Pin(25, Pin.OUT)
led.toggle()
Blink the onboard LED (pin 25):
from machine import Pin, Timer
led = Pin(25, Pin.OUT)
timer = Timer()
def blink(timer):
led.toggle()
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
External LED
Blink an external LED on pin 15 led. This uses a timer which calls a callback function at a defined frequency.
from machine import Pin, Timer
led = Pin(15, Pin.OUT)
timer = Timer()
def blink(timer):
led.toggle()
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
This is what it looks like using an external LED ( pin 15 ):
Blink BOTH LEDs:
from machine import Pin, Timer
led1 = Pin(25, Pin.OUT)
led2 = Pin(15, Pin.OUT)
timer = Timer()
def blink(timer):
led1.toggle()
led2.toggle()
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
Using a Button
Using a button to toggle the LED:
from machine import Pin
import time
led = Pin(15, Pin.OUT)
button = Pin(14, Pin.IN, Pin.PULL_DOWN)
while True:
if button.value():
led.toggle()
time.sleep(0.5)
This is what it looks like with a LED and button:
PWM - Pulse Width Modulation
Using pulse width modulation to controle the brightness of the LED:
from machine import Pin, PWM
from time import sleep
pwm = PWM(Pin(15))
pwm.freq(1000)
while True:
for duty in range(65025):
pwm.duty_u16(duty)
sleep(0.0001)
for duty in range(65025, 0, -1):
pwm.duty_u16(duty)
sleep(0.0001)
ADC Module and Potentiometer
Using a potentiometer and ADC module to control brightness.
from machine import Pin, PWM, ADC
pwm = PWM(Pin(15))
adc = ADC(Pin(26))
pwm.freq(1000)
while True:
duty = adc.read_u16()
pwm.duty_u16(duty)
This is what it looks like with a potentiometer, button, and external LED:
Videos
Demo projects video showing how to blink a LED, use a button, install MicroPython, etc.
How to solder the pins on a Raspberry Pi Pico:
Where to Buy Everything
These are affiliate links showing where you can buy everything you need:
- Raspberry Pi Pico Basic Kit on Amazon
- Electronic components kit on Amazon
- AUSTOR 6 Pack 60-40 Rosin Core Solder on Amazon
- KOTTO Helping Hands Soldering Tool PCB Holder on Amazon
- Hakko FX888D-23BY Digital Soldering Station FX-888D FX-888 on Amazon
- Lesnow solder wick braid with flux Super on Amazon