Micro Python
Micro Python
MicroPython is a lean and efficient implementation of the Python 3programming language that includes a
small subset of the Python standard library and is optimised to run on microcontrollers and in constrained
environments.
The MicroPython pyboard is a compact electronic circuit board that runs MicroPython on the bare metal,
giving you a low-level Python operating system that can be used to control all kinds of electronic projects.
MicroPython is packed full of advanced features such as an interactive prompt, arbitrary precision integers,
closures, list comprehension, generators, exception handling and more. Yet it is compact enough to fit and
run within just 256k of code space and 16k of RAM.
MicroPython aims to be as compatible with normal Python as possible to allow you to transfer code with
ease from the desktop to a microcontroller or embedded system.
TEST DRIVE A PYBOARD BUY A PYBOARD USE MICROPYTHON ONLINE
MicroPython is a full Python compiler and runtime that runs on the bare-metal. You get an interactive
prompt (the REPL) to execute commands immediately, along with the ability to run and import scripts
from the built-in filesystem. The REPL has history, tab completion, auto-indent and paste mode for a great
user experience.
MicroPython strives to be as compatible as possible with normal Python (known as CPython) so that if you
know Python you already know MicroPython. On the other hand, the more you learn about MicroPython
the better you become at Python.
In addition to implementing a selection of core Python libraries, MicroPython includes modules such as
"machine" for accessing low-level hardware.
import pyb
# turn on an LED
pyb.LED(1).on()
Example 1 / 7
The pyboard
The pyboard is the official MicroPython microcontroller board with full support for software features. The
hardware has:
o STM32F405RG microcontroller
o 24 GPIO on left and right edges and 5 GPIO on bottom row, plus LED and switch GPIO available on
bottom row
o 3x 12-bit analog to digital converters, available on 16 pins, 4 with analog ground shielding
o On-board 3.3V LDO voltage regulator, capable of supplying up to 250mA, input voltage range 3.6V
to 16V
o DFU bootloader in ROM for easy upgrading of firmware
Visit the store to order!
You can freely use and adapt MicroPython for personal use, in education, and in commercial products.
MicroPython is developed in the open on GitHub and the source code is available at the GitHub page, and
on the download page. Everyone is welcome to contribute to the project.
MicroPython employs many advanced coding techniques, and lots of tricks to maintain a compact size
while still having a full set of features.
o extensive test suite with over 590 tests, and more than 18,500
individual testcases
o code coverage at 98.4% for the core and at 96.3% for the core plus
extended modules
o fast start-up time from boot to loading of first script (150
microseconds to get to boot.py, on PYBv1.1 running at 168MHz)
o a simple, fast and robust mark-sweep garbage collector for heap
memory
o errors have a backtrace and report the line number of the source
code
o support for 30-bit stuffed floats, which don't require heap memory
o a native emitter that targets machine code directly rather than the
bytecode virtual machine
Online resources
You can learn more about MicroPython and keep up-to-date with developments via the following
resources:
o subscribe to the newsletter
o read the documentation
o join the community at the forum
o submit bug reports, and follow and join in development on GitHub
Take me to the store!
import pyb
import time
sw = Switch()
sw.value() # returns True or False
sw.callback(lambda: pyb.LED(1).toggle())
Pins and GPIO
See pyb.Pin.
rtc = RTC()
rtc.datetime((2017, 8, 23, 1, 12, 48, 0, 0)) # set a specific date and time
rtc.datetime() # get date and time
PWM (pulse width modulation)
See pyb.Pin and pyb.Timer.
adc = ADC(Pin('X19'))
adc.read() # read value, 0-4095
DAC (digital to analog conversion)
See pyb.Pin and pyb.DAC.
dac = DAC(Pin('X5'))
dac.write(120) # output between 0 and 255
UART (serial bus)
See pyb.UART.
accel = Accel()
print(accel.x(), accel.y(), accel.z(), accel.tilt())
Next Previous