For a project, the goal is to program a large number of WS2811 LED strips. Ultimately, this will require the use of about 10 Arduino Uno's. A pulse needs to be sent along the LED strip. When the pulse is need to start, it is done from a Raspberry Pi with Node-RED, which then sends a UDP message to the Arduino, and then a pulse is started. The communication works perfectly, but the LED strips are not working completely as expected yet. I still encounter the problem that with the code below, I can only control 2 LED strips. The compile is successful and can be uploaded to the Arduino, but only the first 2 defined LED strips work. If I define other LED strips first, then those work.
Now my question is, what is the best library to use for controlling multiple LED strips with an Arduino Uno? I have the impression that <Adafruit_NeoPixel.h>
does not meet my expectations, or is there something wrong with my code?
Additionally, I have tried using arrays, but while the compile was successful, the LED strips did not work. If you want i can share this code also but the code below is for me working for 2 ledstrips and not 8. Sorry that the comment in the code is in dutch but i think it is clear what te code does.
#include <Adafruit_NeoPixel.h>
#define PIN2 2 // De pin waarop de LED-strip is aangesloten
#define PIN3 3 // De pin waarop de LED-strip is aangesloten
#define PIN4 4 // De pin waarop de LED-strip is aangesloten
#define PIN5 5 // De pin waarop de LED-strip is aangesloten
#define PIN6 6 // De pin waarop de LED-strip is aangesloten
#define PIN7 7 // De pin waarop de LED-strip is aangesloten
#define PIN8 8 // De pin waarop de LED-strip is aangesloten
#define PIN9 9 // De pin waarop de LED-strip is aangesloten
#define NUM_LEDS 160 // Het totale aantal LEDs in je strip
uint8_t PixelStrip1 = 0; // Pixel op ledstrip 1
uint8_t PixelStrip2 = 0; // Pixel op ledstrip 2
uint8_t PixelStrip3 = 0; // Pixel op ledstrip 3
uint8_t PixelStrip4 = 0; // Pixel op ledstrip 4
uint8_t PixelStrip5 = 0; // Pixel op ledstrip 5
uint8_t PixelStrip6 = 0; // Pixel op ledstrip 6
uint8_t PixelStrip7 = 0; // Pixel op ledstrip 7
uint8_t PixelStrip8 = 0; // Pixel op ledstrip 8
uint8_t maxlengte = 160;
int L1 = 2; // afstand naar led
int L2 = 4; // afstand naar led
int Leind = 8; // afstand vanaf waar de leds uitgaan
int delaytime = 20; // tijd in milliseconden tussen led overstap
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LEDS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(NUM_LEDS, PIN4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(NUM_LEDS, PIN5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip5 = Adafruit_NeoPixel(NUM_LEDS, PIN6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip6 = Adafruit_NeoPixel(NUM_LEDS, PIN7, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip7 = Adafruit_NeoPixel(NUM_LEDS, PIN8, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip8 = Adafruit_NeoPixel(NUM_LEDS, PIN9, NEO_GRB + NEO_KHZ800);
uint32_t Color1 = strip1.Color(220, 80, 100); // kleur led 1
uint32_t Color2 = strip1.Color(225, 90, 110); // kleur led 2
uint32_t Color3 = strip1.Color(255, 255, 255); // kleur led 9
/* ------------- ETHERNET --------------------- */
#include <Ethernet.h>
#include <EthernetUdp.h>
int i = 0;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xEF, 0xED
};
IPAddress ip(192, 168, 0, 11);
unsigned int localPort = 8887; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[1]; // buffer to hold incoming packet,
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
//Serial.begin(9600);
// start UDP
Udp.begin(localPort);
strip1.begin();
strip1.show(); // Initialiseer alle pixels naar 'uit'
strip2.begin();
strip2.show(); // Initialiseer alle pixels naar 'uit'
strip3.begin();
strip3.show(); // Initialiseer alle pixels naar 'uit'
strip4.begin();
strip4.show(); // Initialiseer alle pixels naar 'uit'
strip5.begin();
strip5.show(); // Initialiseer alle pixels naar 'uit'
strip6.begin();
strip6.show(); // Initialiseer alle pixels naar 'uit'
strip7.begin();
strip7.show(); // Initialiseer alle pixels naar 'uit'
strip8.begin();
strip8.show(); // Initialiseer alle pixels naar 'uit'
}
void loop() {
int packetSize = Udp.parsePacket();
if (packetSize) {
Udp.read(packetBuffer, 1);
//Serial.println("packetBuffer: " + String(packetBuffer));
int strip = atoi(packetBuffer);
//Serial.println("Strip: " + String(strip));
switch (strip) {
case 1: PixelStrip1 = 1; break;
case 2: PixelStrip2 = 1; break;
case 3: PixelStrip3 = 1; break;
case 4: PixelStrip4 = 1; break;
case 5: PixelStrip5 = 1; break;
case 6: PixelStrip6 = 1; break;
case 7: PixelStrip7 = 1; break;
case 8: PixelStrip8 = 1; break;
}
}
if (PixelStrip1 > 0) {
PulsStrip1();
}
if (PixelStrip2 > 0) {
PulsStrip2();
}
if (PixelStrip3 > 0) {
PulsStrip3();
}
if (PixelStrip4 > 0) {
PulsStrip4();
}
if (PixelStrip5 > 0) {
PulsStrip5();
}
if (PixelStrip6 > 0) {
PulsStrip6();
}
if (PixelStrip7 > 0) {
PulsStrip7();
}
if (PixelStrip8 > 0) {
PulsStrip8();
}
delay(delaytime); // Wacht voor de volgende stap
}
void PulsStrip1() {
//Serial.println("PixelStrip1: " + String(PixelStrip1));
strip1.setPixelColor(PixelStrip1, Color1); // Zet de huidige pixel aan (wit)
strip1.setPixelColor(PixelStrip1 - L1, Color2); // Zet de huidige pixel aan (wit)
strip1.setPixelColor(PixelStrip1 - L2, Color3); // Zet de huidige pixel aan (wit)
strip1.setPixelColor(PixelStrip1 - Leind, 0); // Zet de pixel 6 stappen terug uit
strip1.show();
if (PixelStrip1 < NUM_LEDS) {
PixelStrip1++;
Serial.println("PixelStrip1: " + String(PixelStrip1));
} else {
PixelStrip1 = 0;
Serial.println("PixelStrip1: " + String(PixelStrip1));
}
}
void PulsStrip2() {
strip2.setPixelColor(PixelStrip2, Color1);
strip2.setPixelColor(PixelStrip2 - L1, Color2);
strip2.setPixelColor(PixelStrip2 - L2, Color3);
strip2.setPixelColor(PixelStrip2 - Leind, 0);
strip2.show();
if (PixelStrip2 < NUM_LEDS) {
PixelStrip2++;
//Serial.println("PixelStrip2: " + String(PixelStrip2));
} else {
PixelStrip2 = 0;
//Serial.println("PixelStrip2: " + String(PixelStrip2));
}
}
void PulsStrip3() {
strip3.setPixelColor(PixelStrip3, Color1);
strip3.setPixelColor(PixelStrip3 - L1, Color2);
strip3.setPixelColor(PixelStrip3 - L2, Color3);
strip3.setPixelColor(PixelStrip3 - Leind, 0);
strip3.show();
if (PixelStrip3 < NUM_LEDS) {
PixelStrip3++;
//Serial.println("PixelStrip3: " + String(PixelStrip3));
} else {
PixelStrip3 = 0;
//Serial.println("PixelStrip3: " + String(PixelStrip3));
}
}
void PulsStrip4() {
strip4.setPixelColor(PixelStrip4, Color1);
strip4.setPixelColor(PixelStrip4 - L1, Color2);
strip4.setPixelColor(PixelStrip4 - L2, Color3);
strip4.setPixelColor(PixelStrip4 - Leind, 0);
strip4.show();
if (PixelStrip4 < NUM_LEDS) {
PixelStrip4++;
//Serial.println("PixelStrip4: " + String(PixelStrip4));
} else {
PixelStrip4 = 0;
//Serial.println("PixelStrip4: " + String(PixelStrip4));
}
}
void PulsStrip5() {
strip5.setPixelColor(PixelStrip5, Color1);
strip5.setPixelColor(PixelStrip5 - L1, Color2);
strip5.setPixelColor(PixelStrip5 - L2, Color3);
strip5.setPixelColor(PixelStrip5 - Leind, 0);
strip5.show();
if (PixelStrip5 < NUM_LEDS) {
PixelStrip5++;
//Serial.println("PixelStrip5: " + String(PixelStrip5));
} else {
PixelStrip5 = 0;
//Serial.println("PixelStrip5: " + String(PixelStrip5));
}
}
void PulsStrip6() {
strip6.setPixelColor(PixelStrip6, Color1);
strip6.setPixelColor(PixelStrip6 - L1, Color2);
strip6.setPixelColor(PixelStrip6 - L2, Color3);
strip6.setPixelColor(PixelStrip6 - Leind, 0);
strip6.show();
if (PixelStrip6 < NUM_LEDS) {
PixelStrip6++;
//Serial.println("PixelStrip6: " + String(PixelStrip6));
} else {
PixelStrip6 = 0;
//Serial.println("PixelStrip6: " + String(PixelStrip6));
}
}
void PulsStrip7() {
strip7.setPixelColor(PixelStrip7, Color1);
strip7.setPixelColor(PixelStrip7 - L1, Color2);
strip7.setPixelColor(PixelStrip7 - L2, Color3);
strip7.setPixelColor(PixelStrip7 - Leind, 0);
strip7.show();
if (PixelStrip7 < NUM_LEDS) {
PixelStrip7++;
//Serial.println("PixelStrip7: " + String(PixelStrip7));
} else {
PixelStrip7 = 0;
//Serial.println("PixelStrip7: " + String(PixelStrip7));
}
}
void PulsStrip8() {
strip8.setPixelColor(PixelStrip8, Color1);
strip8.setPixelColor(PixelStrip8 - L1, Color2);
strip8.setPixelColor(PixelStrip8 - L2, Color3);
strip8.setPixelColor(PixelStrip8 - Leind, 0);
strip8.show();
if (PixelStrip8 < NUM_LEDS) {
PixelStrip8++;
//Serial.println("PixelStrip8: " + String(PixelStrip8));
} else {
PixelStrip8 = 0;
//Serial.println("PixelStrip8: " + String(PixelStrip8));
}
}