Skip to main content

ALPACA 2.0

© Copyright Delft University of Technology, CC BY 4.0.

ALPACA (Advanced Learning Platform for Analog Circuits and Automation) is a device built on RP2 and MicroPython and equipped with several digital tools to be a guide in introduction to digital systems and electronics for NB2420 Electronic Instrumentation course of TU Delft.

ALPACA splits work across two Picos:

  • Student Pico: the board a student writes code on via Belay. It exposes a tiny RPC client so student programs can ask the Helper to do things. Student Pico is equiiped with a double channel DAC.

  • Helper: a self-contained instrument. It drives an LCD and runs a set of measurement screens (voltmeter, component/resistance tester) that the user can cycles through. It also answers commands sent by the Student over a UART link.

A host-side CLI (alpaca) copies board libraries over USB and opens a serial REPL, so you never have to manage USB ports by hand. Firmware installation uses the Pico's BOOTSEL mode and the ALPACA UF2 files.

The Student and Helper talk over UART0 with a crossover wiring and a shared ground:

  Student GP00 (TX) ──► Helper GP13 (RX)
  Student GP01 (RX) ◄── Helper GP12 (TX)
  GND ◄──────────────► GND

Repository layout

📁 alpaca folder contains the libraries for Picos. 📁 src/alpaca contains the desktop-side library and the ALPACA CLI for managing the boards (src/alpaca/cli). It is published on PyPI as alpaca2, but the import name and the command stay alpaca, so installed users write from alpaca import list_boards.

alpaca/common is copied alongside alpaca/student or alpaca/helper onto each board at sync time, which is why on-device imports are flat (from command import ..., from link import ...).

Therefore if the folders are like this

📁 alpaca/
  📁 common/
    📄 A.py
  📁 student/
    📄 B.py
  📁 helper/
    📄 C.py

using alpaca sync will copy the files to the root as:

🍓 HelperPico
  📄 A.py
  📄 C.py

🍓 StudentPico
  📄 A.py
  📄 B.py

Installation

Choose the instructions for your environment manager. ALPACA requires Python 3.14 or newer. The package is called alpaca2; the Python import and CLI command are both called alpaca.

uv users

To work from this repository, open a terminal in the repository root and run:

uv sync

This creates the project's .venv, installs the project and its dependencies, and makes the CLI available through uv run alpaca.

To use the published package without cloning this repository, run the following in your working folder:

uv venv --python 3.14
uv pip install alpaca2

Run uv run alpaca commands from the same folder. In VS Code, select this folder's .venv using Python: Select Interpreter (and select it as the kernel when working in a notebook).

Conda users (course students)

Follow the course manual's Software Installation instructions. You will need Conda and VS Code, and a separate environment named ei-env.

Download ei-env.yaml from the course manuals and open a terminal with Conda available. Change to the folder where you saved the file; for example, on macOS:

cd ~/Downloads

Create and activate the course environment:

conda env create -f ei-env.yaml
conda activate ei-env

The YAML file installs Python 3.14 or newer, the course's scientific Python packages, notebook tools, alpaca2, Belay, and the MicroPython RP2 stubs. You do not need to install alpaca2 separately. If you already created ei-env following the manual, just activate it.

In VS Code, press Ctrl/Cmd+Shift+P, choose Python: Select Interpreter, and select ei-env. For notebooks, also select ei-env as the kernel. Activate ei-env in each new terminal before running alpaca commands.

Usage

Use uv run alpaca with uv, or alpaca in an activated Conda environment. Both run the same CLI.

Flash firmware with BOOTSEL (normal student setup and updates)

Download the course-specified firmware from the ALPACA releases. Choose the alpaca-student-...uf2 file for the Student Pico and alpaca-helper-...uf2 for the Helper Pico, matching your board model. The current build targets RPI_PICO2.

For each board that needs updating:

  1. Disconnect its USB cable, hold BOOTSEL, and reconnect it to your computer.
  2. Release BOOTSEL when the USB drive appears (RP2350 for Pico 2).
  3. Copy the matching .uf2 file onto that drive. The Pico reboots automatically.

These images include MicroPython and the ALPACA libraries. Students normally do not need to run alpaca sync after flashing. If the board was previously synced, read the FAQ about removing filesystem overrides first. The BOOTSEL procedure is also described in the Raspberry Pi documentation.

Sync board libraries (development or an instructor-directed patch)

Use this to test changed board libraries without rebuilding the firmware. Close any notebook or serial connection using the boards first. Back up files saved on the Picos: sync can delete files outside the library set. See the FAQ before using this on a student board.

# uv
uv run alpaca sync

# Conda (after conda activate ei-env)
alpaca sync

This selects connected Picos, copies the common + student/helper code onto each selected board's filesystem, and soft-resets them. It uses the libraries in your checkout, or those bundled in the installed alpaca2 package. To drop into a REPL on one board right after syncing:

# uv
uv run alpaca sync --connect student

# Conda
alpaca sync --connect student

Open a serial REPL

# uv
uv run alpaca connect student   # or: helper

# Conda
alpaca connect student          # or: helper

Picking a board

The first time the CLI needs a board it lists the connected Picos in a terminal menu. Hovering an entry lights that board's onboard LED so you can tell which is which, and you can choose to remember the selection — it's cached per role under .alpaca/ so later runs skip the prompt.

