This project provides a structured development environment for programming Raspberry Pi Pico (or RP2040-based boards) using MicroPython. It uses a Python virtual environment (venv) and a Makefile to simplify deployment, REPL access, and file management with the device.
Ensure the following are installed on your system:
- Python 3.8 or higher
- Homebrew (for macOS users)
- Visual Studio Code (optional, but recommended)
Install Python via Homebrew (macOS):
brew install python- Press and hold the BOOTSEL button on the Raspberry Pi Pico.
- Connect the device to your computer via USB while holding the button.
- The Pico will mount as a USB mass storage device.
- Download the latest
.uf2firmware for Raspberry Pi Pico from:
https://micropython.org/download/rp2-pico/ - Drag and drop the
.uf2file onto the mounted Pico device. - The device will reboot and appear as a USB serial device.
git clone <repository-url>
cd <project-directory>make venv
make installThis will:
- Create a Python virtual environment in
./venv/ - Install project dependencies from
requirements.txt
Edit the PORT variable in the Makefile if necessary. You can identify the correct device path using:
ls /dev/tty.usbmodem*| Command | Description |
|---|---|
make venv |
Creates a Python virtual environment |
make install |
Installs required Python packages from requirements.txt |
make run |
Executes main.py on the connected device |
make repl |
Opens an interactive REPL session |
make ls |
Lists files stored on the device |
make put |
Uploads main.py to the device |
make get |
Downloads main.py from the device |
make reset |
Issues a soft reset to the device |
micropython_project/
├── main.py # MicroPython source code
├── requirements.txt # Python dependency list
├── Makefile # Automation for development tasks
├── pico-mpy.code-workspace# VS Code workspace (optional)
└── venv/ # Python virtual environment
- This workflow assumes that all Python tooling (e.g.,
mpremote) runs inside a virtual environment. - Use the Makefile targets instead of manually copying files to the Pico.
- For consistent formatting and linting, tools such as
blackandflake8are included inrequirements.txt.
To remove the virtual environment:
rm -rf venv/To reset the environment:
make venv
make install