Rasberry Pi Pico
Description of the practice: The following laboratory consists on a Rasberry Pi Pico card in which, through the Thonny language, a LED is intended to be turned on in 3 different ways (LED intensity by time, Control LED brightness with PW and Control an LED with an analogue input.
Parts of a Rasberry Pi Pico
First we need to conect the card by USB cable to your computer, after this we configure your Rasberry Pico Pi onece the computer had recognized it. , we configure R.P. on Thonny Window. We select it and install de copy frimware.
We verify by creating a machine Pin object to correspond with the onboard LED, which can be accessed using GPIO pin 25.
Methods
LED Intensity (Timer): By the Thonny Lenguage we control de light Intensity and the time in which it turn on and off the LED. We use the Timer module to set a timer that runs a function at regular intervals.
Connect your Rasberry, Board and LED like following figure bellow.
Once we connectated our system, we put Thonny on by the following code:
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)
led = Pin(15, Pin.OUT)
timer = Timer()
def blink(timer):
led.toggle()
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
We run the program and the LED started to blink. If it was not working, we wiring to be sure that the LED is connected.
2. Control LED brightness with PW: In this point we made the same process like step 1. The only difference is that you will use a button.
We connected the system like the image bellow:
And we add the following code on the Thonny program:
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)
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)
3. Control LED with an analoge input: Our Raspberry Pi Pico has an input pins that can receive analogue signals. This means that instead of only reading the values of 1 and 0 (on and o!), it can read values in between.
We replace the button on our circuit with a potentiometer. Follow the wiring diagram below to connect it to an analogue pin.