Site icon Meccanismo Complesso

 MicroPython – Python for programming microcontrollers

Introduction

Thanks to the success of Python as a programming language, today many developers have chosen this language in their projects and more and more people are familiar with and experience this language. So why microcontrollers are still programmed in C?

Well, things seem to be taking another direction. MicroPython has been released, a development software that allows the programming of microcontrollers using exclusively Python as a programming language. In this article we will see in detail MicroPython. We will also talk about PyBoard, a microcontroller board specifically designed to be programmed into Python.

MicroPython

MicroPython is an application based entirely on Python 3. This application allows all developers to program microcontrollers using some Python libraries that have been optimized to work on microprocessors normally mounted on microcontrollers.

The development on MicroPython is really simple. It does not require any installation, just open the corresponding web page (see here) on the official micropython.org website. In fact MicroPython is an application that works online, and so instead of installing an application on your computer you can work directly from the browser.

MicroPython

MicroPython has therefore been designed and designed specifically for programming on MicroControllers by adapting the standard Python libraries. In fact, once a program is written in Python, MicroPython compiles the code in a compact enough to be able to occupy a space limit of 256kB and run on devices with 16kB of RAM.

In addition, MicroPython works with highly standard Python code, so everything that is developed on this environment is also working in other development environments in Python, and vice versa.

Compiler with hardware-specific modules

The power of MicroPython is right in the compiler. In fact, this software has within it a series of hardware-specific modules so you can compile the code in Python appropriately depending on the microcontroller used.

But it is not limited to this. The other programming languages, such as C for Arduino for example, are generally used to write a program in its entirety, and once corrected, it is compiled and sent to the microcontroller to be executed (generally in loop). Whilst programming in Python, he knows very well that Python is a language that uses an interpreter. So you can use it to write programs or to work in runtime, launching one command at a time. Well, with MicroPython you can write one command at a time from the console, which is compiled in real time and sent to the microcontroller.

In fact, MicroPython has an interactive prompt (REPL) to execute the commands one at a time interactively, which are executed immediately. The REPL has a history, tab completion, auto-indent and copy-cut-paste functionality, all to make code development easy and simple.

Finally, MicroPython, in addition to the optimized standard library, has a series of modules (for example machine) that allows low-level access to the hardware.

MicroPython – Mandelbrodt example

For those interested in furthering the topic, you can find all the documentation on this site.

Otherwise there is currently a book full of examples for sale, which covers the whole subject in a comprehensive manner.

Python for Microcontrollers: Getting Started with MicroPython

The MicroPython project

MicroPython, developed in the C99 language, is an entirely opensource project. The code is licensed under the MIT license, and is available to everyone on GitHub. Anyone is free to download the code for study, or to contribute to the improvement and improvement of this project.

Previously you have seen that the most important aspects of this application are the advanced coding techniques that have been used to maintain the same features of Python, even though they have compiled small ones, in order to adapt to the scarce resources of microcontrollers.

Here are some features that have been published on the official website.

Pyboard

However, MicroPython has been developed taking into account a reference card, also developed primarily for working with Python. The name of this board is PyBoard.

This board is a completely open hardware project and therefore the electronic schemes are accessible to everyone. So you can make it and modify it at your convenience, but if you prefer to buy it is available online at a very reasonable price.

MicroPython pyboard

The specifications of this board can be summarized in the following list:

The board is equipped with a micro USB port for connection to the computer and for feeding. There is also a slot for inserting a microSD as a memory. It also has some very interesting integrated chips, such as an accelerometer, some analog-digital converters and 4 multicolour LEDs.

As you can see from the images of the pyboard, we can immediately notice an extensive pinout. The following figure shows in detail the function of each PIN present.

Conclusions

In this short article the MicroPython application was shown, a software that allows Python programming for microcontrollers. You have seen in detail the features of this totally opensource project and in particular of the compiler that is able to produce hardware-specific compiled code according to microcontrollers and small size. You also took a quick look at the pyBoard, a microcontroller developed specifically to be programmed into Python. In the next articles some tutorials on programming in Python will be proposed in this development environment.

[:]



Exit mobile version