Raspberry Pi Pico W is a development board with wireless function based on the Raspberry Pi RP2040 chip. Pico can be developed under multiple operating systems, such as Windows, Linux, etc. Pico officially supports the development method of MicroPython. Using MicroPython can take advantage of Python's syntax features and can run directly without compilation. It also provides many library functions, which can quickly get started.
Let's talk about how to use MicroPython on Pico. The overall steps mainly include 2 steps:
- First you need to download the MicroPython firmware on Pico
- Then build the development environment
The details are as follows:
1. Download MicroPython firmware
1.1 Download the official MicroPython firmware
The MicroPython firmware download address for Pico W is:
https://micropython.org/download/rp2-pico-w/rp2-pico-w-latest.uf2
If you are using Pico, you need to download the following firmware:
https://micropython.org/download/rp2-pico/rp2-pico-latest.uf2
Note that the 2 firmwares are different.
1.2 Burning firmware The official MicroPython firmware is available at:
Follow these steps to burn the firmware to the Pico:
- Press the 'BOOTSEL' button on the board and then power on;
- At this point the computer will recognize Pico as a USB drive and copy the downloaded firmware to the USB drive.
Reference: MicroPython page on Pico official website
2. Build the development environment
Now that the Pico board that supports MicroPython is ready, the next step is to build a development environment. The official recommendation is Thonny IDE, which is a very small Python integrated development tool with a size of only 20MB. This IDE has a built-in Pico interpreter and can directly write Pico code.
First download the latest installation package from the official website: Thonny, Python IDE for beginners
After the installation is complete, you need to switch the software to the MicroPython interpreter that supports Pico. Click "Tools->Options" in the menu bar, open "Thonny Options", and select "MicroPython (Raspberry Pi Pico)" in the "Interpreter" tab, as shown below:
At this point, the Pico development board will automatically connect when it is connected to the computer.
3. Write test code
The editing interface of Thonny IDE is shown in the figure above. You can edit the code in the form of files in the editor above, or you can edit the code in the interactive form in "Shell". For example, output "Hello world"
print("Hello world")
You can directly see the running results in Shell. If you edit it in file form, you need to click the "Run current script" button.
You can also write code to flash the LED. The code is as follows:
from machine import Pin
from utime import sleep
pin = Pin("LED",Pin.OUT)
print("LED starts flashing...")
while True:
pin.toggle()
sleep(1)
IV. Summary
Now we can use MicroPython to program Pico. However, Thonny IDE does not have the function of code completion, so in order to pursue programming efficiency, we can use VS Code. The next post will introduce how to use VS Code.