Outils pour utilisateurs

Outils du site


issue182:micro-ci_micro-la

In my Python article for this month, I said “Being from Texas, most of us here have a tendency to “change horses in midstream” as the saying goes, and this month, I’m afraid I’m going to have to do just that.”. That applies even to the ‘Micro This Micro That’ article for this month. I try very hard to be consistent, but when issues come up with readers and/or users, I try to share information that might help other readers, especially when the topic is relevant to the subject of the articles. Last month, I said that I would expand on the compass project. My friend in Norway, Halvard, contacted me yesterday with an issue that dealt with his NeoPixel ring that I tried to help him with, and I thought I’d share that with you. He had found a new driver library for the Raspberry Pi Pico that was supposed to handle the NeoPixel devices a bit better than the “standard” statemachine version that we have used in the past. However, he was having a problem on his system, where, when he ran the example program, he set the number of LEDs to 24, but only 18 ever lit. That seemed very strange to me, so I started looking into his issue.

Dans l'article de ce mois sur Python, j'ai écrit : « Comme la plupart de ceux qui viennent du Texas, nous avons tendance à “changer de cheval en cours de route”, comme on dit, et ce mois-ci, j'ai bien peur de devoir le faire ». Cela s'applique même à l'article « Micro-ci micro-là ». J'essaie très fort d'être cohérent, mais lorsque des problèmes surviennent avec des lecteurs et/ou des utilisateurs, j'essaie de partager des informations qui pourraient aider d'autres lecteurs, surtout lorsque le sujet est en rapport avec le thème des articles. Le mois dernier, j'ai dit que j'allais développer le projet de la boussole. Mon ami norvégien, Halvard, m'a contacté hier pour me faire part d'un problème concernant son anneau NeoPixel, pour lequel j'ai essayé de l'aider, et j'ai pensé que je devais partager ça avec vous.

Il avait trouvé une nouvelle bibliothèque de pilotes pour le Raspberry Pi Pico qui était censée gérer les périphériques NeoPixel un peu mieux que la version statemachine « standard » que nous avons utilisée dans le passé. Cependant, il avait un problème sur son système, où, quand il a exécuté le programme d'exemple, il a réglé le nombre de LED à 24, mais seulement 18 se sont allumées. Cela m'a semblé très étrange et j'ai donc commencé à examiner son problème.

He pointed me to the repository for the driver which is https://github.com/shreyask21/neopixel_rp2040 . As I usually do, I downloaded the repository as a zip file rather than clone the folder. Once I got it downloaded, I unpacked it and copied the relevant files to a working folder. I already had the RPi Pico set up with the NeoPixel ring and the battery pack from trying to work on the next installment of the article from last month, so I thought I was good. Using Thonny, I copied the driver library and the example to the Pico and jumped in. The first thing I did was to change the Driver ‘In pin’ in the instantiation function call. led = neopixel_rp2040.neopixel(LEDS=2, PIN=16) To remind you, the PIN assignment is the GP16 pin which is the physical pin 21 of the Pico. In the example file the author uses led = neopixel_rp2040.neopixel(LEDS=2, PIN=22)

Il m'a indiqué le dépôt du pilote qui est https://github.com/shreyask21/neopixel_rp2040. Comme je le fais habituellement, j'ai téléchargé le dépôt sous forme de fichier zip plutôt que de cloner le dossier. Une fois que je l'ai téléchargé, je l'ai décompressé et j'ai copié les fichiers pertinents dans un dossier de travail. J'avais déjà installé le RPi Pico avec l'anneau NeoPixel et le pack de batteries en essayant de travailler sur la suite de l'article du mois dernier, donc je pensais être prêt. En utilisant Thonny, j'ai copié la bibliothèque de pilotes et l'exemple sur le Pico et je me suis lancé.

La première chose que j'ai faite a été de changer le pilote « In pin » dans l'appel de fonction d'instanciation.

led = neopixel_rp2040.neopixel(LEDS=2, PIN=16)

Pour rappel, l'affectation du PIN est la broche GP16 qui est la broche physique 21 du Pico.

Dans le fichier d'exemple, l'auteur utilise

led = neopixel_rp2040.neopixel(LEDS=2, PIN=22)

