This is an old revision of the document!


Table of Contents

Micropython

MicroPython implements the Python programming language optimized for microcontrollers and embedded systems that are resource-constrained devices. It is simple and enables rapid prototyping.

Here are some key features and characteristics of MicroPython:

  1. MicroPython is designed to run on devices with limited memory and processing power. It has a small storage and RAM footprint.
  2. MicroPython is compatible with Python 3 syntax.
  3. MicroPython includes a Read-Eval-Print Loop (REPL), which allows developers to run interactively and test code on a microcontroller line by line and evaluate results immediately. This feature is invaluable for debugging and tracing.
  4. MicroPython provides a rich set of libraries and modules for interacting with hardware components such as GPIO pins, sensors, motors, displays and networking capabilities that make it suitable for building IoT devices.
  5. MicroPython is designed to be cross-platform. including popular ones like the ESP8266, ESP32, Raspberry Pi Pico, and more. Developers should be aware of the hardware limitations that somehow reduce code portability.
  6. MicroPython has a growing community, shared libraries and sample projects. A package manager called “upip” also enables the installation of additional MicroPython libraries easily.
  7. MicroPython is released under an open-source license (typically the MIT License).
  8. MicroPython is designed to be power-efficient, crucial for battery-powered and energy-constrained devices.
  9. While Micropython is not a real-time operating system (RTOS) itself, it can be used in conjunction with RTOSes to build real-time systems, if only needed.
  10. MicroPython is a popular choice for educational purposes: thanks to REPL, the setup of the SDK is simple and quick.
Installation

Installation of the Micropython usually involves flashing firmware, specific for a microcontroller, that contains a Python interpreter and becomes de-facto a middleware between hardware and developer used with means of scripts. Micropython scripts can be executed inline via terminal (REPL), or a file with a source code (usually named main.py) can be uploaded to the drive's root folder exposed via USB connection by the MCUs firmware.

A website that is a starting point for Micropython is https://micropython.org[1].

The installation procedure is specific to the hardware platform and sometimes differs slightly from flashing C++-based solutions or burning an OS, as in the case of the RP2040. The main steps to prepare a working environment are presented below:

  • Download a Micropython binary image suitable for your hardware.
  • Switch the MCU into the bootloader mode that exposes a flash drive: in the case of the RP2040, the easiest way is to hold down the Bootsel button and power on the device while holding.
  • Move the firmware file into the flash drive; the device will flash and reboot.
  • Connect to the serial port exposed.
Development

Once Micropython is installed in the device, it exposes a terminal (REPL) via serial port, either on the dedicated GPIOs for serial or via serial over USB. Developing directly inline is possible (samples are presented in the following chapters) but it is not convenient for complex code. Complex and multi-file solutions can benefit from uploading files (even multiple) to the device. A file named main.py is automatically executed on device restart.

IDEs use those features to simplify development and enable remote code authoring and execution.

en/iot-open/scriptingprogramming/micropythonfundamentals.1699896101.txt.gz · Last modified: 2023/11/13 17:21 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0