APA102 LEDs light up incorrectly


I use an ESP32 and APA102 with 40 LEDs. The ESP32 is connected to the LEDs via Data, Clock and Ground. An external power supply powers the LEDs (40W 5V 8A). If I set the LEDs to blue (RGB 0-0-255), then some of the first 20 LEDs will glow blue correctly, others will be off and others will not light up. The next 20 LEDs will all turn blue. Same behavior happens with another LED Stripe. Set the LEDs to green (RGB 0-255-0) or red (RGB 255-0-0) everything is ok. I try to set the LEDs to "black", in order to turn them off (RGB 0-0-0) a part goes out and others switch over to any color. If I use the Sample Script (Rainbow), all LEDs work correctly and play the required color. Use the APA102.h library for the control. If I put a few LEDs on white with blue all works fine.

What could be the problem?

Thanks and greetings

What could be the problem?

Your code. Since you didn't bother posting it, we can only assume that you are happy with the way it works now.

It’s a workaround, with the putting of white LEDs.

Sorry and here is the original code where the problem with the blue LEDs occurs. It is an electrical problem or is it from programming?

#include <WiFi.h>
#include <APA102.h>
const uint8_t dataPin = 21;
const uint8_t clockPin = 18;
APA102<dataPin, clockPin> ledStrip;
const uint16_t led_anzahl = 40;
rgb_color colors[led_anzahl];
const char* ssid = "ssid";
const char* password = "password";
WiFiServer server(80);

void setup()
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)

void loop()
  WiFiClient client = server.available();
  if (client)
    while (client.connected())
      if (client.available())
        if (client.findUntil("?rgb=", "\n"))
          String befehl = client.readStringUntil(' ');
          char befehl_hilf[15];
          befehl.toCharArray(befehl_hilf, 50);
          char* token = strtok(befehl_hilf, "-");
          char* r = token;
          token = strtok(0, "-");
          char* g = token;
          token = strtok(0, "-");
          char* b = token;
          token = strtok(0, "-");
          char* helligkeit = token;
          uint8_t time = millis() >> 4;
          for (uint16_t i = 0; i < led_anzahl; i++)
            uint8_t x = time - i * 8;
            colors[i] = rgb_color(atoi(r), atoi(g), atoi(b));
          ledStrip.write(colors, led_anzahl, atoi(helligkeit));

OK, first things first. Your :astonished: code is very hard to follow.

You need to go and read the forum instructions so that you can go back and modify your post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code” it has as you now see, been garbled and is always more difficult to read.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only between complete functional blocks.

APA102 with 40 LEDs

I've never used those so I can't help you with the software, but it's most-likely a software problem.

The data out of each chip/LED is buffered ("re-conditioned") so the processor only "talks to" the 1st chip, and the 1st one talks to the 2nd one, and so-on. That means the data doesn't degrade as you go farther down the strip. You can get power loss at the far-end, but 40 LEDs isn't that much.

Yesterday I continued working with the LEDs. If I first set the LEDs to white and then set the desired color, it works with the color blue. But you have to set the desired color, still a few LEDs on white (currently there are 4 LEDs).