I purposely kept the number of LEDs set to 2, just to verify that the program worked. Halvard’s issue was that if he set the number of LEDs to 24, only the first 18 worked. To get the entire 24 to light, he had to set the LEDs to 32. Anyway, back to my story. When I tried to run the example, nothing happened. I was very confused. It turned out that my battery pack (which uses rechargeable batteries) had run low on power. After a brief 2 hours of replacing electrons into the batteries, I tried again. The example program worked with just the two LEDs without an issue (except for the brightness) and I then moved on to a test using just 12 LEDs. Again it worked. I then took a deep breath and tried all 24. Again, it worked. When I say that the brightness was an issue, I’m just saying that the darn things are TOO BRIGHT for my old eyes. It thought I was looking directly into a bright halogen bulb! So, I let Halvard know my progress and suggested that he check his battery pack.

J'ai volontairement maintenu le nombre de DEL à 2, juste pour vérifier que le programme fonctionnait. Le problème de Halvard était que s'il réglait le nombre de DEL à 24, seules les 18 premières fonctionnaient. Pour que les 24 s'allument, il devait régler les DEL à 32.

Bref, revenons à mon histoire. Lorsque j'ai essayé d'exécuter l'exemple, rien ne s'est produit. J'étais très confus. Il s'est avéré que mon bloc piles (qui utilise des piles rechargeables) était à court d'énergie. Après avoir passé deux heures à remplacer les électrons dans les piles, j'ai réessayé.

Le programme d'exemple a fonctionné sans problème avec les deux LED (sauf pour la luminosité) et j'ai ensuite fait un test avec 12 LED. Là encore, cela a fonctionné. J'ai ensuite pris une grande respiration et j'ai essayé les 24. Encore une fois, ça a marché.

Quand je dis que la luminosité était un problème, je dis simplement que ces fichues choses sont TROP LUMINEUSES pour mes vieux yeux. J'avais l'impression de regarder directement dans une ampoule halogène ! J'ai donc informé Halvard de mes progrès et lui ai suggéré de vérifier son bloc piles.

It turns out that Halvard had purchased a newer version of the PixelRing that is RGBW, not just RGB. While you would think (on one side of your brain), that the RGB drivers would work with RGBW NeoPixel sets. They do, but not quite properly. When trying to figure out why things were not quite right, I stumbled across this web site https://forums.electricimp.com/t/neopixel-strips-rgb-vs-rgbw/4212/8. It contains a long discussion that eventually explains everything. Peter, one of the posters, explained it in a very short but important comment. “The RGBW ‘Neopixels’ are a different controller, SK6812, but it looks like the actual protocol is very similar (except for having 32 bits per LED instead of 24). It sounds like it’d be worth starting from the WS2812 library and making some modifications.” So that explains why things went wonky when Halvard tried to use the driver for WS2812 NeoPixels when he actually had SK6812 NeoPixels. Thank you Peter for the explanation.

Il s'est avéré qu'Halvard avait acheté une version plus récente du PixelRing qui est RGBW, et pas seulement RGB. Alors que l'on pourrait penser (d'un côté de votre cerveau) que les pilotes RGB fonctionneraient avec les ensembles NeoPixel RGBW, ils le font, mais pas tout à fait correctement.

En essayant de comprendre pourquoi les choses n'étaient pas tout à fait correctes, je suis tombé sur ce site web https://forums.electricimp.com/t/neopixel-strips-rgb-vs-rgbw/4212/8. Il contient une longue discussion qui finit par tout expliquer. Peter, l'un des posteurs, l'a dit dans un commentaire très court mais important.

