MicroPython - Python for microcontrollers. More...
MicroPython - Python for microcontrollers.
MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.
MicroPython on RIOT has to be considered experimental. While the basic interpreter works fairly well on native and Cortex-M, it has not seen much testing.
The RIOT OS port targets microcontrollers that have at least 16 KiB of RAM and 256 KiB of flash. Although MicroPython has many different tuning options, the requirement provides a decent out-of-the-box experience.
Use the following environment variables in the application Makefile or from the command line to configure MicroPython:
MP_RIOT_HEAPSIZE: heap size for MicroPython, in bytes. Defaults to 16 KiB.Example on the command line:
This package builds upstream MicroPython. The RIOT port itself lives in this package's contrib/ directory. It is compiled with MicroPython's own build system, and is based on MicroPython's ports/minimal with some extra modules enabled.
MicroPython will handle interrupts in as scheduled callbacks, so they run in the MicroPython's thread context. This means an interrupt will have a bit of latency before the callback is executed.
It is possible to run MicroPython's test suite for testing this port.
Steps:
The default baud rate is 115200. The test will switch the interpreter into raw REPL mode for testing. Expect some tests to fail, depending on the enabled features and configured heap size.
MicroPython has a large number of built-in modules available. See the port configuration file contrib/mpconfigport.h for more details on the exact set of modules enabled in this port.
The following modules are built-in, but use RIOT's own APIs internally:
machine - ADC, GPIO, SPI and moretime - time functionsThe following RIOT specific modules are available:
riot - RIOT-specific functionsxtimer - xtimer subsystemYou can import these modules and then use help(<module name>) to introspect the available functions.
The callback does not run in interrupt context. When the timer fires, its execution is deferred via MicroPython's scheduler and runs in thread context. See the implementation details section for more information.
See examples/lang_support/community/micropython for example code.
Files | |
| file | modmachine.h |
| MicroPython machine module type declarations. | |
| file | mp_riot.h |
| MicroPython RIOT port core glue declarations. | |
| file | mpconfigport.h |
| MicroPython port configuration for RIOT. | |
| file | mphalport.h |
| MicroPython HAL port definitions for RIOT. | |
| file | qstrdefsport.h.in |
| Port-specific MicroPython qstr definitions. | |
| file | micropython.h |
| MicroPython RIOT specific API. | |