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

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.

Create a free account to access full content.

All access to code and resources on ShillehTek.

Signup Now

Already a member? Sign In

Explore More on Our Blog

Create Tabular Product Descriptions on Your Shopify Store

Create Tabular Product Descriptions on Your Shopify Store

Enhance your Shopify store's product pages with our comprehensive guide on implementing tabular descriptions. Learn how to add a...

SSH Into Raspberry Pi with Tailscale VPN

SSH Into Raspberry Pi with Tailscale VPN

Effortlessly access and manage your Raspberry Pi from anywhere using Tailscale's secure mesh VPN.

Send Email with Lua and the ESP32

Send Email with Lua and the ESP32

In this tutorial, we delve into sending emails with the ESP32-S3 using Lua, focusing on the Xedge IDE's built-in SMTP...

How to Code with Lua on ESP32 with XEdge32

How to Code with Lua on ESP32 with XEdge32

Learn how to set up Xedge32 and start coding on the ESP32-S3 with Lua programming!

Stream Audio From Raspberry Pi to Local Computer

Stream Audio From Raspberry Pi to Local Computer

Discover the simplicity of streaming live audio directly from a USB microphone connected to your Raspberry Pi to...

SSH Raspberry Pi via Cell Phone

SSH Raspberry Pi via Cell Phone

This beginner-friendly guide will walk you through remotely controlling your Raspberry Pi using SSH through your cell phone.

Remotely Control Raspberry Pi via SSH from External Network

Remotely Control Raspberry Pi via SSH from External Network

Learn how to SSH into your Raspberry Pi from any network. This is critical in IoT since you can control...

Stream Video from Raspberry Pi Camera to YouTube Live

Stream Video from Raspberry Pi Camera to YouTube Live

Learn how to stream to YouTube from a Raspberry Pi Camera.

How to Connect BH1750 with Arduino: Measure Ambient Light

How to Connect BH1750 with Arduino: Measure Ambient Light

Learn how to measure ambient light for smart lighting control using Arduino and the BH1750 Light Intensity Module.

How to Connect MPU9250 and Raspberry Pi (Part 2 - Calibration)

How to Connect MPU9250 and Raspberry Pi (Part 2 - Calibration)

Learn how to calibrate the MPU9250 in Python with the Raspberry Pi to get more accurate acceleration and gyroscopic...

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.