In this article, we’ll use the Raspberry Pi Pico to run a basic LED flashing application. The Raspberry Pi Pico is based on the RP4060 microcontroller chip, which is the Raspberry Pi Foundation’s first microcontroller family class. The Pico board is the perfect choice if you’re looking for a low-cost development board with high-performance capabilities. Because it provides basic debugging tools and libraries for C/C++ development and a Micropython environment, we can programme this Pico board in a variety of ways. I’ll show you how to use the Micropython framework to programme the Pico board.
Connecting LED with Raspberry PI Pico
The following schematic diagram can be referring to connecting an LED with Raspberry Pi Pico. I connected the LED to the GPIO 1 or Pin number 2 and the GND pin is connected to the Ground.
Installation of Thonny IDE and MicroPython Framework On Raspberry Pi Pico
At first, you need to install the Thonny IDE to program the Raspberry Pi Pico. When the installation has been completed we need to perform some basic setup of the Thonny IDE. The following Picture is a snapshot of the Thonny IDE. In the picture, you can see the red circled section has the basic debugging tools. The green section is for selecting the device or python version we are using. This can be called an interpreter selection menu.
Now you need to follow the below steps to install the Micropython framework on Raspberry Pi Pico. On the Pico board, you can see a White Push Button that is marked as “BOOTSEL”.
The BOOTSEL button on my board is shown above-highlighted red. Press the button and hold it until you connect the Pico board to the PC or Laptop via USB port. When you will connect the Pico board you can see under the Interpreter selection menu “MicroPython (Raspberry Pi Pico)”. Click on this and follow the installation as per instructed on the window.
You can now use the code below to blink an LED on the Raspberry Pi Pico. The code is really easy to comprehend. In MicroPython, we have a machine library that contains all of the core built-in libraries. To create an object, use the Pin() function. In my situation, I used “lead” in the code below to create an object. I used the Led and Pin.OUT parameters in the Pin() function to represent the GPIO pin and the Pin.OUT parameter to configure the GPIO pin as an OUTPUT pin, respectively. It can be turned on or off. The Timer() function allows us to use the Raspberry Pi Pico’s built-in timer.
from machine import Pin, Timer
Led = 0
led = Pin(Led, Pin.OUT)
timer = Timer()
Now, we need to create a function ledblink() to provide the timer. Actually the Timer() has an in-built method named as init(). In this init() method, we can callback a function with some delay. This delay can be provided as “PERIODIC” by using the “mode” parameter. The “freq” parameter is used to determine the frequency delay of each callback. The led.toggle() is used to change the state of the led from HIGH to LOW or LOW to HIGH.
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=ledblink)
Now, let’s save the code. When you save the code, it will show you a popup as shown below, asking where you want to save the file. You need to select Raspberry Pi Pico and then name the file as “main.py” and click on save. By doing this procedure, the Raspberry Pi Pico will run the program when it is power up.
Running our first Blink Program on Pico
So, we have finished our first Raspberry Pi Pico tutorial.
from machine import Pin, Timer inbuiltLed = 25 led = Pin(inbuiltLed, Pin.OUT) timer = Timer() def ledblink(timer): led.toggle() timer.init(freq=2.5, mode=Timer.PERIODIC, callback=ledblink)