Raspberry Pi Pico – Lesson 1: Pico Led flashing.
This RPi Pico project is perfect to get started with the Thonny programming tool and MicroPython.
You will learn to connect the Pico to your PC and install programs on it.
In this lesson we are going to flash the internal small LED on the pico. (This is located right next to the USB connection on the Pico.)
This manual covers:
- Level - Beginner 25% 25%
- Duration 15 min 25% 25%
- Costs €8,95 10% 10%
Having an Raspberry Pi Pico is a microcontrollerboard which was developed by the same organization responsible for the popular Raspberry Pi single-board computers.
Some features of the Raspberry Pi Pico are:
- RP2040 microcontroller: The Pico is powered by the RP2040 microcontroller, which is specially designed by Raspberry Pi. This microcontroller has a dual-core ARM Cortex-M0+ processor and offers significant computing power for a microcontroller.
- I/O pins: The Pico has a large number of GPIO (General Purpose Input/Output) pins, with which you can connect and operate sensors, displays, motors and other electronic components.
- USB connection: The Pico has a USB port for programming and powering the board. It can be programmed with MicroPython, C/C++, and other programming languages.
- Versatility: Thanks to the powerful RP2040 and the many I/O pins, the Pico is suitable for a wide range of projects, from simple flashing LEDs to complex IoT applications.
- Low costs: From Raspberry Pi Pico is very affordable and therefore accessible to hobbyists, makers and professionals.
Step 1: Supplies:
Step 2: Install software
Around the Raspberry PiTo be able to program with MicroPython, we must first flash the firmware of the Pico.
This means that we provide the internal software that starts the pico with a special Python version.
Download firmware from the website below (uf2 file)
(Make sure you select the correct version of the firmware, the WiFi version and the non-WiFi version are different)
Press the white boot button on the pico and keep it pressed.
Plug the pico into a USB port on your computer. (Then you can release the button)
There will now be a drive letter, as accessible with a memory stick.
Copy the firmware file RPI_PICO_xxxxxx.uf2 to this drive
(pico will restart and the firmware will be installed)
Download and install Thonny on your PC.
Select the MicroPython Interpreter below
Tools > Options > Interpreter > MicroPython (Raspberry Pi Pico)
Step 3: Programming
Now you can type in the program below in the Thonny interface.
Caution: For the Pico-W, the variable 'GP25' must be changed to 'LED'.
Explanation of the program:
- The machine module contains specific functions related to the hardware on a particular board.
Such as the pin function used in this case.
- The utime module offers functions for the current time and date, measuring time intervals and for delays.
- Define a variable led_onboard which selects GP25 pin and sets it as output.
- This is the start of an infinite loop that continues to execute the commands below it.
- Here is the command to turn on the LED. This is the variable name of line 4 with the addition .on()
- This line waits 1 second.
- The command to turn the LED off again.
- After switching off, wait another 1 second.
from machine import Pin
led_onboard = Pin('LED', Pin.OUT)
Then press save and save the program on your own computer.
Press the red stop sign button to restart the backend.
(Thonny will now reconnect to your Pico)
Then you could press the green button (Run current script).
The LED should now flash. One second off and one second on.
If the pico is now removed from the computer and reconnected, the program will not be started.
We only tested the programming code.
To enable automatic starting, we must save the program again, but then select the pico.
File > Save As > Raspberry Pi Pico
Save the program with its name main.py. The pico will automatically start the program with this name when connecting the Pico to a USB port or other power supply.
Step 4: Result
You now have Thonny installed and a Raspberry Pico connected to your PC. Then wrote and executed the code.
Is the LED not flashing? Then take a look at the previous steps and try again!
Did you enjoy doing this project? Take a look at our other projects, or Lesson two of this Pico series!