Low Orbit Flux Logo 2 D

Raspberry Pi Pico - Demo

Raspberry Pi Pico - Demo

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:

Raspberry Pi Pico with on board LED 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 ):

Raspberry Pi Pico with external LED Blinking

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:

Raspberry Pi Pico with 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:

Raspberry Pi Pico with LED, button, and potentiometer

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 Images

Raspberry_pi_pico_demo_6391 Raspberry_pi_pico_demo_6392 Raspberry_pi_pico_demo_6424 Raspberry_pi_pico_demo_6425 Raspberry_pi_pico_demo_6426 Raspberry_pi_pico_demo_6428 Raspberry_pi_pico_demo_6429 Raspberry_pi_pico_demo_6430 Raspberry_pi_pico_demo_6431 Raspberry_pi_pico_demo_6432 Raspberry_pi_pico_demo_6434 Raspberry_pi_pico_demo_6435 Raspberry_pi_pico_demo_6436

References