Hello readers, I hope you all are doing great. In our previous tutorials on raspberry pi Pico, we discussed the basic features, architecture, download and installation of development environments for raspberry Pi Pico programming. In this tutorial, we will learn how to access and control Raspberry Pi Pico and its GPIO pins to implement LED blinking using MicroPython.
Raspberry Pi development boards are quite popular and frequently used among students and hobbyists. But the drawback of Raspberry Pi is their cost i.e., around $35-$45. So when cost of the development board is of prime importance the users prefer to use ESP8266, ESP32, Arduino, PIC etc. over Raspberry Pi. To overcome this drawback, Raspberry Pi foundations designed a new board i.e., Raspberry Pi Pico which is a cost effective solution for costlier Raspberry Pi boards.
Raspberry Pi Pico is a cost-effective development platform designed by Raspberry Pi which has enough processing power to handle complex task. It is a low cost and yet powerful microcontroller board with RP2040 silicon chip.
We have already published tutorials on how to download and install the above mentioned software components.
Follow the given link for detailed study of Raspberry Pi Pico: https://www.theengineeringprojects.com/2022/04/getting-started-with-raspberry-pi-pico.html
We have already published a tutorial on installing Thonny IDE for Raspberry Pi Pico Programming. Follow the given link to install the IDE: https://www.theengineeringprojects.com/2022/04/installing-thonny-ide-for-raspberry-pi-pico-programming.html
The Raspberry Pi Pico board comes with an onboard LED which is internally connected with GPIO 25. So first we will discuss how to access the on board LED and then will interface an external one.
Fig.
Steps included in programming the Raspberry Pi Pico to make the onboard LED to blink are:
“from machine import Pin, Timer”
“led = Pin(25, Pin.OUT)”
“ led.toggle()”
Fig. Save the program
Fig. Run the code
Note: If you are already running a program on Raspberry Pi Pico board then press ‘Stop’ before running a new program.
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)
Fig. Blinking On-board LED
Table 1
Fig. Iterfacing LED with Raspberry Pi Pico
Steps included in programming the Raspberry Pi Pico to make the peripheral LED to blink are:
“from machine import Pin”
“import time”
Create an object ‘led’ from pin14 and set GPIO pin14 to output.
“led=Pin(14,Pin.OUT)”
“while True:"
“led.value(1)”
“time.sleep(1)”
“led.value(0)”
Fig. Interfacing and Blinking LED with raspberry Pi Pico
from machine import Pin, time
led=Pin(14,Pin.OUT) #Creating LED object from pin14 and Set Pin 14 to output
while True:
led.value(1) #Set led turn ON
time.sleep(1)
led.value(0) #Set led turn OFF
time.sleep(1)
This concludes the tutorial, we hope you find this of some help and also hope to see you soon with a new tutorial on Raspberry Pi Pico programming.