| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/MicroPython |
| MicroPython | |
|---|---|
| Developer | Damien P. George |
| Release | 3 May 2014;12 years ago (2014-05-03) |
MicroPython is a software implementation of a programming language largely compatible with Python 3, written in C, that is optimized to run on a microcontroller.
MicroPython consists of a Python compiler to bytecode and a runtime interpreter of that bytecode. The user is presented with an interactive prompt (the REPL) to execute supported commands immediately. Included are a selection of core Python libraries; MicroPython includes modules which give the programmer access to low-level hardware.
MicroPython does have an inline assembler, which lets the code run at full speed, but it is not portable across different microcontrollers.
The source code for the project is available on GitHub under the MIT License.
help(): help messageMicroPython is a lean and efficient implementation of Python with libraries similar to those in Python. Some standard Python libraries have an equivalent library in MicroPython renamed to distinguish between the two. MicroPython libraries are smaller with less popular features removed or modified to save memory.
The three types of libraries in MicroPython:
MicroPython is highly customisable and configurable, with language differing between each board (microcontroller) and the availability of libraries may differ. Some functions and classes in a module or the entire module may be unavailable or altered.
| Library name | Description |
|---|---|
| array | operations on arrays |
| cmath | provides math functions for complex numbers |
| gc | garbage collector |
| math | provides basic math operations for floating-point numbers |
| sys | system-level functions; provides access to variables used by the interpreter |
| binascii | functions for converting between binary and ASCII |
| collections | operations for collections and container types that hold various objects |
| errno | provides access to error codes |
| hashlib | operations for binary hash algorithms |
| heapq | operations to implement heap queue algorithm |
| io | operations for handling input/output streams |
| json | handles conversion between JSON documents and Python objects |
| os | functions for filesystem access and basic operating system functions |
| re | implements regular expression matching operations |
| select | functions for handling events on multiple streams |
| socket | connecting to sockets (networks), providing access to socket interface |
| struct | performs conversions to Python objects by packing and unpacking primitive data types |
| time | provides time and date function, including measuring time intervals and implementing delays |
| zlib | operations to decompress binary data |
| Library name | Description |
|---|---|
| framebuf | provides a frame buffer that can be used to create bitmap images to be sent to a display |
| machine | functions assisting with accessing and interacting with hardware blocks |
| micropython | access and control of MicroPython internals |
| network | assists with installing network driver, allowing interactions through networks |
| ctypes | access binary data structures |
When developers begin to create a new application, standard MicroPython libraries and drivers may not meet the requirements, with insufficient operations or calculations. Similar to Python, there is the possibility of extending MicroPython's functionality with custom libraries which extend the ability of the existing libraries and firmware.
In MicroPython, files ending with .py take preference over other library aliases which allows users to extend the use and implementation of the existing libraries.
As MicroPython's implementation and popularity continues to grow, more boards have the ability to run MicroPython. Many developers are building processor specific versions that can be downloaded onto different microcontrollers. Installing MicroPython on microcontrollers is well documented and user-friendly. MicroPython allows interactions between microcontroller hardware and applications to be simple, allowing access to a range of functionality while working in a resource constrained environment, with a strong level of responsiveness.
The two types of boards used to run MicroPython:
To move a program onto a MicroPython board, create a file and copy it onto the microcontroller in order to execute. With the hardware connected to a device, such as a computer, the board's flash drive will appear on the device allowing files to be moved to the flash drive. There will be two existing python files, boot.py and main.py that are typically not modified, main.py may be modified if you wish to run the program every time the microcontroller is booted, otherwise, programs will be run using the REPL console.
The pyboard is the official MicroPython microcontroller board which fully supports MicroPython's software features. The pyboard's hardware features include:
The pyboard contains an internal drive with filesystem named /flash which is stored within the board's flash memory, additionally, a microSD card can be inserted into a slot and is accessible through /sd. When booted up, a pyboard must select a filesystem to boot from either /flash or /sd with the current directory being set to either /flash or /sd. By default, if an SD card is inserted, /sd will be used, if not, /flash is used. If needed, the use of the SD card for the booting process can be avoided by creating an empty file called /flash/SKIPSD which is stored on the board flash memory to skip the SD card for the booting process.
When the pyboard is powered up normally or the reset button is pressed then the pyboard is booted in a standard mode, meaning that the boot.py file is executed, then the USB configured and finally the python program will run.
There is an ability to override the standard boot sequence through holding down the user switch whilst the board is in the booting process and then pressing reset as you continue to hold the user switch. The pyboard's LEDs will flick between modes and once the LEDs have reached the mode wanted by the user, they can let go of the user switch and the board will boot in the specific mode.
the boot modes are:
Source:
Hello world program:
MicroPython includes a cross compiler which generates MicroPython bytecode (file extension .mpy). The Python code can be compiled into the bytecode either directly on a microcontroller or it can be precompiled elsewhere.
MicroPython firmware can be built without the compiler, leaving only the virtual machine which can run the precompiled mpy programs.
MicroPython is utilised through firmware being loaded by standard software onto a particular microcontroller into flash memory, communicating using a terminal application loaded onto a computer that emulates a serial interface.
The main uses of MicroPython can be generalised into three categories:
Implementation of MicroPython can differ depending on the availability of standard and supporting libraries and the microcontroller's flash memory and RAM size.
| View original on Wikipedia | Back | FazBrowse Home |