NeoPixel-UserGuide-Programmation-Avancée

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Question - Réponse

Mo code servo sur Arduino arrête de fonctionner lorsqu'il est combiné avec NeoPixels!

Malheureusement, les bibliothèques NéoPixel et servo ne fonctionne pas très bien ensemble; La première ayant besoin de désactiver les interruptions de façon périodique et la deuxième en a absolument besoin pour fonctionner. Vous avez néanmoins quelques alternative:

  • Utiliser un shield controleur servo ou un breakout controleur PWM/Servo, déchargeant le processeur de la tâche et libérant ainsi les interruptions.
  • Utiliser une bibliothèque servo hardware-PWM-based (signal PWM contrôlé matériellement) plutôt que la librairie Servo Arduino (d'origine). Cela peut offrir un contrôle du temps vraiment très stable sans utiliser d'interruption, mais peut seulement contrôler but un nombre très limité de servo (2-3) et uniquement sur des broches très spécifiques. PWMServo semble pouvoir gérer cela... téléchargez la "bibliothèque de Paul (v2)” depuis cette page.

A quelle vitesse puis-je rafraichir une chaine de (N) pixels?

Les NéoPixels reçoivent le flux de donnée à la fréquence fixée de 800 KHz (excepté pour les pixels Flora “V1” qui utilisait un fréquence de 400 KHz). Un bit à donc besoin de de 1/800.000 de sec — soit 1.25 microsecondes pour être transmit. Un pixel à besoin de 24 bits pour fixer sa couleur (8 bits pour chaque couleur de base rouge, vert, bleu) — soit 30 microsecondes. Après l'envoi des données du dernier pixels, le flux de donnée doit être arrêté pendant au mois 50 microsecondes avant de relancer un nouveau flux de donnée (et recommencer le cycle d'initialisation des couleurs du premier au dernier pixel)

Pour un ruban de 100 pixels, cela représente (100 * 30) + 50, soit 3.050 microsecondes par cycle. Comme il y a 1.000.000 micro-secondes dans une seconde, cela donne 1.000.000 / 3.050 = approximativement 328 mise-à-jour par seconde.

Cependant

C'est seulement le temps nécessaire pour l'envoi des données sur le fil. Le taux de rafraichissement réel sera quand même inférieur et ne peux pas être facilement évaluer en un valeur finie couvrant tous les cas. Le traitement de chaque image d'une animation prends du temps. Le temps nécessaire dépends de la complexité, des opérations mathématiques et de l'efficacité du code (par exemple, les opérations en virgule flottante sont relativement lente). La technique ci dessus donne un taux maximum théorique mais c'est juste un point de départ.

Si vous désirez faire des explorations et des relevés (du benchmarking), vous pouvez toujours écrire du code pour un plus grand nombre de pixels même s'il ne sont pas présent. Cela permet de relever le temps de traitement. Les bits de données en extra (pour les pixels non présents) sont simplement ignorés par le ruban/chaine (ou vous pouvez même tester sans aucun NéoPixel connectés).

That won’t do. Now what?

Because NeoPixels use a fixed-frequency clock, options are limited. You can’t switch out for a faster microcontroller and expect substantially different results.

One option is to use a different LED type, such as our LPD8806 strips or WS2801 pixels. These can be driven at higher data rates, though they do have some other tradeoffs with respect to NeoPixels (cost, color resolution and/or pixel density).

Another is to develop your own code for a more capable microcontroller or an FPGA that drives multiple NeoPixel strips in parallel. One such project — OctoWS2811 for the Teensy 3.0 microcontroller — is shown later. This sort of thing is a complex undertaking and not recommended for beginners. And even among more experienced programmers, there’s often an unreasonable over-emphasis on data rates when the real bottlenecks lie elsewhere…don’t dwell on this too much unless you can confirm it’s a problem.

Can I control NeoPixels using (Board X)?

