This is a comprehensive guide on getting started with Raspberry Pi Pico & Pico W using MicroPython. This detailed guide will provide step-by-step instructions to connect and upload code to Pico. At the end of this Raspberry Pi Pico tutorial, you shall learn how to blink the onboard LED in Raspberry Pi Pico using MicroPython. Pi Pico can also be programmed using C/C++.
This tutorial is written for Windows OS and will demonstrate the process of uploading MicroPython code using two IDEs:
- Thonny IDE.
- uPyCraft IDE.
The instructions here will work with all variants of Raspberry Pi Pico at the time of writing this article:
- Raspberry Pi Pico 2020(First variant) / Raspberry Pi Pico H.
- Raspberry Pi Pico W / Raspberry Pi Pico WH.
The ‘H’ stands for “Headers” and these two boards come with pin headers pre-soldered.
If you are using macOS, visit our article How To Program Raspberry Pi Pico On macOS Using Thonny IDE.
Raspberry Pi Pico Specifications & Overview
Raspberry Pi Pico is a development board based on the RP2040 microcontroller, a dual-core Arm Cortex M0+ processor. It has 264kB on-chip SRAM in six independent banks and 2MB of flash memory. The flash memory can be extended using a dedicated QSPI bus.
It also features an onboard temperature sensor, not seen in other boards in this segment. To know more on how to read the onboard temperature sensor, you can visit our article Raspberry Pi Pico Onboard Temperature Sensor Tutorial Using MicroPython.
The connectivity front includes two SPI controllers, two I2C controllers, two UARTs, and USB1.1. The board features 3 12-bit ADCs for high-resolution analog to digital conversions.
There are 30 GPIO pins. Out of these, 26 are available to use through the pin-headers. The pins GP23, GP24, GP25, and GP29 are not available in the board’s pinout. They are used for specific functions as shown in the table below.
|GPIO 23||Used to control the on-board SMPS Power Save pin|
|GPIO 24||VBUS sense – HIGH if VBUS is present, else LOW|
|GPIO 25||Connected to the on-board LED|
|GPIO 29||Used in ADC mode (ADC3) to measure VSYS/3|
Note that, unlike many Arduino boards, Pico pins operate at 3.3V. So if you have any input peripherals that output 5v, be sure to use an appropriate logic level converter. Pico has a flexible clock that can run up to 133 MHz. You can access the Pi Pico datasheet here.
Raspberry Pi Pico Pinout
Here is the pinout of the first variant of Raspberry Pi Pico/ Raspberry Pi Pico H:
Raspberry Pi Pico W Specifications
Most features of the Raspberry Pi Pico W version are similar to the first Raspberry Pi Pico variant. The Raspberry Pi Pico W maintains the Pico small factor while adding on-board single-band 2.4GHz wireless ports (802.11n), utilizing the Infineon CYW4343 chip. Infineon CYW4343 features a single-band 2.4 GHz Wi-Fi 4 (802.11n) and Bluetooth® 5.1. The RP2040 microprocessor is connected to the wireless interface via SPI.
Like the Pi Pico original version, 26 out of 30 GPIOs are available through the pin headers. GP23, GP24, GP25, and GP29 retain the same functionality as described in Table 1 above. Three GPIO pins from the Infineon CYW43439 are used for some specific functions:
|WL_GPIO0||Connected to onboard LED.|
|WL_GPIO1||Controls the on-board SMPS power save pin.|
|WL_GPIO2||Senses the VBUS voltage. It is in a HIGH state if VBUS is present, else its state is LOW.|
Raspberry Pi Pico W Pinout
Below is the pinout of Raspberry Pi Pico W and Raspberry Pi Pico WH.
The pinout of both Raspberry Pi Pico & Pico W is similar in most aspects. You can learn more about the pinouts in our in-depth article: Raspberry Pi Pico & Pico W Pinout Reference – A Complete Guide.
How To Power Up The Raspberry Pi Pico – Using USB or GPIO
There is an onboard buck-boost Switched-mode Power Supply(SMPS) in Pico, which can generate 3.3V. So, we can even use a single rechargeable lithium-ion cell to power up the Pico. VSYS(Pin 39) is the main board input voltage, which can be in the range of 1.8V to 5.5V. The 3.3V which is used by the RP2040 microcontroller and other components is available at Pin 36(3V3 OUT). To power the Raspberry Pi Pico using GPIO, you can use the VSYS Pin for the positive supply voltage, and any of the Ground Pins marked as GND.
VBUS pin(Pin 40) is connected to the micro-USB port pin 1, so it stays at around 5V when connected to a computer.
What is MicroPython on Raspberry Pi Pico?
MicroPython is a port of Python 3 that is specifically designed to work with low-power microcontrollers. It features a subset of the standard Python library and is optimized to run on bare metal processors. Although MicroPython is not a full implementation of Python, its syntax and features are the same to an extent. So, if you are experienced with Python, then you can easily get started with MicroPython and vice-versa. MicroPython has a built-in filesystem and allows us to execute commands via USB Serial. We get an interactive prompt called the REPL to interact with the microcontroller.
What is REPL in MicroPython?
When we power up the Raspberry Pi Pico, it waits for user commands to perform an action. The fastest way to interact with it is through REPL. REPL stands for read-evaluate-print loop. In the read phase, MicroPython waits for code to be written on the shell of an IDE. Upon pressing the Enter key, Micropython evaluates the code that was typed and runs it immediately. If any result is to be shown, it is printed for the user to view. This process continues in a loop, i.e. it again goes back to the read phase and waits for the next line of code to be written.
The REPL environment is very fast and shows results immediately. On the contrary, C/C++ code is compiled first, so development in MicroPython can be faster than in C/C++.
Steps To Build Our First Project Using Raspberry Pi Pico
- Installing MicroPython on Raspberry Pi Pico.
- Installing an IDE.
- Soldering Header pins to Pico(if the version you purchase has no headers).
Installing MicroPython On Raspberry Pi Pico & Raspberry Pi Pico W
- Download the MicroPython UF2 file for the original Pi Pico. For Raspberry Pi Pico W, download the Pico W UF2 file. UF2 is a file format that is suitable for flashing microcontrollers over USB.
- Press and hold the BOOTSEL button on your Pico and insert it into the USB port of your computer(while the button is still pressed). After proper connection, release the BOOTSEL button.
- Your Pico will mount as a Mass Storage Device with the label RPI-RP2. Copy and paste the UF2 file inside this volume.
Upon successfully copying, your device will reboot, and the volume RPI-RP2 will disappear from your drive list. Congratulations! Your Pico is now running MicroPython. You can now use the REPL to interact with your Pico via USB.
Installation of Thonny IDE and Using The REPL
- Go to thonny.org. Download the version suitable for your OS from the website. I installed version 3.3.13 for Windows. This version of Thonny IDE has Python 3.7 built-in. Install the IDE once the download completes.
- While installing, accept the license agreement, set the destination location of Thonny, set the desktop shortcut, and finally click on the Install button. Click on Finish in the last step and launch Thonny.
- Upon opening the IDE for the first time, set the Initial settings section to ‘Standard‘ and click the ‘Let’s Go‘ button.
- Click on the Python version displayed in the bottom right corner of Thonny IDE (Python 3.7.9 in my case). It displays the interpreter that Thonny is currently using. Change the default interpreter to Micropython(Raspberry Pi Pico).
- Type the following code in the shell:
print ('Hello')Code language: PHP (php)
- If you followed all the steps correctly, you can now view “Hello” printed on the interface terminal, as shown in the screenshot below.
Soldering Pin Headers – Raspberry Pi Pico Tutorial
Pico comes with castellated mounting points and plated holes. Soldering pin headers(Berg strips) to the holes will make it easier to prototype projects using a beadboard. Pico has 40 pins, 20 on each side. Cut your pin headers in groups of 20 like the image below.
For easier soldering, insert the pin headers to the breadboard as shown in the following image. Place your Pico atop the pins and solder the header pins to the holes in Pico. Make sure that the connections are proper.
Soldering Tips: Apply flux to the pins where you will apply solder -> apply a little solder to your soldering iron for proper transfer of heat -> heat the pins with your soldering iron and then apply solder to the heated pins, one by one.
After the pin headers are soldered, they should look somewhat like the image below.
How To Program Pi Pico Using Thonny IDE & Blink The Onboard LED
Raspberry Pi Pico has an onboard LED connected to Pin 25. In the case of Pico W, the LED is connected to a pin on the CYW4343 chip. We will now try to blink this LED by writing a simple Python program.
- Connect your Pico to your computer via USB. (Do not press BOOTSEL as we did earlier).
- Open Thonny. Copy the following code and paste it into your main editing space in Thonny. Remember, Python uses indentation. Use proper indentation while typing your code. The following code is for Raspberry Pi Pico W.
from machine import Pin import time led = Pin("LED", Pin.OUT) while True: led.low() time.sleep_ms(500) led.high() time.sleep_ms(500)Code language: Python (python)
- Click on File> Save as from the top toolbar and select Raspberry Pi Pico as the save location.
- Save the file as main.py Press OK to save.
The onboard LED on your Pico should now start blinking.
- First, we import two libraries, the
machinelibrary has specific functions that help us interact with the microcontroller’s hardware. The time library has functions that can fetch the current date/time and can help us to set delays within code execution.
led = Pin("LED", Pin.OUT)sets the pin connected to the onboard LED as an output pin.
led.high()will send 3.3V to the output pin of Pico which is connected to an LED.
led.low()will turn off the LED by grounding the pin.
time.sleep_ms(500)will put the microcontroller to sleep for 500 milliseconds.
The LED will keep on toggling between the high and low states at an interval of 500 milliseconds. Try experimenting with the delay times. For example, typing
led.sleep(1) will introduce a delay of 1 second.
Program Raspberry Pi Pico Using uPyCraft IDE
Users can also use the uPyCraft IDE to write and upload scripts to their microcontroller. It is another beginner-friendly and easy-to-use IDE. Let us look at how to get started with uPyCraft IDE on Raspberry Pi Pico.
- First, we need to have Python installed on our computer. If you don’t have it already, you can get the latest version by visiting https://www.python.org/downloads/. Download the latest version for your operating system.
- Open the Python installation file. Make sure to tick “Add Python to path“. Then click Install Now.
- After Python successfully installs, we can install the uPyCraft IDE. You can find the installation file by visiting https://github.com/DFRobot/uPyCraft. Download one of the latest versions for your OS. You can also download the IDE from this Google Drive link of version 1.1 of the IDE that I have shared for public access.
- Opening the uPyCraft IDE file will show a window as described in the image below.
- Connect your Raspberry Pi Pico to your computer via USB data cable.
- From the top toolbar of the IDE, click on Tools>board>other.
- Then click Tools>Serial and select the COM Port that is shown. In my case, COM4 was displayed.
- If the steps were followed correctly, three arrows >>> will show up in the terminal window, meaning a successful connection has been established with Pico. If not, then reconnect your Pico board to computer by disconnecting and reconnecting the USB cable.
- To write a new program, click File>New and paste the following code in the blank space. The code is the same that we wrote in the previous steps.
- Click File>Save or use the Ctrl+S shortcut to save the code. A pop-up window will ask you to enter the file name. Enter any filename with a ‘.py’ extension. For example, I named the file blink_led.py. Press ok when done.
- To send the code to Pico, go to Tools>DownloadAndRun or press F5.
The onboard LED on Pico must now start blinking.
Raspberry Pi Pico Example Projects To Get Started
Here are some projects you can try next on your Raspberry Pi Pico-
- Raspberry Pi Pico W Bluetooth (BLE) using MicroPython | Point-to-Point Communication
- Raspberry Pi Pico Serial Communication Tutorial With Example.
- Raspberry Pi Pico I2C Communication Guide With Examples.
- Raspberry Pi Pico Interrupts & Button Interfacing Tutorial Using MicroPython.
- Raspberry Pi Pico PWM Guide & LED Brightness Control Example.
- Raspberry Pi Pico ADC Guide-MicroPython Example In RP2040 Using A Potentiometer.
- Raspberry Pi Pico Onboard Temperature Sensor Tutorial Using MicroPython.
- Raspberry Pi Pico Ultrasonic Sensor(HC-SR04) Interfacing.
- Raspberry Pi Pico BMP280 Tutorial-Interface Using MicroPython.
- Raspberry Pi Pico YF-S201 Flow Sensor Interfacing Guide.
- Raspberry Pi Pico DHT11 Interfacing Guide Using MicroPython.
- Raspberry Pi Pico DHT22(AM2302) Interfacing Tutorial.
Frequently Asked Questions (FAQs)
How To Run MicroPython Script on Startup In Pico?
In this tutorial, the script we saved to Pico will only start and execute when we press Run or F5. If you disconnect the Pico and connect it to your computer again, you will notice that the script that we flashed no longer runs. To start our script on power-up, we need to save it as main.py.
If your script is running, stop it by clicking the red stop button on the top toolbar of Thonny. Now, click on File>Save as>Raspberry Pi Pico. Set the file name to main.py and click OK. Now, if you disconnect and reconnect your Pico to your computer, or an external power supply, the script main.py will start executing at power-up
How To Reset Raspberry Pi Pico
Raspberry Pi Pico can be easily reset to the factory state by flashing a special UF2 file. More about this is described in our article to reset Raspberry Pi Pico.
Is Raspberry Pi Pico A Computer?
A computer is defined as a digital machine that can automatically carry out arithmetic and logical operations in a sequence. As Raspberry Pi Pico can process and store digital data, you can call it a computer. More specifically, it is a microcontroller development board.
Based around the RP2040 microcontroller, it has some peripherals that make it easier to program and interact with the microcontroller. But Pico is far less powerful than our mobile devices or desktop PCs.
It does not come with ready-made USB ports to connect devices such as a mouse, keyboard, or monitor. Pico is designed for low-power computing applications, such as monitoring a motion sensor or measuring object distances.
What is Raspberry Pi Pico Used For?
This tiny microcontroller has a variety of uses for hobbyists and engineers. Some common uses of Raspberry Pi Pico include – Home automation, Robotics, the Internet of Things(IoT), data logging using sensors, etc.
Does Raspberry Pi Pico Have Wi-Fi?
The newer version released in 2022 i.e. Raspberry Pi Pico W has Wi-Fi. But the earlier versions do not have it. In order to send or receive data to the original Raspberry Pi Pico via the internet or a web browser, we need to interface it with Wi-Fi modules such as ESP8266 or ESP32.
“Couldn’t find the device automatically” Error in Thonny
You might have encountered this problem with an error message saying “Couldn’t find the device automatically. Check the connection (making sure the device is not in bootloader mode) or choose
“Configure interpreter” in the interpreter menu (bottom-right corner of the window)
to select specific port or another interpreter.”
To get around this error, ensure your Raspberry Pi Pico is connected to your computer via USB. Check the USB cable for faults. If the connection is OK, click the ‘Stop‘ button on the top toolbar. Now you should be able to upload code to your Pico.
We used MicroPython throughout this tutorial, but you can also use C/C++ to develop programs for Pico. You can read about it here from the official documentation. To learn more about programming the Pico using MicroPython, you can visit their official documentation via this link.
I hope you found this getting started tutorial for Raspberry Pi Pico to be useful. Please leave your thoughts in the comments below.