PyMCU Libraries#

Architectural Shift: MicroPython Compatibility

PyMCU’s standard library is being restructured. The official user-facing API will soon be aligned with the MicroPython / CircuitPython machine and board modules.

The modules documented below (pymcu.hal.* and pymcu.drivers.*) are considered internal foundations (HAL). While they work perfectly, they are designed to be wrapped by the upcoming compatibility layers. Users are strongly encouraged to use the machine module (when available) for better portability across different hardware.

The PyMCU internal library provides hardware abstraction layer (HAL) modules and device drivers. All modules compile to tight native machine code — there is no Python runtime on the device.

Internal HAL modules#

Module

Import path

Description

GPIO / Pin

pymcu.hal.gpio

Digital I/O, pin interrupts

UART

pymcu.hal.uart

Serial communication

ADC

pymcu.hal.adc

Analog-to-digital conversion

DAC

pymcu.hal.dac

Analog output — refused on every part PyMCU targets today, and says what to use instead

Timer

pymcu.hal.timer

Hardware timers

PWM

pymcu.hal.pwm

Pulse-width modulation

Pulses

pymcu.hal.pulse

Measuring the pulses on a pin, and sending a gated carrier

SPI

pymcu.hal.spi

SPI bus (hardware + soft)

I2C

pymcu.hal.i2c

I2C bus (hardware + soft)

EEPROM

pymcu.hal.eeprom

Non-volatile byte storage

Watchdog

pymcu.hal.watchdog

Watchdog timer

Power / Sleep

pymcu.hal.power

Sleep modes

Time / Delays

pymcu.time

Busy-wait delays

Device drivers#

Driver

Import path

Description

DHT11

pymcu.drivers.dht11

Temperature and humidity sensor

Third-party libraries#

Writing a PyMCU library — package layout, manifest, architecture dispatch and publishing, for anyone shipping a driver of their own.

Cross-backend parity#

HAL Parity — a generated report comparing the public API each architecture backend offers against the facade, and auditing the CircuitPython and MicroPython compatibility layers for chip-specific code that should live in the HAL instead.

Design principles#

All HAL classes are @inline — they have zero SRAM cost. Instantiating a Pin or UART compiles to register writes; no struct is allocated on the MCU. See Type System for details on the Zero-Cost Abstraction model.