Ceci est une ancienne révision du document !
Micropython 1.21 Released!
Greetings again, fellow Beings!
Usually, I have a plan for what I’m going to write about each month and this month is a normal month. AND, and as normal, the original plan 80% of the time is not what actually gets into the article.
I WAS going to give an update on the WIO terminal and the progress that I’ve made on the screen display coding. However, as you will see, stats don’t lie.
On October 6, 2023, Micropython.org released version 1.21. This is a major upgrade, just as 1.20 was.
Just some of the things that have changed in version 1.21 include (from the release notes) :
“This release of MicroPython sees the renaming of built-in modules to remove the u-prefix, a new deflate module with optional compression support, the introduction of board variants, switching of the esp32 port to use IDF 5 together with improved heap management, support for BLE on RPi Pico W boards, and STM32H5xx support. The project is also now using codespell and ruff to improve code quality. New boards added in this release are: ARDUINO_NANO_ESP32 and UM_NANOS3 (esp32 port), ADAFRUIT_METRO_M7 (mimxrt port), ARDUINO_PORTENTA_C33 and VK_RA6M5 (renesas-ra port), ADAFRUIT_METRO_M4_EXPRESS (samd port), NUCLEO_L4A6ZG and STM32H573I_DK (stm32 port).”
To load it onto your board of interest, download the latest build (https://micropython.org/download/ ) and either you Thonny or RShell and in the REPL type:
machine.bootloader()
This will get you the file manager window that you can drag and drop the new firmware into. Assuming you are running Thonny, once the microcontroller reboots you’ll see the new version information in the REPL. Otherwise, when you plug into the board and go enter the REPL, you’ll see the new version.
I’ll try to break down just some of the “generic” enhancements and we’ll look at some of them in future articles.
ESP-NOW
According to the espressif (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html), ESP-NOW is a kind of connectionless Wi-Fi communication protocol that is defined by Espressif. In ESP-NOW, application data is encapsulated in a vendor-specific action frame and then transmitted from one Wi-Fi device to another without connection.
I’ve been reading about ESP-NOW for a while, and have wanted to test it, but between time constraints and other projects, I’ve just never gotten around to playing. Now that it is fully supported by Micropython, I will start concentrating on it and will try to give you some information on it in the next month or so.
Enhanced support for python f-strings
Micropython has supported “normal” python f-strings for a while, but for the life of me, I can’t find any information as to what version was the first to get f-strings. That having been said, there have been some additions to the f-string support. Mainly support for conversion specifiers like “!r”.
If you are not familiar with conversion specifiers, take a look at the following snippet (previous page, bottom right).
This is the “old” way to print strings. The output from the print statement (passing which=1) would look like this…
I2C configuration: I2C(1, freq=399361, scl=7, sda=6, timeout=50000)
Now, if we change the print statement to use f-strings, it would look like this…
print(f“I2C configuration: {str(i2c)}”)
This output looks identical to the “old” way.
Trying the new “!r” conversion flag, you would code it this way…
print(f“I2C configuration: {i2c!r}”)
And guess what, the output is exactly the same yet again.
I2C configuration: I2C(1, freq=399361, scl=7, sda=6, timeout=50000) So why bother. Well, the answer is that you can use str(i2c) or repl(i2c) and get the same kind of output. But, the strings returned by the two functions, which most times will look the same, are two different types.
Max Brenner (https://shipit.dev/posts/python-str-vs-repr.html ) says:
The following clues (below) might help you to decide when to use which:
BLE in RPi-W
BLE has officially been added in Micropython 1.21 for the RPi-W board. While this has been in the nightly builds for a while, it now is in the official release. We’ll be looking at this in future articles.
So that’s it for this month. I know this is shorter than normal, but I’m saving up for next month.
Until then, as always; stay safe, healthy, positive and creative!