Thursday, March 28, 2024
Embedded & MCUExplainerIoT Software&ToolsMicrocontrollers

MicroPython : optimized to run on a microcontroller

MicroPython is a software implementation of the Python 3 programming language, written in C, that is optimized to run on a microcontroller. It is a full Python compiler and runtime that runs on the micro-controller hardware. The user is presented with an interactive prompt (the REPL) to execute supported commands immediately. Included are a selection of core Python libraries; It includes modules which give the programmer access to low-level hardware.

It was originally created by the Australian programmer and physicist Damien George, after a successful Kickstarter backed campaign in 2013. While the original Kickstart campaign released MicroPython with a pyboard microcontroller, MicroPython supports a number of ARM based architectures. MicroPython has since been run on Arduino platform based products, ESP8266, ESP32, and Internet of thingshardware. In 2016 a version of MicroPython for the BBC Micro Bit was created as part of the Python Software Foundation’s contribution to the Micro Bit partnership with the BBC. In 2017, Microsemi made a MicroPython port for RISC-V (RV32 and RV64) architecture.

It 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.

Micro Python 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.

Micro Python has some unique features that set it apart from other embedded systems:

  • Interactive REPL, or read-evaluate-print loop.  This allows you to connect to a board and have it execute code without any need for compiling or uploading–perfect for quickly learning and experimenting with hardware!
  • Extensive software library.  Like the normal Python programming langauge MicroPython is ‘batteries included’ and has libraries built in to support many tasks.  For example parsing JSON data from a web service, searching text with a regular expression, or even doing network socket programming is easy with built-in libraries for MicroPython.
  • Extensibility.  For advanced users MicroPython is extensible with low-level C/C++ functions so you can mix expressive high-level MicroPython code with faster low-level code when you need it.

What is The pyboard?

The pyboard is the official MicroPython microcontroller board with full support for software features. The hardware has:

  • STM32F405RG microcontroller
  • 168 MHz Cortex M4 CPU with hardware floating point
  • 1024KiB flash ROM and 192KiB RAM
  • Micro USB connector for power and serial communication
  • Micro SD card slot, supporting standard and high capacity SD cards
  • 3-axis accelerometer (MMA7660)
  • Real time clock with optional battery backup
  • 24 GPIO on left and right edges and 5 GPIO on bottom row, plus LED and switch GPIO available on bottom row
  • 3x 12-bit analog to digital converters, available on 16 pins, 4 with analog ground shielding
  • 2x 12-bit digital to analog (DAC) converters, available on pins X5 and X6
  • 4 LEDs (red, green, yellow and blue)
  • 1 reset and 1 user switch
  • On-board 3.3V LDO voltage regulator, capable of supplying up to 250mA, input voltage range 3.6V to 16V
  • DFU bootloader in ROM for easy upgrading of firmware

What is CircuitPython? How does it relate to MicroPython?

CircuitPython is Adafruit’s open source derivative of MicroPython.  This version of MicroPython was created to add support for easily getting started with electronics using boards like Circuit Playground Express, Trinket M0, Gemma M0, and more.  Check out the CircuitPython documentation for more details about it, including a list of differences between CircuitPython and MicroPython.

In almost all cases you can do the same things with both CircuitPython and MicroPython.

What can Micro Python do? What can’t Micro Python do?

In short, MicroPython can do a lot! Just like an Arduino board and many other boards Micro Python can control hardware and connected devices. You can control GPIO pins to blink lights, read switches, and drive PWM outputs for servos, LEDs, etc. or read analog sensors with an analog to digital converter. Connect with I2C or SPI devices, OLED Display is easy too.

MicroPython code isn’t as fast and might use a little more memory compared to similar Arduino or other low-level C/C++-based code. Usually this doesn’t matter since the speed and memory differences are small and don’t impact most normal uses. The Micro Python langauge implements most of the core Python 3 language, however MicroPython can’t implement the entire Python 3 standard library.

Completely free, open source software

Micro Python is written in C99 and the entire Micro Python core is available for general use under the very liberal MIT license. Most libraries and extension modules (some of which are from a third party) are also available under MIT or similar licenses. You can freely use and adapt Micro Python for personal use, in education, and in commercial products.

Micro Python 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.

What hardware supports Micro Python?

Be sure to check the MicroPython website to see the latest information on supported boards.

  • pyboard
  • ESP8266
  • SAMD21-based Boards
  • Teensy 3.x
  • BBC micro:bit
  • WiPy
  • Espruino Pico
  • STM32F4 Discovery board
  • Adafruit Circuit Playground Express

Source: http://micropython.org/, https://learn.adafruit.com, Wikipedia


You may like also:


 

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

6 thoughts on “MicroPython : optimized to run on a microcontroller

Leave a Reply

Your email address will not be published. Required fields are marked *