Photo by Vishnu Mohanan

Uploading to the Raspberry Pi Pico without Thonny

Thonny is the recommended way of working with a Pico and MicroPython as it has built-in support for running and uploading files. However, I wanted to use Visual Studio Code as my code editor and upload files via the command line instead. I found two CLI tools that I could use to achieve this: rshell and ampy.

rshell

rshell provides a shell that runs on the Pico. It can be downloaded using pip:

pip3 install rshell

To connect to the Pico:

rshell -p /dev/ttyXXXX --buffer-size 512

Where ttyXXXXis the serial port that your Pico is connected to. You can find the serial port by running ls /dev/tty*with the board disconnected, and then connected, and compare the results. If the output is hard to compare, redirect it to a text file (e.g. ls /dev/tty* >> connected.txt) and then use diff to compare the files. On my Mac, the Pico’s serial port is currently /dev/tty.usbmodem000000000001 but this might not be the same for you so make sure to check first!

The files for the Pico are stored in /pyboard. Once rshell has connected, you can see what files are on the Pico by running ls /pyboard . You can copy a local file to the Pico with cp main.py /pyboard. If you want the python file to run when the Pico is powered on, make sure the file is named main.py.

To exit the shell, type exit.

ampy

ampy is a CLI tool for manipulating files and running code on a MicroPython board, such as the Pico, over a serial connection. It’s the tool that I find myself using most and it can be also installed via pip:

pip3 install adafruit-ampy

To list files on the board (see the discussion above on how to find out your serial port):

ampy --port /dev/ttyXXXX ls

To run a file on the board without uploading it:

ampy --port /dev/ttyXXXX run main.py

To upload a file:

ampy --port /dev/ttyXXXX put main.py

To remove a file:

ampy --port /dev/ttyXXXX rm main.py

--

--

--

https://mikeesto.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Testing in Elixir:: Chapter 3: The outside world is scary…

Stateful vs Stateless Architecture

March Unlocked Stories

Explore the possibilities with hundreds of domain extensions — {link} -

Continuous Integration: GitHub Integration with Jenkins

How To Connect With OPC-UA Using Go

Rebiber: Normalizing BibTeX with Conference Information

StackExchange — The 8 best resources every developer must follow

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Esteban

Michael Esteban

https://mikeesto.com

More from Medium

How to operate LDR using Arduino Uno

How to operate LDR using Arduino Uno

3D-printing with Robotic arm and PowerMill Robot

Upgrade with Arduino Uno — A Fun way to recycle a toy car

Kid-lara-ga-bil

UtilityGenius™ Launched by Encentiv Energy