The MicroPythonMCU.Examples package holds 52 ready-to-simulate models: open the model, simulate, plot the listed variables. Each one runs the program named in the "Program" column, to be read alongside: in Resources/Scripts/MCU/, or in Resources/Verification/ for those marked (V). The examples also serve as scenarios for the library's verification suite. Program comments and printed messages are in French.
Chaser on 8 LEDs placed around the microcontroller
LED icons (animated replay)
led_chaser.py
Gpio.PinEcho
GP1 toggles, GP2 reads back its electrical state, GP3 copies it
mcu.GP1.v, mcu.GP3.v
pin_echo.py
Gpio.InputReactivity
A button on GP1 wakes the program during a sleep(3600)
mcu.GP1.v, program output
input_reactive.py(V)
Gpio.Timing
Cost of a pin access (gpioOpTime): on()/off() pulse without sleep, burst, busy-wait, masked IRQ
mcu.GP0.v (zoom to the µs)
gpio_timing.py(V)
Gpio.Pull
Internal pull resistors: two buttons without any external resistor (Pin.PULL_UP to ground, Pin.PULL_DOWN to 3.3 V), and a pin whose pull changes against a 1 MΩ external resistor
mcu.GP0.v, mcu.GP3.v, mcu.GP4.v
gpio_pull.py
Gpio.InputReactivity: an input edge interrupts a one-hour sleep(). Figure labels are in French: « bouton » = button, « le programme dort » = the program sleeps, « réveillé par le front de GP1 : led.on() aussitôt » = woken up by the edge of GP1: led.on() at once.
Gradual change of the duty cycle: the LED fades in
LED icon, led0.p.i
pwm_led_fade.py
Figure labels are in French: « temps » = time, « courant LED » = LED current, « rapport cyclique » = duty cycle.
Pwm.LedFade: duty cycle written by duty_u16() every millisecond (top), and the 1 kHz PWM signal at 25 % and 75 % (bottom). Figure labels are in French: « rapport cyclique » = duty cycle, « temps » = time.
The LogicAnalyzer probe decodes the wires of a circuit into a text file, opened in Notepad at the end of the simulation, and records them in a VCD file for PulseView (Logic analyser).
Example
What it shows
What to watch
Program
Analyzer.UartLink
Probe on both wires of the 8E2 link of Uart.Format, channels of kind Uart
UartLink.analyzer.txt: "Hello, parity!" in hex + ASCII, bits and bytes under the timing diagram; the echo overlaps the message
uart_format.py
Analyzer.UartErrors
Same probe, device in odd parity (Uart.FormatMismatch)
bytes sent back marked ! and !P
uart_format.py
Analyzer.I2cBus
Probe on the bus of I2c.Echo: SCL as Logic, SDA as I2cSda
one line per transaction, NACK ending a read, repeated START
i2c_echo.py
Analyzer.Hx711Serial
Probe on the PD_SCK/DOUT link of Weighing.Hx711Read, DOUT as SyncData (24 bits, MSB first)
one word per conversion, gain pulses, compressed silences