O que é MicroPython?

What is MicroPython?

MicroPython implements the Python 3 programming language for microcontrollers and microcomputers. It is a firmware solution designed to implement Python's high-level language features on low-level hardware platforms. The firmware is optimized for running in constrained environments while enabling a small subset of standard Python 3 libraries for embedded programming.

The MicroPython firmware can run on a footprint of 256 Kilobytes and 16 Kilobytes of RAM. MicroPython can offer several high-level programming features such as arbitrary precision integers, object-oriented programming, generators, closures, exception handling, and list comprehension even with such limited code space and memory. Typically, such features are not available in typical microcontroller programming. All of these features are available with low-level hardware access through the MicroPython firmware machine module.

Additionally, the MicroPython compiler and runtime code includes an interactive prompt called REPL (Read-Eval-Print-Loop) that allows you to execute commands from a desktop computer directly on an embedded platform. Commands using REPL are executed via UART, where the target microcontroller board is connected to the host PC via USB. This is useful in fast, real-time testing and debugging of embedded systems.

One of the notable high-level language features enabled in MicroPython is multithreading. Typically, bare metals do not have multithreading capabilities. The multithreading feature of MicroPython firmware allows you to accelerate embedded applications by handling many embedded tasks simultaneously from a single microcontroller and allows you to think through typical programming loops.

MicroPython is open source
MicroPython is available for general use under the MIT license. Many of its modules and libraries are also available under MIT license or similar open source license. MicroPython is free for educational and commercial use. Anyone can use and modify the firmware. It is an open source project with source code available on Github. As an open source project, MicroPython is open to contributions from the community. If you are looking for a firmware version targeting a specific hardware platform, microcontroller, port, or feature, check the official MicroPython download link.

MicroPython vs Python
MicroPython is largely an implementation of Python 3.4 with some selected features from Python 3.5 and higher. Many standard CPython libraries have been rewritten in C99 to run on restricted bare metal environments (microcontrollers and microcomputers without any operating system) as part of MicroPython. These micro-formed standard Python libraries form the core of MicroPython firmware. Not all of Python's standard libraries were rewritten to form MicroPython; MicroPython is a subset of standard Python. Includes reimplementation of only those Python libraries that may be useful in embedded systems programming or programmatic enhancement of embedded applications.

MicroPython may differ in syntax and behavior from standard Python equivalent operators, functions, and modules in many places. Many of these conflicts are listed in the following link. Except for a few conflicts listed in the link mentioned above, most of MicroPython's syntax and programming is compatible with the standard Python documentation.

A microcontroller board, RTOS, or operating system that supports MicroPython is called a MicroPython port. It is important to know that many MicroPython core features may be unavailable for a given port, that is, they may not be supported on a given microcontroller, RTOS, or operating system. Additionally, a specific port may have additional MicroPython modules and functionality. For example, the MicroPython version for ESP32 and ESP8266 has additional libraries and functions available to handle network connections and supports WebREPL (REPL over web sockets).

Supported Boards and MicroPython Ports
MicroPython is available for several common platforms, including x86, x86-64, ARM-Thumb, and Xtensa. It is extremely fast, with code execution possible at speeds of up to 168 MHz. The official microcontroller board supported by MicroPython is the pyboard. Pyboard has the following important features.

-> STM32F405RG Microcontroller
-> 168 MHz Cortex M4 CPU with hardware floating point
-> 1024KiB flash ROM
-> 192KiB of RAM
-> Micro SD card slot
-> Micro USB port
-> Integrated 3-axis accelerometer and RTC
-> 29GPIO; 3x 12-bit ADC available on 16 pins 4 with analog ground shield and 2x 12-bit DAC available on pins X5 and X6.

Not just on pyboard, MicroPython can be used on many other microcontroller boards from STMicroelectronics. Some of the STMicroelectronics microcontrollers with full MicroPython firmware support are listed below.

