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.
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 16KiB.
Example on the command line:
The RIOT port of MicroPython currently resides in a fork at https://github.com/kaspar030/micropython (in branch add_riot_port). It is based on Micropython's "ports/minimal" with some extra modules enabled. It reuses the gc_collect code from ports/unix, which has special support for i386 and Cortex-M. On other platforms, it uses setjmp() to collect registers.
It is possible to run MicroPython's test suite for testing this port.
Currently, the port enables only a subset of the available MycroPython modules. See "ports/riot/mpconfigport.h" for details.
For now, the utime module has RIOT specific code and should work as expected.
Currently, these are implemented:
>>> import riot >>> print(riot.thread_getpid())
>>> import xtimer >>> >>> a = 0 >>> def inc_a(): >>> global a >>> a += 1 >>> >>> t = xtimer.xtimer(inc_a) >>> t.set(100000) >>> print(a)
See examples/micropython for example code.
|MicroPython RIOT specific API. |