Outils pour utilisateurs

Outils du site


issue198:micro-ci

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).”

Micropython 1.21 est disponible !

Encore une fois, salutations, chers amis !

Habituellement, j'ai un plan pour ce que je vais écrire chaque mois et ce mois-ci est un mois normal. ET, comme d'habitude, dans 80 % du temps, le plan original n'est pas ce qui se retrouve dans l'article.

J'allais faire le point sur le terminal WIO et sur les progrès que j'ai faits dans le codage de l'affichage de l'écran. Cependant, comme vous le verrez, les statistiques ne mentent pas.

Le 6 octobre 2023, Micropython.org a publié la version 1.21. Il s'agit d'une mise à niveau majeure, tout comme l'a été la version 1.20.

Voici quelques-unes des choses qui ont changé dans la version 1.21 (extraites des notes de version) :

« Cette version de MicroPython voit le renommage des modules intégrés pour supprimer le préfixe u, un nouveau module, deflate, avec un support optionnel de la compression, l'introduction de variantes de cartes, la commutation du port esp32 pour utiliser IDF 5 avec une gestion améliorée du tas, le support de BLE sur les cartes RPi Pico W, et le support de STM32H5xx. Le projet utilise désormais codespell et ruff pour améliorer la qualité du code. Les nouvelles cartes ajoutées dans cette version sont : ARDUINO_NANO_ESP32 et UM_NANOS3 (port esp32), ADAFRUIT_METRO_M7 (portage de mimxrt), ARDUINO_PORTENTA_C33 et VK_RA6M5 (portage de renesas-ra), ADAFRUIT_METRO_M4_EXPRESS (portage de samd), NUCLEO_L4A6ZG et STM32H573I_DK (portage de stm32) ».

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.

Pour le charger sur la carte qui vous intéresse, téléchargez la dernière version (https://micropython.org/download/) et, en utilisant Thonny ou RShell, dans le REPL, tapez :

machine.bootloader()

Vous obtiendrez ainsi la fenêtre du gestionnaire de fichiers dans laquelle vous pourrez glisser et déposer le nouveau firmware.

Si vous utilisez Thonny, une fois que le microcontrôleur aura redémarré, vous verrez les informations de la nouvelle version dans le REPL. Sinon, lorsque vous branchez la carte et entrez dans le REPL, vous verrez la nouvelle version.

Je vais essayer de détailler quelques-unes des améliorations « génériques » et nous en examinerons certaines dans de futurs articles.

ESP-NOW

Selon espressif (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html), ESP-NOW est un type de protocole de communication Wi-Fi, sans connexion, défini par Espressif. Dans ESP-NOW, les données d'application sont encapsulées dans une trame d'action spécifique au fournisseur, puis transmises d'un appareil Wi-Fi à un autre sans connexion.

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)

J'ai lu des articles sur ESP-NOW depuis un certain temps, et j'ai voulu le tester, mais entre les contraintes de temps et d'autres projets, je n'ai jamais eu l'occasion de le faire. Maintenant qu'il est entièrement supporté par Micropython, je vais commencer à m'y intéresser et j'essaierai de vous donner quelques informations à ce sujet dans les mois à venir.

Support amélioré pour les f-strings en python

Micropython supporte les f-strings python « normales » depuis un certain temps, mais pour ma part, je n'arrive pas à trouver d'information sur la version qui a été la première à supporter les f-strings. Cela étant dit, il y a eu quelques ajouts au support des f-strings. Principalement le support des spécificateurs de conversion comme « !r ».

Si vous n'êtes pas familier avec les spécificateurs de conversion, jetez un coup d'œil à l'extrait suivant (page précédente, en bas à droite).

Il s'agit de l'« ancienne » façon d'imprimer des chaînes de caractères. La sortie de l'instruction print (en passant par which=1) ressemblerait à ceci :

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.

Maintenant, si nous modifions l'instruction print pour utiliser des f-strings, elle ressemblerait à ceci :

print(f“I2C configuration: {str(i2c)}”)

Cette sortie semble identique à l'« ancienne » méthode.

Pour essayer le nouveau drapeau de conversion « !r », vous le coderiez de la manière suivante :

print(f“I2C configuration: {i2c!r}”)

Et, devinez quoi, la sortie est exactement la même encore une fois.

I2C configuration: I2C(1, freq=399361, scl=7, sda=6, timeout=50000)

Alors, pourquoi le faire ? La réponse est que vous pouvez utiliser str(i2c) ou repl(i2c) et obtenir le même type de résultat. Mais les chaînes renvoyées par les deux fonctions, qui se ressemblent le plus souvent, sont de deux types différents.

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!

Voyez ce que dit Max Brenner (https://shipit.dev/posts/python-str-vs-repr.html):

Les indices suivants (ci-dessous) peuvent vous aider à décider quand utiliser lequel :

BLE dans RPi-W

BLE a été officiellement ajouté à Micropython 1.21 pour la carte RPi-W. Bien que c'était déjà dans les builds nocturns depuis un certain temps, c'est maintenant dans la version officielle. Nous y reviendrons dans de prochains articles.

C'est donc tout pour ce mois. Je sais que c'est plus court que d'habitude, mais j'économise pour le mois prochain.

D'ici là, comme toujours, restez en sécurité, en bonne santé, positifs et créatifs !

issue198/micro-ci.txt · Dernière modification : 2023/10/31 17:47 de andre_domenech