« Les 'Neopixels' RVBW sont un contrôleur différent, SK6812, mais il semble que le protocole actuel soit très similaire (sauf qu'il y a 32 bits par LED au lieu de 24). Il semble que cela vaille la peine de partir de la bibliothèque WS2812 et de faire quelques modifications. »

Cela explique donc pourquoi les choses se sont gâtées lorsque Halvard a essayé d'utiliser le pilote pour les NeoPixels WS2812 alors qu'il avait en fait des NeoPixels SK6812. Merci Peter pour cette explication.

So off I went again on a search for a driver that would, at least, support the SK6812 and hopefully for the WS2812 as well. I found it at https://github.com/blaz-r/pi_pico_neopixel. On his repository he states: “You create an object with the parameters number of LEDs, state machine ID, GPIO number and mode (RGB or RGBW) in that order. So, to create a strip of 10 leds on state machine 0 and GPIO 0 in RGBW mode you use: from neopixel import Neopixel pixels = Neopixel(10, 0, 0, “RGBW”) Mind that you can use whichever order of RGB / RGBW you want (GRB, WRGB, GRB, RGWB …). This only represents the order of data sent to led-strip, all functions still work with RGBW order. Exact order of leds should be on the package of your led-strip. (My BTF-lights sk6812 has GRBW).”

Je suis donc reparti à la recherche d'un pilote qui, au moins, prendrait en charge le SK6812 et, espérons-le, le WS2812. Je l'ai trouvé à https://github.com/blaz-r/pi_pico_neopixel.

Sur son dépôt, il déclare :

« Vous créez un objet avec comme paramètres le nombre de LEDs, l'ID de la machine d'état, le numéro GPIO et le mode (RGB ou RGBW) dans cet ordre. Donc, pour créer une bande de 10 LED sur la machine d'état 0 et le GPIO 0 en mode RGBW vous utilisez :

from neopixel import Neopixel

pixels = Neopixel(10, 0, 0, “RGBW”)

Notez que vous pouvez utiliser n'importe quel ordre de RGB/RGBW que vous voulez (GRB, WRGB, GRB, RGWB …). Cela ne représente que l'ordre des données envoyées à la bande de LED ; toutes les fonctions agissent toujours avec l'ordre RGBW. L'ordre exact des LED doit être indiqué sur l'emballage de votre bande de LED. (Ma BTF-lights sk6812 indique GRBW). »

So if you are using a RGBW strip or ring, you can simply use the initialization as shown above in the quote. pixels = Neopixel(10, 0, 0, “RGBW”) If, however, you are using an older RBG strip or ring, you can simply replace the mode designation “RGBW” with “RGB”. pixels = Neopixel(10, 0, 0, “RGB”) The parameters are easy. pixels = Neopixel(NumberOfPixels, StateMachine, Pin, Mode) As always, Pin refers to the IO pin, not the physical pin. The distribution comes with four example programs that show off the abilities of the driver and I have to admit, they work well, both for me and for Halvard – who tested them as well and they ran fine for him when he modified the initialization call.

Donc si vous utilisez une bande ou un anneau RGBW, vous pouvez simplement utiliser l'initialisation comme indiqué ci-dessus dans la citation.

pixels = Neopixel(10, 0, 0, “RGBW”)

Si, par contre, vous utilisez une bande ou un anneau RBG plus ancien, vous pouvez simplement remplacer la désignation du mode “RGBW” par “RGB”.

pixels = Neopixel(10, 0, 0, “RGB”)

Les paramètres sont simples.

pixels = Neopixel(NumberOfPixels, StateMachine, Pin, Mode)

Comme toujours, Pin fait référence à la broche IO, pas à la broche physique.

La distribution est livrée avec quatre programmes d'exemples qui montrent les capacités du pilote et je dois admettre qu'ils fonctionnent bien, à la fois pour moi et pour Halvard - qui les a également testés. Ils ont bien fonctionné pour lui quand il a modifié l'appel d'initialisation.

My favorite example is the firefly example program. It reminds me of summer evenings back when I was a child, chasing the fireflies in the back yard with a mason jar my mother let me use. Even today, when I see fireflies (which are actually in the beetle family and not flies at all), I am thrown back to those memories. So, with the pause for this month’s update, we'll press play on the compass program next month using the new driver for the NeoPixel display. Until next time, as always; stay safe, healthy, positive and creative!

Mon exemple préféré est le programme d'exemple des lucioles. Il me rappelle les soirées d'été de mon enfance, lorsque je chassais les lucioles dans le jardin avec un bocal que ma mère me laissait utiliser. Aujourd'hui encore, lorsque je vois des lucioles (qui sont en fait de la famille des coléoptères et pas du tout des mouches), ces souvenirs me reviennent en mémoire.

Ainsi, après la pause de ce mois pour la mise à jour, nous allons appuyer sur le programme de la boussole le mois prochain en utilisant le nouveau pilote pour l'affichage NeoPixel.

Jusqu'à la prochaine fois, comme toujours, restez en sécurité, en bonne santé, positifs et créatifs !

issue182/micro-ci_micro-la.txt · Dernière modification : 2022/06/30 16:10 de andre_domenech