In this lesson, we will create a simple project to make the onboard LED on your Raspberry Pi Pico blink. To begin, connect your Raspberry Pi Pico W to your computer using a micro USB cable.
To connect your Raspberry Pi Pico W to your computer, follow these steps:
Note: If you want to connect your Pico in USB mass storage device mode (so you can copy files to it), hold down the BOOTSEL button as you are connecting the USB to your computer.
To connect your Raspberry Pi Pico W to your iPad, follow these steps:
Open the Thonny editor on your computer.
The Thonny editor is the software you can use to program your Raspberry Pi devices using the MicroPython language.
Visit the Thonny website and download the appropriate version for your operating system. Follow the installation instructions provided on the website.
Once installed, open the Thonny editor. You are now ready to start programming!
An interpreter is a program that reads and executes code written in a programming language. We need to select the interpreter to ensure that Thonny understands and runs the code correctly for our specific hardware.
In this case, we need to select 'MicroPython (Raspberry Pi Pico)' as the interpreter for the Raspberry Pi Pico W.
An interpreter is a program that reads and executes code written in a programming language. We need to select the interpreter to ensure that Thonny understands and runs the code correctly for our specific hardware.
Look at the text in the bottom right-hand corner of the Thonny editor. It will show you the version of Python that is being used.
To select which interpreter to use, click on the text and select the interpreter you want from the options.
Create a new file in Thonny and save it with the name 'blink.py'.
To create a new file in Thonny, click 'File' > 'New'. This will open up a new tab in Thonny where you can code your new file.
To save a file in Thonny, click 'File' > 'Save' and save the file on your computer.
In this step, you will import the necessary libraries for your project. A library is a collection of pre-written code that you can use to perform specific tasks. By importing libraries, you can save time and effort, as you don't have to write the code from scratch.
Type the following lines of code to import the necessary libraries:
from machine import Pin
import time
from picozero import pico_led
Here's what each library does:
machine
: This library provides access to the hardware components of your Raspberry Pi Pico, such as the pins and the onboard LED.time
: This library allows you to add delays in your code, which you'll use to control the blinking speed of the LED.picozero
: This library contains functions specifically designed for the Raspberry Pi Pico, such as controlling the onboard LED.