FAQ

What is the difference between BOOTSEL flashing and alpaca sync?

BOOTSEL + ALPACA UF2 alpaca sync
Writes Firmware containing MicroPython and frozen ALPACA libraries Library files on the writable MicroPython filesystem
Requires BOOTSEL USB drive mode Running MicroPython and a USB serial connection
Library format Precompiled MicroPython bytecode frozen into firmware .py source files (minified by Belay)
Typical use Student setup, released updates, firmware recovery Development and instructor-directed temporary patches

Sync does not rewrite the frozen modules or update MicroPython itself. With the default MicroPython 1.28.0 RP2 import path, the current directory is searched before frozen modules, so synced modules in the filesystem root override imports of their frozen counterparts. They remain there after a reboot. This follows MicroPython's runtime initialization and RP2 initialization.

Startup files are a special case: MicroPython 1.28.0 checks for frozen boot.py and main.py before filesystem copies. Our Helper has a frozen main.py, so syncing a changed main.py does not replace that startup script. Use a new UF2 for startup changes. See MicroPython's pyexec_file_if_exists.

What should students do when we publish a patch?

For a board-code patch, use the course-specified ALPACA UF2 release containing the fix and flash the affected board(s) using BOOTSEL. Follow the release instructions about which boards need updating. For a desktop-only patch to the CLI or host library, update alpaca2 in your Python environment; the Picos do not need reflashing.

A Git commit alone does not update installed packages or boards. Maintainers must publish a package or build a UF2 containing the patch before students can get it through that route. If an instructor asks students to apply a library patch through sync, first install the package containing it:

# Conda: the course YAML installs alpaca2 through pip
conda activate ei-env
python -m pip install --upgrade alpaca2
alpaca sync
# uv: published package in a working folder, outside this repository
uv pip install --upgrade alpaca2
uv run alpaca sync

When developing from a checkout, pull the intended patch and run uv sync, then uv run alpaca sync. Sync uses that checkout's board libraries. It does not download a patch itself. Back up board files before either sync workflow; use UF2 flashing for changes to MicroPython or frozen startup files.

Does syncing an up-to-date UF2 make it slower?

It can increase startup/import time and RAM use without adding a fix. The frozen libraries are MicroPython bytecode, not Cython modules. The current sync command uploads .py files without asking Belay to precompile them. When those files shadow frozen imports, MicroPython must parse and compile them on the Pico and keep the resulting bytecode in RAM. Frozen bytecode avoids that compilation and runs directly from flash. See MicroPython's frozen-bytecode explanation.

This does not imply a fixed slowdown in every measurement loop: both forms execute MicroPython bytecode, and steady-state timing depends on the workload. Extra RAM use can also increase garbage-collection pressure. The size of the effect needs a hardware benchmark. Keep the frozen libraries for normal student use; do not sync an already up-to-date board just in case. Repeated syncs skip unchanged file contents, but leave the overrides in place.

Can sync delete my saved programs?

Yes. The current CLI uses Belay's directory sync with its default cleanup: filesystem files absent from the staged library set are deleted, except for boot.py, webrepl_cfg.py, and lib. This can remove saved student scripts and data. Files with matching library names can be overwritten. Frozen firmware modules are unaffected. Keep a laptop copy of anything you need before running sync.

How do I return to the frozen libraries after syncing?

Back up your board files, remove the ALPACA filesystem copies created by sync, and reset the Pico. Imports can then use the frozen versions again. Reflashing a UF2 alone is not a guaranteed filesystem cleanup: surviving overrides can still hide the new firmware's libraries.

For a completely clean course setup, follow the instructor's filesystem-cleanup procedure or a factory reset, then flash the correct ALPACA UF2. A factory reset erases saved programs and data as well as the overrides. Do not run sync again unless you need another development patch.

Building

The repository workflow should build and publish stubs, and assemble firmware images on creation of a version tag.

git tag v1.0.0
git push origin v1.0.0

The MicroPython version for firmware is set inside the build-firmware.yml (currently 1.28.0).

Metadata

Release files for alpaca2 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alpaca2 1.0.5
File Size Uploaded Provenance Actions
alpaca2-1.0.5.tar.gz 32.7 kB Without provenance Details for alpaca2-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for alpaca2 1.0.5
File Interpreter ABI Platform Actions
alpaca2-1.0.5-py3-none-any.whl Python 3 none any Details for alpaca2-1.0.5-py3-none-any.whl

Total release size: 74.7 kB

Release files / alpaca2-1.0.5.tar.gz

Download URL alpaca2-1.0.5.tar.gz
Size 32.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cd5b0a2c3ccbad83f136c3e0da85d649f29b790100d195020c481a34f73cc362
BLAKE2b-256 checksum
How to use checksums
398094e37bbe8a72947d3e9456745e870517d7a116c0e7c1e20b2ef92c3dccbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / alpaca2-1.0.5-py3-none-any.whl

Download URL alpaca2-1.0.5-py3-none-any.whl
Size 42.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd18d5b1289db18ea63f08bc5c3818ca8a80ddc1b00fdb3d61c856fc01410d20
BLAKE2b-256 checksum
How to use checksums
5a34835b7a686733bfcf73558ec825091e0268533c29ae90534db2b4771e593e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for alpaca2 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page