Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

What is MicroPython?

By Nikhil Agnihotri

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

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

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

One of the notable high-level language features allowed in MicroPython is multithreading. Typically, bare metals are void of multithreading capabilities. The multithreading feature of MicroPython firmware allows speeding up embedded applications by handling many embedded tasks simultaneously from a single microcontroller and lets you think out of the typical programming loops.

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

MicroPython vs. Python
MicroPython is largely an implementation of Python 3.4 with some select Python 3.5 and above features. Many standard CPython libraries have been rewritten in C99 to run within constraint environments of bare metals (microcontrollers and microcomputers without any operating system) as part of MicroPython. These micro-fied standard Python libraries form the core of MicroPython firmware. Not all standard Python libraries have been rewritten to form MicroPython; MicroPython is a subset of standard Python. It includes the re-implementation of only those Python libraries that may be useful in programming embedded systems or programmatically enhancing embedded applications.

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

A microcontroller board, RTOS, or operating system supported by MicroPython is called a MicroPython Port. It is important to know that many features of core MicroPython may be unavailable for a particular port, i.e., it may not be supported in a given microcontroller, RTOS, or operating system. Plus, a particular port may have additional modules and functionalities of MicroPython. 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 remarkably fast, with code execution possible at speeds up to 168 MHz. The official microcontroller board supported by MicroPython is pyboard. The pyboard has the following salient features.

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

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

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

Apart from the above-listed microcontrollers of STMicroelectronics, MicroPython supports the following notable embedded platforms.

-> ESP32
-> ESP8266
-> Micro:Bit
-> WiPy and CC3200
-> Pyboard D-Series
-> Teensy 3.X
-> Adafruit Circuit Playground Express
-> 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 in other RTOS like pyRTOS and FreeRTOS.

MicroPython libraries
The core MicroPython includes implementation of several standard Python 3.4 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. These are called micro-libraries, 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 particular microcontroller boards and real-time operating systems to exploit their exclusive features. For example, the port-specific version of MicroPython for pyboard includes libraries like pyb, stm, and lcd160cr. The port-specific version of MicroPython for WiPy includes wipy library and additional classes like 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, comes packaged in the MicroPython version for Zephyr RTOS.

Additional Python libraries from micropython-lib
The core MicroPython modules are called umodules in the MicroPython terminology. Apart from the select standard Python libraries rewritten to form core MicroPython, many other standard Python libraries have been rewritten in 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 OS-specific functionalities. That is why micropython-lib can be generally used only on hosts with POSIX-compatible operating systems like Linux, FreeBSD, Solaris, MacOS, etc. It has limited support for Windows. Unlike standard MicroPython modules, micropython-lib modules need to be installed either using upip or 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 overwrites the standard MicroPython umodule within a package. The package can still use the built-in functionalities by importing the u-module directly. Most of the libraries in micropython-lib have been written in the same manner.

Conclusion
MicroPython can be the next revolution in the microcontroller world after the Arduino. First of all, MicroPython has accomplished the major task of introducing Python to microcontrollers and MCU-based embedded systems. Python is the one-stop for developing networked and AI-backed applications. The use of multithreading in embedded applications will be another important milestone set by the MicroPython initiative.

You may also like:

  • Python basics
    RPi Python Programming 07: Python basics (part 2)

  • RPi Python Programming 08: Python lists and byte arrays
  • Object-Oriented Python
    RPi Python Programming 10: Object-oriented Python

  • How to use Raspberry Pi camera module with Python

  • How to Make First Python Program with Beaglebone Black (Part…
  • Raspberry Pi 4
    RPi Python Programming 01: Introduction to Raspberry Pi 4

Filed Under: Tutorials
Tagged With: MicroPython, MicroPython Boards, MicroPython Firmware, MicroPython libraries, MicroPython Ports, micropython-lib, What is MicroPython
 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Op amp non inverting amplifier not working
  • Measure AC current accurateley (100mA to 10A)
  • Avalanche Pulser
  • Fpga wake up
  • RCF Subwoofer Amplifier PIC16F870-I/SP please help me about hex code

RSS Electro-Tech-Online.com Discussions

  • How to search component to replace my burn RF inductor?
  • Need a ducted soldering fan for solder smoke extraction
  • Someone please explain how this BMS board is supposed to work?
  • bluetooth jammer
  • Disabled son needs advice please
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering