Raspberry PI Pico with Micropython

After using ESPHome, I want to experiment more with the Picos without going back to programming in C. So it is MicroPython or CircuitPython. I chose MicroPython because it seems to have more features (i.e. Bluetooth).

First download a current Firmware from https://micropython.org/download/RPI_PICO/ and install via pressing the button on the Pico while connecting to USB. Copy the file on the device and it restarts when done.

On my ArchLinux I need sudo to write to /dev/ttyACM0. To fix this add the group uucp to your user:

sudo usermod -a -G uucp $USER

This is ArchLinux specific. For Ubuntu/Debian it is typically the group dialout.

Next step is to get a REPL and type in some Python. For this I used screen because of old habbit from years ago:

screen /dev/ttyACM0

This small snippet copied into there will let the LED blink every second:

from machine import Pin, Timer
led = Pin(25, Pin.OUT)
timer = Timer()
timer.init(freq=1, mode=Timer.PERIODIC, callback=lambda timer: led.toggle())

More on the timer in the MicroPython docs.

Writing in the REPL is nice but actual files are the way to go. But how to get the files on the Pico? Because I am late here and the MicroPython hype was years ago, the Internet is full of now dead instructions. One that seems to be still active is rshell. This can be pip installed, but I installed the Archlinux package.

When started with rshell it connects automatically to /dev/ttyACM0. To start the same REPL as before with screen type repl in the rshell. Positive here: Ctrl-X to exit the REPL, which was more trouble in screen.

After REPL success lets use a file to do the same. Copy the code into a file on your PC and name it blink.py. In rshell copy the file to the Pico:

cp blink.py /pyboard/main.py

The file main.py is started when the Pico is started. A boot.py is started before, but this may interfere with the REPL, so I chose not to add my own boot.py.

Verify if the file is there (still in rshell):

ls /pyboard

When disconnected and reconnected again the Pico will now let the LED blink. After reconnecting with rshell the blinking will stop again and the filesystem can be changed again.

Thanks to https://blog.martinfitzpatrick.com/using-micropython-raspberry-pico/ for a good rshell/Pico introduction.