Libraries and projects for MicroPython compatible boards
Project description
Baremetal MicroPython libraries with built-in cooperative multitasking for the Raspberry Pi Pico and Espressif boards.
Overview
The purpose of this project is to develop a set of libraries that allow easy programming and prototyping of essential sensor and robotics functions, similar to the form of the Arduino IDE. The implementations here are independent of any IDE or existing framework โ written in 'baremetal' form using only the machine modules provided by MicroPython.
N.B: Initial development was for Raspberry Pi Pico boards, but the libraries in this repository work seamlessly with ESP32 boards. In projects or documentation where references are made to Pico boards rather than MCU, treat this as a legacy reference โ the libraries work equivalently for both boards. If you wish to see such documentation updated, kindly open a pull request.
๐ง Supported Components
| Component | Library | Key Features |
|---|---|---|
| LED | led.py |
On/Off, non-blocking blink, PWM fade & brightness |
| Servo | servo.py |
Angle positioning, sweep, oscillate, calibration |
| Ultrasonic | ultraSonic.py |
HC-SR04 distance measurement |
| Button | button.py |
Debounced input with short/long press |
| RGB LED | rgbLed.py |
PWM/digital, named colours, hex, fades |
| LCD | liquidCrystal.py |
I2C HD44780 via PCF8574 driver |
| OLED | oled.py |
SSD1306 & SH1106 (I2C/SPI) |
| Wi-Fi | wifiManager.py |
Station mode connect + TCP server |
| Scheduler | scheduler.py |
Cooperative task scheduler with profiling |
Multitasking Without an RTOS
In building this library, I had to tackle multitasking in a way that didn't require me to build a full RTOS. If this project has any use or advantage over similar libraries, then it's that.
The libraries for LEDs, servos, and the ultrasonic sensor are embedded with an update() function which performs cooperative scheduling while hiding the complexity. This allows a programmer to multitask multiple processes on a single core:
"""Simultaneously blink LEDs and oscillate a servo motor."""
from stansmicropy.led import LED
from stansmicropy.servo import Servo
blinkLed = LED(16)
pwmLed = LED(17)
servo = Servo(15)
servo.oscillate(min_angle=30, max_angle=150, step=3, delay=0.03)
blinkLed.blink(delay=0.3)
pwmLed.fade(minP=5, maxP=80, step=5, delay=0.05)
while True:
servo.update()
blinkLed.update()
pwmLed.update()
For more complex scenarios, the Scheduler class manages multiple task modules with priority sorting, runtime add/remove, and optional profiling:
- schedulerDemo.py โ Running multiple task files as simultaneous processes on the MCU
- buttonTogglePrograms.py โ Using a physical button to switch between active programs at runtime, with OLED menu UI and mode persistence
For someone seeking to replicate modern PC OS capabilities on a cheap MCU, those demonstrations serve as a solid backbone.
Computer Vision
Architecture: Heavy processing (OpenCV, MediaPipe) runs on the PC โ commands are sent to the MCU over Wi-Fi TCP.
The repository includes gesture control projects split into:
| Side | Location | Role |
|---|---|---|
| Client (PC) | projects/Computer_Vision/client_side/ |
Webcam capture, hand tracking, sends commands |
| Server (MCU) | projects/Computer_Vision/server_side/ |
Receives commands, drives hardware |
The desktop-side compVision.py library wraps MediaPipe's Hand Landmarker for simplified hand detection. When transferring stansmicropy to the MCU, copy it without the desktop module:
mpremote cp -r src/stansmicropy :
Getting Started
Prerequisites
|
Quick Start
For CV Projectspip install -r requirements.txt
|
Project Structure
StansMicroPy/
โโโ src/
โ โโโ stansmicropy/ # โ Core MicroPython libraries
โ โ โโโ led.py, servo.py, button.py, ultraSonic.py
โ โ โโโ rgbLed.py, liquidCrystal.py, lcd.py, oled.py
โ โ โโโ wifiManager.py, scheduler.py
โ โ โโโ __init__.py
โ โโโ desktop/ # โ Desktop-side libraries (PC only)
โ โโโ compVision.py # MediaPipe hand tracking wrapper
โ
โโโ projects/ # โ Example projects by component
โ โโโ LED/, Servo/, Button/, LCD/, OLED/, RGBLED/, Ultrasonic/
โ โโโ multi_component_projects/ # Sound sensor, multi-actuator demos
โ โโโ Computer_Vision/
โ โ โโโ client_side/ # PC scripts (sends commands)
โ โ โโโ server_side/ # MCU scripts (receives commands)
โ โโโ wifi/ # Wi-Fi connection examples
โ โโโ task/ # Task modules for the scheduler
โ โโโ schedulerDemo.py
โ โโโ buttonTogglePrograms.py
โ
โโโ Docs/ # โ Guides & library documentation
โ โโโ Coding_Guide.md
โ โโโ LED.md, Servo.md, Button.md, Ultrasonic.md
โ โโโ LCD.md, RGB.md
โ โโโ AI_Kit_recommendations.md
โ
โโโ pyproject.toml
โโโ requirements.txt
โโโ LICENSE
Conventions
- Libraries and methods use camelCase naming
- Each library module has corresponding documentation in
Docs/ - Project files include docstrings and inline comments where intuition might fail
Citations
This project is indebted to the open source community, particularly the contributions of:
whose code provided the foundations for the OLED library in this repository.
and
whose code is the backbone of the LCD Library
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stansmicropy-0.1.1.tar.gz.
File metadata
- Download URL: stansmicropy-0.1.1.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42cd99a310c64a3ccdba84d015c3300be2dd3885aadd94f1f14927c39848b2bf
|
|
| MD5 |
e84a8e6e893c2e7b95c0ab3691af58f7
|
|
| BLAKE2b-256 |
0bb16fa2bc5af88223ae71298143697a8f3dd7d3f85a5d26838ccd44f1c65ac4
|
File details
Details for the file stansmicropy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: stansmicropy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb642bbd9dea2a6fd99d955eda4862af0c480a385cb75fd3d2ff31ce993da34a
|
|
| MD5 |
64f71b3d0ac756855d6d2e9740197458
|
|
| BLAKE2b-256 |
fe12decfc4b26f7c8080f463dce8788b7b3acf65182c7bdb56cf983bbadd0b38
|