0

I am working on a project where I am required to work with a WS2812B LED strip that has 360 LEDs. I am using Adafruit_NeoPixel.h library to drive the LED strip. I have a class called lights which are responsible for driving the LEDs.

Here is a snippet of my code:

//---- in Lights.h
private:

   Adafruit_NeoPixel m_LedStrip;
//----------------------------------------

//--- in Lights.cpp

Lights::Lights()
{
   m_LedStrip = Adafruit_NeoPixel(360, m_LedPin, NEO_GRB + NEO_KHZ800);

   #if defined (__AVR_ATtiny85__)
      if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
   #endif

   m_LedStrip.begin();

   Serial.print("m_LedStrip.numPixels() is ");
   Serial.println(m_LedStrip.numPixels());
}

//----------------------------------------

I am working on Arduino Nano w/ATmega328 by the way.

Now, m_LedStrips.numPixels() shows that it have 0 pixels. Strangely it works when I put the number of pixels to something smaller. 360 also works on my prototype code that only has lights control. I suspect that this might be a memory issue but my Arduino memory is not even full. Here are the memory usage stats.

Program size: 9,186 bytes (used 30% of a 30,720 byte maximum) (1.64 secs)
Minimum Memory Usage: 928 bytes (45% of a 2048 byte maximum)

Can someone give some advice as to how I can fix this issue?

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Saik
  • 993
  • 1
  • 16
  • 40

1 Answers1

0

360 LEDs with 3 bytes per pixel takes 1080 bytes of memory.

The Adafruit_NeoPixel library dynamically allocates memory, that's why you don't see that memory usage during compile time.

Together with your 928 bytes at compile time, it uses 2008 bytes of memory. At 2048 bytes being the maximum, that is 98% of your memory used. And you would still need memory for the stack.

You will either need to reduce the memory usage of your other code or get a MCU with more memory.

gre_gor
  • 6,669
  • 9
  • 47
  • 52