I've recently been experimenting with MicroPython on the Pi PicoPi Pico. There are a few steps you need to get this setup.
- Install the MicroPython Firmware
- Suitable editor
- Upload the code
- Setting the code to run at boot
Although it is designed for a younger audience, I found the "Getting Started with MicroPython" book to be a useful reference. I also used the pi-pico-python-sdk
Installing the firmware
Installing the firmware is covered on the the https://www.raspberrypi.org/documentation/rp2040/getting-started/ page.
You need to download a suitable uf2 image and then copy it to the Pi Pico as a file. Before you first plug in the Pi Pico, hold down the "BootSel" button then connect the USB. This makes the device appear as a harddisk on your computer and you can copy over the UF2 image. If you then un-plug and replug the Pico Pi it reverts to programming mode.
https://micropython.org/download/rp2-pico/
Suitable Editor
The recommendation from the Raspberry Pi foundation is Thonny, you can also use the Mu editor. However, as I already had VSCode installed I didn't want to install yet another editor just for this project so I decided to use VSCode instead. You can use any text editor or IDE for writing your code, the Pico Pi does seem to support UTF-8 and ASCII formats for the files. As I had already done some python development with VSCode I had the extensions for syntax highlighting and intellisense already installed but needed something that would allow me to upload and run the code.
Upload the code
The Pico Pi defaults to being a USB Serial device. So should appear on your machine as a COM port. So for this reason some kind of tool is needed to copy the files to the board. I used the Pico-Go extension for VSCode but the Pymakr extension should also work. These provide buttons on the status bar at the bottom of the screen to upload and run the code. You can also get more options from the menus such as deleting all the files on the board or downloading the board content. Note that these work at a project level so will upload all of the files in the working folder including subfolders. The extension also gives you access to the REPL via a terminal window.
REPL is the read–eval–print loop, an interactive prompt. This allows you to run Micropython commands one at a time.
You can also upload code using the command line using RShell or Ampy
https://mikeesto.medium.com/uploading-to-the-raspberry-pi-pico-without-thonny-53de1a10da30
Setting the code to run at boot
To auto run the code, it is simply a case of having the file named "main.py". This will be run when the board starts up.
Note that there is also "boot.py", this typically sets up the hardware on the board so if you make an error in that you can stop the board working. You'll need to reflash the firmware to get your board back in operation.
Top Comments