Updated information for this post: In May 2020, LEGO released its LEGO MicroPython 2.0, which enhanced the functionality of LEGO MicroPython 1.0 dramatically. You could refer to another post: First Experience of LEGO MicroPython 2.0 for further information.
In April of 2019, LEGO Group released its first version of Python library for its well-known LEGO EV3 model. After burning an operation system image into a MicroSD card and inserting the card into the slot of the LEGO EV3, the user could use Visual Studio Code to load an extension module and then write code to drive motors, sensors, brick buttons, lights, etc.
However, do you know that before this official release, lots of LEGO fans have already set up their open-source community, which developed multiple operation systems to run on various hardwares, not only LEGO EV3 smart brick, but also FatCatLab and Raspberry Pi. The community also developed libraries to support the usage of various languages like Python, C, C++, Go, Java, etc.
In this post, I will compare the two versions of Python. One is LEGO officially released MicroPython, and the other is EV3DEV’s Python. I will explain their relations and also different functionalities. At the end of the posts, I will give my personal opinions on the choice of the two versions.
Relation between the Two Versions of Python
LEGO’s EV3 MicroPython runs on top of ev3dev with a new Pybricks MicroPython runtime and library. It also comes with a dedicated Visual Studio Code extension that includes project templates and documentation to get started (refer to EV3Dev article).
What is EV3Dev?
Open www.ev3dev.org, you could get all around information about EV3Dev.
To quote its own introduction:
“ev3dev is a Debian Linux-based operating system that runs on several LEGO® MINDSTORMS compatible platforms including the LEGO® MINDSTORMS EV3 and Raspberry Pi-powered BrickPi.
Just like you can take apart your LEGO® models and build something completely different, we have reverse-engineered the EV3 and created a new software platform for programming your robots.”
So Why MicroPython?
So why does LEGO use MicroPython? What is it different from standard Python? Here is the official explanation from MicroPython.
MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.Source: https://micropython.org/
EV3Dev Python is using the standard python, but it has also a version of EV3Dev MicroPython. You could find the detailed information and document at this place.
How to Install?
You could install both EV3 Micro Python and EV3Dev Python in a same machine and use them in the same VS Code environment. The two versions of Python have either starter project (EV3Dev Python) or project templates (EV3 MicroPython), so you could create both types of the projects and experience their difference of functionality.
|Install EV3Dev Python||https://sites.google.com/site/ev3devpython/setting-up-vs-code, please ensure to follow it step by step.|
|Install EV3 MicroPython||https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3|
Which is More Advantageous?
In the following sections, I will compare the methods and properties provided by both EV3Dev Python and EV3 MicroPython. You could decide which one is suitable for you.
EV3Dev Python has provided rich methods for Display module. It realizes all of the functions in the Display block (see below image), such as drawing different geometries, or writing text in specified pixels or grids of LCD screen.
Moreover, it could let user specify font size and font type, which is not an option in LEGO block language. As the original font size on LCD screen is super small, this function provides much convenience.
In contract, EV3 MicroPython apparently has not done much work in this regard. It just exposes very limited functions to the user. Totally there are three functions available:
brick.display.clear(); brick.display.text(); brick.display.image()
It even did not provide the functions to set the font size. Therefore, if you have ever tried the Ev3 MicroPython, you will know the problem. The font size is super mini, as small as an ant. Luckily, you could still “import os” and then set the font size, although it is not mentioned in the user guide at all (see below sample code). If you ask me where I found this function? I just copied it from EV3Dev Python and it worked!
In EV3Dev Python, buttons module realizes all of the functions in the original LEGO Block language. Meanwhile, it provides function to check the status of backspace button, which is not supported in LEGO Block language.
For EV3 MicroPython, there is only one function offered to access brick buttons: brick.buttons(), which returns a list of pressed buttons. As to which button is pressed, you need to realize this functionality by defining your own method, as shown below.
The Brick Button Light block in LEGO Block is renamed as Leds module in EV3DEv Python. It can set multiple colors, and also offer some predefined lighting patterns, such as police lights, circle lights and flash lights. Although those functions can be realized by users themselves, they really make the light setting a breeze.
Another enhanced functionality is that Leds module could set left and right light status separately.
Again, let’s see EV3 MicroPython. This module is named as “Light” and it provides only one function called brick.light(). It could set the light to different colors or set it to NONE to turn the light off. Except this, it could not get the light color or set color separately.
The sound module of EV3Dev Python realizes all of functions of LEGO Sound Block. Meanwhile, it has a new function called “speak”, which can convert text into speech and let the EV3 brick speak out. Amazing!
In EV3 MicroPython, Sound module exposes three simple methods. It has not text-to-speech functionality, nor playing note or other functions.
When you read till now, you might think that in comparison, EV3Dev Python is much more versatile than LEGO’s EV3 MicroPython. It seems that LEGO does not pay much attention to the display, sound and light modules. After all, all of those modules are supplementary to the basic and core functions of motor and sensors. So in the next post, let me compare the functionalities of Motors and various Sensors modules. See you then!
Note: All the analysis articles are copyright products of http://www.thecodingfun.com. Anyone re-posting them should credit author and original source. Anyone using them for commercial purposes or translating them into other languages should notify TheCodingFun and get confirmation first. All Rights Reserved.