-> Pico sprue (STM32F401CD)
-> BLACK STM32F407VET6 (STM32F407VE)
-> BLACK STM32F407ZET6 (STM32F407ZE)
-> BLACK STM32F407ZGT6 (STM32F407ZG)
-> DID Cerb40 II (STM32F405RG)
-> G30HDR Module (STM32F401RE)
-> Lemur FEZ (STM32F401RE)
-> Netduino Plus 2 (STM32F405RG)
-> OpenMV (STM32F765)
-> Core/Dev Board HY-STM32F4xxCore144 (STM32F407ZGT6)
-> HydraBus V1.0 (STM32F405RG)
-> Olimex STM32-405STK (STM32F405RG)
-> Olimex STM32-E407 (STM32F407ZG)
-> CORE F401RE (STM32F401RE)
-> STM Discovery STM32F401 (STM32F401VC)
-> STM Discovery STM32F407 (STM32F407VG)
-> STM Discovery STM32F429 (STM32F429ZI)
-> STM Discovery STM32F746G (STM32F746NG)
-> STM32F407VET6 Mini (STM32F407VE)

In addition to the STMicroelectronics microcontrollers listed above, MicroPython supports the following notable embedded platforms.

-> ESP32
-> ESP8266
-> Micro:Bit
-> WiPy and CC3200
-> Pyboard D Series
-> Teen 3.X
-> Adafruit Playground Express Circuit
-> Arduino Due
-> Cypress FreeSOC
-> Raspberry Pi Pico

MicroPython boards and ports

Examples of MicroPython boards and ports

Zephyr is one of the real-time operating systems supported by MicroPython. MicroPython can run as a thread on other RTOS like pyRTOS and FreeRTOS.

MicroPython Libraries
The MicroPython core includes the implementation of several Python 3.4 standard libraries, which consists of an array, binascii, builtins, cmath, collections, errno, gc, hashlib, heapq, io, json, math, os, random, re, select , socket, ssl, struct, sys, time, uasyncio, zlib and _thread. Other libraries included in MicroPython are hardware specific. They are called microlibraries, including Bluetooth, btree, cryptolib, framebuf, machine, micropython, neopixel, network, and uctypes.

Port-specific libraries
Different microcontroller boards and RTOS offer additional features and core microcontroller operations. MicroPython includes libraries specific to specific microcontroller boards and real-time operating systems to exploit their unique capabilities. For example, the port-specific version of MicroPython for pyboard includes libraries such as pyb, stm, and lcd160cr. The port-specific version of MicroPython for WiPy includes wipy library and additional classes such as ADCChannel, TimerChannel, TimerWiPy, and ADCWiPy. The port-specific version of MicroPython for ESP8266 and ESP32 boards includes esp and esp32 packages. The rp2 package is additionally included in the MicroPython version for Raspberry Pi Pico. An additional module, zephyr, is bundled in the MicroPython version for Zephyr RTOS.

Additional Python libraries from micropython-lib
MicroPython core modules are called modules in MicroPython terminology. In addition to selected standard Python libraries rewritten to form the main MicroPython, many other standard Python libraries have been rewritten into MicroPython projects. These libraries can be accessed as a separate distribution in the form of micropython-lib. Most of these libraries/modules use FFI for operating system specific functionality. This is why micropython-lib can generally only be used on hosts with POSIX-compliant operating systems such as Linux, FreeBSD, Solaris, MacOS, etc. Unlike standard MicroPython modules, micropython-lib modules need to be installed using upip or by copying unzipped packages manually.

Extending MicroPython libraries
It is also possible to extend the implementation of built-in MicroPython libraries. Any user-defined module named module.py replaces the standard MicroPython module within a package. The package can still use the built-in functionality by importing the u module directly. Most of the libraries in micropython-lib are written in the same way.

Conclusion
MicroPython could be the next revolution in the world of microcontrollers after Arduino. Firstly, MicroPython performed the main task of introducing Python into MCU-based microcontrollers and embedded systems. Python is the one-stop shop for developing networked, AI-backed applications. The use of multithreading in embedded applications will be another important milestone established by the MicroPython initiative.

Conteúdo Relacionado

A network of sensors is embedded in every vehicle,...
The motor controller is one of the most important...
ESP32-CAM is a compact camera module that combines the...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
Determinar uma localização precisa é necessário em várias indústrias...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
You have probably come across the term ' drag...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
You have probably experienced situations where controlling a circuit...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.