Skip to content

MicroPythonMCU

A Python-programmable microcontroller to drop into an OpenModelica diagram.

MicroPythonMCU is an OpenModelica library whose MCU block runs a real Python script written against the MicroPython API (machine, time) of the Raspberry Pi Pico (official documentation, rp2 port). Its pins are real electrical nodes: the script drives and measures the Modelica circuit around it. You can develop embedded code on the digital twin of a system before flashing it onto the real board.

The BasicBlink model being simulated: the LED blinks

  • User guide


    Install the library, simulate a first example, write your own program and wire peripherals. No knowledge of the internals is needed.

    Getting started · The MCU block · API · Examples

  • Maintainer reference (in French)


    For those who develop the library: architecture, CPython integration, synchronisation protocol with the solver, serial and I2C engines, verification suite, releases.

    Architecture · Life cycle · Tests

What the microcontroller can do

Feature Script-side API Details
Digital inputs / outputs, interrupts, bit-banging Pin, Pin.irq() API
Analog input, PWM output ADC, PWM API
Timers, delays Timer, time.sleep() API
Electrical serial link UART Serial devices
Open-drain I2C master bus I2C I2C devices
Flash-like file system, boot.py / main.py open(), os API
Module imports, off-the-shelf drivers import The MCU block
Raspberry Pi Pico board: real pinout, USB / battery supply, power-on RPi_Pico (block) The Raspberry Pi Pico board

A time.sleep(1) costs no real time: the solver jumps straight to the deadline. One simulated hour runs in a fraction of a second.

Supplied peripherals

LED, teaching display, serial devices (echo, temperature sensor, GPS, 20x2 display, generic device), I2C devices (Grove LCD RGB display, echo, generic device) a complete weighing chain (load cell, strain-gauge bridge, HX711 converter), a logic analyser probe and radio modules (set up like an APC220 by default) whose modulated signal is drawn. The 48 examples use all of them, up to a kitchen scale that runs off-the-shelf MicroPython drivers unmodified.

Current limits

Windows only, no SPI. A model can hold several microcontrollers, which talk through their pins, a serial link or an I2C bus. Full list: Limits and troubleshooting.

Background

Library designed by Benoit Delaup, an engineering science teacher, so that students can test their control code on the digital system before deploying it to a real prototype; it also fits an industrial embedded-software digital twin. Source code and issues: GitLab repository. Architecture choices and their alternatives are recorded (in French) in requirements.md.

The library (code, tests and documentation) was developed with the help of an AI, under the direction of the author, who set its choices and reviewed the result.