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

How to Post to Reddit Using Python

How to Post to Reddit Using Python

Post to reddit automatically using a Python script.

How to Create a Time-Lapse Video with a Raspberry Pi Camera

How to Create a Time-Lapse Video with a Raspberry Pi Camera

Learn how to make a timelapse with your Raspberry Pi in Python.

How to Integrate the MPU6050 with the STM32 Blue Pill

How to Integrate the MPU6050 with the STM32 Blue Pill

Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

In this tutorial, I'll show you how to automatically schedule tasks in AWS at regular intervals using AWS...

Implementing Google reCAPTCHA in a Simple React and Node.js App

Implementing Google reCAPTCHA in a Simple React and Node.js App

Learn how to protect your React applications from bots and spam with Google reCAPTCHA integration! This step-by-step tutorial...

AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

In this tutorial, I will guide you through the process of running Selenium with ChromeDriver inside an AWS...

How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

Learn how to use the MLX90614 with the Raspberry Pi Pico W and get infrared values in MicroPython.

Raspberry Pi Pico/Pico W Free Simulator

Raspberry Pi Pico/Pico W Free Simulator

Discover how to simulate Raspberry Pi Pico projects using Wokwi, a free online simulator for Arduino and MicroPython....

Interfacing the MPU6050 with Raspberry Pi Pico W in C++

Interfacing the MPU6050 with Raspberry Pi Pico W in C++

Interface with the MPU6050 using the Raspberry Pi Pico W in C++.

Back to blog

Leave a comment

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