0

I have a pretty simple sketch that crashes, and crashes hard (Platform.io console says "Disconnected (read failed: [Errno 6] Device not configured)" and I need to power off/on the Arduino to continue.

The sketch does not crash and seems to work fine when I use a smaller number of LEDS but crashes after a few seconds when I use a longer number of LEDS. Seems like a strange hardware issue because the sketch looks simple! I have added a lot of Serial.print(ln)'s to verify it is doing what I think it is, and it does... until the crash!

This will run forever, but if I change cNumLeds from 60 to 160 it crashes (and my actual LED strip has 300 LEDs and I use all of them in other sketches).

#include <Arduino.h>
#include <FastLED.h>

const uint16_t cDataPin = 15;
const uint16_t cNumLeds = 60;

CRGB leds[cNumLeds];

void setup() {
   Serial.begin(9600);
   FastLED.addLeds<WS2812B, cDataPin, GRB>(leds, cNumLeds).setCorrection(TypicalLEDStrip).setDither(true);
   FastLED.setBrightness(127);
   FastLED.clear();
   FastLED.show();
   FastLED.delay(100);
}

uint16_t offset = 0;
CRGB colors[] = {CRGB::White, CRGB::Red, CRGB::White, CRGB::Green, CRGB::White, CRGB::Black};
byte numColors = sizeof(colors)/sizeof(colors[0]);
uint32_t cycle = 75;

void loop() {
  EVERY_N_MILLISECONDS(cycle) {
    for (uint16_t i = 0; i < cNumLeds; i++) {
        leds[i] = colors[(i + offset) % numColors];
    }     
    offset = (1 + offset) % cNumLeds;  
  }
  FastLED.show();
}

Any tips for debugging greatly appreciated ! (And apologies in advance for my C++ style, I am a confirmed C programmer trying not to do any damage in C++)

3
  • How are you powering the LED strip? Sounds like either your power supply is not strong enough or you are providing power through the Arduino
    – chrisl
    Commented Nov 23, 2022 at 22:21
  • Yes @chrisl, guilty as charged, powering from the 5V Arduino pin. I guess that's what the extra red and black wire on the strip are for : ) TIme to learn soldering, I guess.
    – PaulM
    Commented Nov 23, 2022 at 22:27
  • But i have run other sketches, much more complex, on the whole of the 300 led strip, so not sure I get why this sketch is having a power issue.
    – PaulM
    Commented Nov 23, 2022 at 22:29

1 Answer 1

1

powering from the 5V Arduino pin.

You should not do this. You can fry the voltage regulator or the protection diode doing this (depending on how you supply the power).

When you draw more current from a power source than it can supply, first the voltage will drop. If the voltage drops enough the Arduino will brown out and reset as soon as the voltage is up again. If you keep drawing that much power, you can fry parts of the power source (in this case your Arduino). Sometimes this is reversible, when the power source has some kind of emergency shutdown (like the voltage regulator of a genuine Arduino Uno). Otherwise it will get destroyed.

When controlling power hungry devices like LED strips you should connect their power lines directly to your power supply (given it has the correct voltage). That way the current doesn't have to flow through the Arduino. Also you need a power supply, that can handle your peak current. The RGB strips with WS2812 drivers can draw up to 60mA per LED (on white in full brightness). So for a strip with 160 of them it would be a current of 60mA * 160 = 9.6A. Add a little headroom and you would need a power supply, that can at least provide 10A of current.

But i have run other sketches, much more complex, on the whole of the 300 led strip, so not sure I get why this sketch is having a power issue.

We haven't seen your previous sketches. But most likely you had a lower current, because you didn't light up all LEDs at once and/or only at lower brightness. The drawn current depends on how bright you set each LED (to be specific each color of each LED, since one RGB LED is actually 3 LEDs with the colors red, green and blue in one casing). So your current was low enough to not brown out the power from the Arduino.

2
  • Appreciate it @chrisl.... not that I had any reason to doubt you but I re-ran my sketch at a ridiculously low brightness and it ran forever.
    – PaulM
    Commented Nov 23, 2022 at 23:35
  • @PaulM Your observation confirms the answer. Commented Nov 24, 2022 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.