Sketch
As usual, all the sources are available in my GitHub’s repository.
After having installed the library in your environment, include it in the sketch:
#include "FastSPI_LED.h" |
Define as constants the number of leds in your strip and the Arduino PIN you connected to the data PIN of the strip (sometimes labelled as DI):
#define NUM_LEDS 12 #define LED_PIN 4 |
Then, define a data struct that will contain the value of the 3 colors (RGB) of a single led. The struct is used to define the pointer *leds:
struct CRGB { unsigned char g; unsigned char r; unsigned char b; }; struct CRGB *leds; |
Within the setup() you have to initialize the library: set the PIN, the number of leds and the control chip (in my example WS2811):
FastSPI_LED.setLeds(NUM_LEDS); FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2811); FastSPI_LED.setPin(LED_PIN); FastSPI_LED.init(); FastSPI_LED.start(); |
In the setup(), get the array that contains the color of the different leds, initialize it (memset) with all zeroes and send its content to the strip:
leds = (struct CRGB*)FastSPI_LED.getRGBData(); memset(leds, 0, NUM_LEDS * 3); FastSPI_LED.show(); |
In the loop(), the sketch receives data packets on the serial port from the GUI running on the PC. Each packet contains the color of the leds and ends with the character 0x0A (new line):
When the sketch receives a byte, it updates the corresponding element in the leds array:
leds[leds_idx].r = input_byte; |
At the end, when the close character (0x0A) is received, the array is sent to the strip:
if(input_byte == 0x0A) { FastSPI_LED.show(); |
GUI
The GUI, developed in C#, let you configure the serial port you connected Arduino to and the number of leds in your strip.
You can then choose the color for each led using a color dialog; when you’re ready press the Send button to send the data packet to Arduino:
Demo
Photos about the connection between Arduino and the led strip:
Small video:
Thanks a lot for these concise and precise explanations. Thanks to share it with us, it works perfectly !
Hello,
Thank you for your article, it helped me a lot.
Is the 60Leds Restriction because of the Byte[] size package ?
Hi! Well no, I put that restriction because my led strip had 60 leds but of course you can increase it with a small change in the code!
Complimenti Luca ottimo tutorial.
Buondì Sig. Luca,
Complimenti per il Suo lavoro.
Avrei bisogno del Suo aiuto in merito ad un progetto per un segnapunti da pallavolo.
Mi occorre realizzare 4 digit a 7 segmenti con pezzi di strisce led per essere visibili da almeno 15m.
A tal proposito ho pensato di utilizzare dei led indirizzabili come quelli della Adafruit NeoPixel.
Visto che la suddetta casa commercia segmenti da 8 led ognuno, ogni digit avrà 7×8=56 Led.
In sintesi, riuscirei a creare un indirizzamento per così tanti led? C’è un limite? Grazie e Scusi la domanda ma sono un neofita di Arduino.
Saluti, Umberto.
Salve Umberto, l’unica accortezza è sull’alimentatore usato per accendere tanti led: deve essere adeguato come corrente di uscita. Per risparmiare potrebbe anche utilizzare delle strisce non indirizzabili, pilotando ogni segmento con un apposito MOSFET.
P.S. – Per farmi comprendere meglio, mi sono ispirato a questo articolo.
http://rubyist.github.io/blog/2014/01/20/led-strips-as-7-segment-display/
Grazie ancora.
Ciao Luca,
grazie per il tutoria.
Una info: volendo controllare la scriscia direttamente con l’alimentazione di Arduino e non con fonte esterna, quanti led posso indirizzare al massimo se utilizzo per es. la striscia di Adafruit? Ci possono essere cali di intensità luminosa al crescere del numero di led con questa soluzione di alimentazione?
Ciao Marcello, purtroppo il chip di alimentazione di Arduino è in grado di fornire qualche centinaio di mA. Adafruit consiglia di stimare 60mA per ogni led, quindi non superarne una decina, altrimenti rischi di danneggiare il tuo Arduino.
Salve, buonasera; piacere sono Luigi volevo dirti che girando su internet mi sono imbattuto negli spettacoli di luci natalizi musicali che fanno in America cercando di capire i vari software e hardware che utilizzano, alla fine mi sono ritrovato difronte ad “arduino” e schede relè “solid state relay” 8 canali e ti allego la foto di quello che ho comprato. Ho acquistato tutto il necessario, utilizzando il software “vixen” ; facendo molte prove ho riscontrato un problema molto strano: colleganado le schede e le luci al relè 220v riesco a farle giocare, invece collegando le luci rgb a 12v le luci si presentano immobili e solo di un colore. Se è possibile un tuo aiuto vorrei capire il problema e se per lei non è un fastidio mandarmi i collegamenti delle schede ad arduino. Le dico anche credendo che arduino 1 non ce la faceva a far giocare le luci ho acquistato anche “arduino mega”.
Aspetto una risposta al più presto,la ringrazio in anticipo.
Buona serata.
Luigi è difficile capire cosa non vada, sicuramente una led strip rgb non può essere comandata con i relays. A seconda della led strip che ha acquistato (“smart”, quindi con controllo intergrato oppure da comandare in PWM da Arduino) servirà collegarla correttamente ad Arduino. Non conosco Vixen quindi le consiglio magari di rivolgersi a forum dedicati a questo software dove sicuramente la sapranno aiutare meglio.
Thanks for your sharing
I have some 12v individual pixel led strips,
could it be the same?
http://addressable-led.com/Products/gs8208-12v-individual-pixel-led-strip.html
Hi Phil, no your led strip uses a different controller (GS8208)
This arduino code does not work with new fastled library andThe FastSPI_led is hard to find nowdays. Do you have a copy of this library? Or you know diffrent lib that will make it work without changeing the code for Arduino?
Hi, unfortunately not, the article was posted 5 years ago…
salve. desideravo delle strisce led colorate per il monopattino, o a batterie ricaricabili o da collegare dentro il vano batterie cosi da collegare alle batterie del monopattino. grazie e distinti saluti
buongiorno Francesco, ormai di strisce led ne trovi tantissime: guarda ad esempio queste, controllabili via bluetooth
Hi Very nice project even if it is several years old. I built this and managed to get it working. Was wondering if you have ever done this same project but with a arduino uno wifi board (esp8266) ?
Hi, I think a very interesting project for that is WLED…