DEV Community

Cover image for How to Run Code & Manage Files on Raspberry Pi Pico via CLI
Shilleh
Shilleh

Posted on

How to Run Code & Manage Files on Raspberry Pi Pico via CLI

Running code through the command line can be lightweight and convenient for some users. Most importantly, it can be used to create some automation on your local computer by automating the runtime of scripts on your device. In this tutorial learn how to quickly set up the adafruit-ampy CLI tool to start running and managing code on the Pico without the need for an IDE like Thonny, VSCode, etc.

Before we get started do not forget to subscribe and support the channel!

Subscribe:

Youtube

Support:

https://www.buymeacoffee.com/mmshilleh

STEPS
adafruit-ampy is a Python tool that allows you to interact with MicroPython-based boards, such as the Raspberry Pi Pico, over a serial connection. It provides a way to manage files on the board, upload Python scripts, and perform various file-related operations.

Here's how you can use adafruit-ampy with your Raspberry Pi Pico W to interact with it over the serial port:

Installation

Make sure you have Python installed on your computer. You can then install adafruit-ampy using pip, the Python package manager:

  • pip install adafruit-ampy

Connecting Your Raspberry Pi Pico

Connect your Raspberry Pi Pico to your computer using a USB cable. You might need to install drivers, depending on your operating system.

Find the Serial Port

You'll need to identify the serial port that your Pico is connected to. On Linux and macOS, you can often find this information by running:

  • ls /dev/tty*

Look for a port that represents your Pico (e.g., /dev/ttyUSB0 on Linux or /dev/tty.usbmodem on macOS). You can also easily find this in Thonny on the bottom right.

Using adafruit-ampy

Once you have adafruit-ampy installed and your Pico connected, you can use it to manage files on the Pico. Here are some common commands:

  • To list files on the Pico:

ampy --port /dev/ttyUSB0 ls

  • To upload a file to the Pico:

ampy --port /dev/ttyUSB0 put your_file.py

  • To download a file from the Pico:

ampy --port /dev/ttyUSB0 get remote_file.py local_file.py

  • To remove a file from the Pico:

ampy --port /dev/ttyUSB0 rm your_file.py

  • To run a Python script on the Pico:

ampy --port /dev/ttyUSB0 run your_script.py

Replace /dev/ttyUSB0 with the actual serial port of your Pico.

Remember that adafruit-ampy assumes that your Pico is running MicroPython firmware. If you haven't installed MicroPython on your Pico, you'll need to do that first.

Conclusion

Hope you learned something new and let me know if you have any questions in the Youtube comments. Do not forget to subscribe and I hope I potentially made your life easier.

Top comments (0)