Skip to content
Free US shipping on orders $35+
Order by 3pm ET — ships same-day from the US
Free US shipping on orders $35+
Skip to main content

Raspberry Pi Pico adafruit-ampy: Run code via CLI | ShillehTek

October 23, 2023

Raspberry Pi Pico adafruit-ampy: Run code via CLI | ShillehTek
Project

Set up adafruit-ampy to manage files and run MicroPython scripts on a Raspberry Pi Pico or Pico W from the command line, without an IDE, with ShillehTek.

10 min Beginner1 parts

Video Tutorial (Optional)

Watch first if you want to follow along with setting up adafruit-ampy and using the command line to manage files and run code on a Raspberry Pi Pico.

Project Overview

Raspberry Pi Pico + adafruit-ampy CLI: In this tutorial, you set up the adafruit-ampy command line tool to run code and manage files on a Raspberry Pi Pico (or Pico W) over USB serial, without using an IDE such as Thonny or VSCode.

Running code through the command line can be lightweight and convenient, and it can also help you automate scripts on your computer that deploy to (or run on) your Pico.

If you want to subscribe and support the channel:

  • Time: 10 to 20 minutes
  • Skill level: Beginner
  • What you will build: A working command line workflow to list, upload, download, delete, and run MicroPython files on a Pico using adafruit-ampy

Parts List

From ShillehTek

External

  • USB cable (data-capable) to connect the Pico to your computer
  • Python installed on your computer
  • adafruit-ampy (installed via pip)

Note: adafruit-ampy assumes your Pico is running MicroPython firmware. If MicroPython is not installed yet, install it first.

Step-by-Step Guide

Step 1 - Install adafruit-ampy

Goal: Install the CLI tool you will use to interact with your Pico over serial.

What to do: Make sure Python is installed on your computer, then install adafruit-ampy using pip.

Code:

pip install adafruit-ampy

Expected result: adafruit-ampy is installed and available from your terminal.

Step 2 - Connect your Raspberry Pi Pico to your computer

Goal: Create a USB serial connection between your computer and the Pico.

What to do: Connect your Raspberry Pi Pico to your computer using a USB cable. Depending on your operating system, you might need to install drivers.

Expected result: The Pico shows up as a serial device on your computer.

Step 3 - Find the serial port your Pico is using

Goal: Identify the correct port name to use with ampy commands.

What to do: On Linux and macOS, you can often list serial devices with the command below.

Code:

ls /dev/tty*

Expected result: You find the device that represents your Pico (for example, /dev/ttyUSB0 on Linux or /dev/tty.usbmodem on macOS). You can also find the port in Thonny (bottom right).

Step 4 - Use adafruit-ampy to manage files and run code

Goal: Use common ampy commands to list files, upload, download, delete, and run scripts on the Pico.

What to do: Replace /dev/ttyUSB0 in the examples below with the actual serial port for your Pico.

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

Expected result: You can manage files on the Pico filesystem and run MicroPython scripts from your command line without an IDE.

Conclusion

You set up a lightweight command line workflow for a Raspberry Pi Pico (or Pico W) using adafruit-ampy, including listing files, uploading and downloading scripts, deleting files, and running MicroPython code over USB serial.

Want the exact parts used in your next Pico build? Grab boards, cables, and prototyping gear from ShillehTek.com. If you want help customizing your workflow or building an automation-focused setup for your project or product, check out our IoT consulting services.