We currently only offer an Arduino library. See the links later for other devices. For anything beyond this, if considering writing your own library, understand that some devices are better suited to the task than others. Read through the timing requirements shown below and determine if the processor or device in question can synthesize a signal meeting those specifications. An 8 MHz AVR can just barely keep up…anything slower may have trouble, though some hardware-specific hacks (like clever use of SPI) might make it possible. In many cases, assembly language is required.

Why not Raspberry Pi?

The Raspberry Pi running Linux is a multitasking system, and control may switch among multiple running programs at any time. As such, it’s impossible to guarantee the strict 800 KHz signal required by NeoPixels. You may be able to fudge it for short intervals, but it’s not something that can be counted upon. This is why we use LPD8806 pixels for the Raspberry Pi light painting demonstration.

Third-Party Libraries

NeoPixel-compatible libraries have been developed for devices beyond Arduino. Please keep in mind that Adafruit did not develop any of this code, does not know it inside and out, and can’t fix bugs or offer technical help. This is Wild West stuff.

  • OctoWS2811: specifically for the PJRC Teensy 3.0 microcontroller board. Uses DMA to drive up to 8 NeoPixel strips concurrently with minimal processor load. Multiple boards can be cascaded for still larger displays.
  • FadeCandy: also for Teensy 3.0. Doesn’t support as many pixels as OctoWS2811, but adds smooth interpolation and other features for the color-persnickety.
  • LEDscape: specifically for BeagleBone Black. Although the BeagleBone is a multitasking Linux system like the not-NeoPixel-compatible Raspberry Pi, this code exploits hardware features specific to the BeagleBone Black to drive hundreds of meters of NeoPixel strip with virtually no processor load.
  • WS2812 LED Driver for Parallax Propeller.
  • xCORE NeoPixel test code for the XMOS xCORE startKIT.

WS2811? WS2812? Why do I see two different names mentioned?

The WS2811 is an earlier driver chip separate from the RGB LED. The data signal is similar, but runs at half the speed. By the time the WS2812 (with integrated LED) was released, a lot of code and projects had already built up around the WS2811 name. Sometimes code “for the WS2811” might actually be for the newer chip, or for either type. The Adafruit_NeoPixel library supports both.

Writing Your Own Library

The WS2812 datasheet explains the data transmission protocol. This is a self-clocking signal — there’s only one wire, not separate data and clock lines. “1” and “0” bits are indicated by varying the duty cycle of a fixed-frequency square wave.

Fichier:NeoPixel-UserGuide-YourLib-01.jpg

There’s a math goof in the datasheet’s timing values. Use these figures instead:

Fichier:NeoPixel-UserGuide-YourLib-02.jpg

Note that there’s nearly 25% “wiggle room” in the timing. So if your code can’t match the recommended times exactly, it’s usually okay.

There are three bytes of data for each pixel. These should be issued in green, red, blue order, with the most-significant bit first.

Fichier:NeoPixel-UserGuide-YourLib-03.jpg

The data for pixel #0 (nearest the microcontroller) is issued first, then pixel #1, and so forth to the furthest pixel. This does not operate like a traditional shift register!

After all the color data is sent, the data line must be held low for a minimum of 50 microseconds for the new colors to “latch.”

You may want to dig through our Arduino library for insights. The timing-critial parts are written in AVR assembly language, but it’s extensively commented with C-like pseudocode.

My Microcontroller Isn’t Fast Enough to Do That

The WS2812 appears to be backwardly-compatible with the 400 KHz WS2811 signal. If you can precisely match the latter chip’s timing, either type will respond. The WS2811 protocol is not simply a half-speed WS2812. The duty cycle for the “0” and “1” bits is slightly different. From the WS2811 datasheet:

Fichier:NeoPixel-UserGuide-YourLib-10.jpg


Source: NeoPixel UserGuide créé par Phillip Burgess pour AdaFruit Industries. Crédit AdaFruit Industries

Traduit par Meurisse D. pour MCHobby.be

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.