Skip to main content

Libraries and projects for MicroPython compatible boards

Project description

StansMicroPy Banner

License MicroPython Python


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

  1. Flash the appropriate firmware from onto your Pico

  2. Install Python 3.12+ (ensure Add to PATH is checked)

  3. Install mpremote:

    pip install mpremote
    
  4. Install the MicroPico VSCode extension, but disable auto-connect โ€” the serial port can only be accessed by one of mpremote or MicroPico at a time. The MicroPico extension helps resolve Pylance issues as micriopython only libraries like machine aren't available on desktop Python.

    Settings > MicroPico > Auto Connect โ†’ OFF
    

Quick Start

  1. Read the Coding Guide
  2. Browse the library docs for method references
  3. Start with the LED examples and progress from there

For CV Projects

pip 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:

Radomir Dopieralski Robert Hammelrath Tim Weber Adafruit Inc.

whose code provided the foundations for the OLED library in this repository.

and

Damien Hylรคnds

whose code is the backbone of the LCD Library


Somtochukwu Stanislus Emeka-Onwuneme ยท MIT License

Connect with me

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stansmicropy-0.1.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stansmicropy-0.1.1-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

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

Hashes for stansmicropy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 42cd99a310c64a3ccdba84d015c3300be2dd3885aadd94f1f14927c39848b2bf
MD5 e84a8e6e893c2e7b95c0ab3691af58f7
BLAKE2b-256 0bb16fa2bc5af88223ae71298143697a8f3dd7d3f85a5d26838ccd44f1c65ac4

See more details on using hashes here.

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

Hashes for stansmicropy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb642bbd9dea2a6fd99d955eda4862af0c480a385cb75fd3d2ff31ce993da34a
MD5 64f71b3d0ac756855d6d2e9740197458
BLAKE2b-256 fe12decfc4b26f7c8080f463dce8788b7b3acf65182c7bdb56cf983bbadd0b38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page