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 into it, consider subscribing or supporting the channel. Also, be sure to checkout our various stores to shop products for Raspberry Pi, Arduino, ESP32, and DIY electronics at ShillehTek!
Subscribe:
Support:
https://www.buymeacoffee.com/mmshilleh
Hire me at UpWork to build your IoT projects:
https://www.upwork.com/freelancers/~017060e77e9d8a1157
Visit ShillehTek Store for Arduino and Raspberry Pi Sensors and Pre-Soldered Components:
ShillehTek Website (Exclusive Discounts):
https://shillehtek.com/collections/all
ShillehTek Amazon Store:
ShillehTek Amazon Store - Canada
ShillehTek Amazon Store - Japan
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:
InstallationMake sure you have Python installed on your computer. You can then install `adafruit-ampy` using pip, the Python package manager:
- pip install adafruit-ampy
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 PortYou'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-ampyOnce 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.
ConclusionHope 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.
Comments