I'm trying to use NeoPixel on the ESP8266. I made simple test put all required code into setup() and loop() methods. Then, to keep everything in order I create a class LedModule which handle the led strip state, changes, etc.

Here some parts of my class

LedModule::LedModule(unsigned int numOfPixels, uint8_t dataPin)
    // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
    // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
    // example for more information on possible values.
    pixels = Adafruit_NeoPixel(numOfPixels, dataPin, NEO_GRB + NEO_KHZ800);

    mIsLedStripOn = false;


// The method to set all leds of the strip to the same color
void LedModule::turnAllNeoPixelsTo(uint8_t red, uint8_t green, uint8_t blue)
    for (uint16_t i = 0; i < getLedCount(); i++)
        // Avoid to light up the middle leds
        if (i < 5 || i > 9)
            pixels.setPixelColor(i, red, green, blue);
            pixels.setPixelColor(i, 0,0,0); // off
    pixels.show(); // This sends the updated pixel color to the hardware.
    mIsLedStripOn = true;

After this changes, when I call the method above, I got the exception:

Exception 29: StoreProhibited: A store referenced a page mapped with an attribute that does not permit stores
Decoding 15 results
0x4020ddbd: ieee80211_send_mgmt at ?? line ?
0x4020db5f: ieee80211_send_mgmt at ?? line ?
0x40102864: trc_NeedRTS at ?? line ?
0x4020fe6d: ieee80211_sta_new_state at ?? line ?
0x402101ab: ieee80211_sta_new_state at ?? line ?
0x4021060f: sta_input at ?? line ?
0x402109cb: ieee80211_parse_wmeparams at ?? line ?
0x402103ab: sta_input at ?? line ?
0x40204ce3: pp_tx_idle_timeout at ?? line ?
0x40204607: ppPeocessRxPktHdr at ?? line ?

It seems to crash during the pixels.setPixelColor(i, red, green, blue); method.

  • What is pixels?
    – Majenko
    Jun 25 '17 at 11:09
  • instance of Adafruit_NeoPixel library object. I updated the class code above.
    – Noisemaker
    Jun 25 '17 at 11:14
  • I don't like your method of constructing. I think you need a new in there and make it a pointer
    – Majenko
    Jun 25 '17 at 11:15
  • I used the sample coming from the library. You can find it here: learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library
    – Noisemaker
    Jun 25 '17 at 11:37
  • That is completely different, sorry.
    – Majenko
    Jun 25 '17 at 11:39

Your "constructor" isn't doing what you think.

In the example you point to you have, efectively:

Class object = Class(parameters);

Whereas in your code you have:

Class object;

object = Class(parameters);

In the first form it results in a new object constructed at declaration time. In the second it first creates a new "empty" object and then at a later date tries to copy a newly constructed object into it - which may be failing if the class doesn't support copying.

Instead you should be working with new and pointers.

In your class definition you create a pointer to your Adafruit class:

    Adafruit_NeoPixel *pixels;

Then you create a new object pointing to it:

pixels = new Adafruit_NeoPixel(numOfPixels, dataPin, NEO_GRB + NEO_KHZ800);

Accessing it is then done with -> instead of .:

pixels->setPixelColor(i, red, green, blue);
  • Another option (to avoid new) would be to use the initializer list: LedModule::LedModule(unsigned int numOfPixels, uint8_t dataPin) : pixels(numOfPixels, dataPin, NEO_GRB + NEO_KHZ800) {...} Jun 25 '17 at 14:43
  • Yeah, I thought of suggesting that, but it can get a bit awkward with the Arduino API and the order things get initialized. I find it's best in general to do things in begin() rather than with constructors. Besides, there's no harm in using new in this situation.
    – Majenko
    Jun 25 '17 at 14:44
  • 1
    Another option would be to extend the NeoPixel class creating a child class that adds more functions to it.
    – Majenko
    Jun 25 '17 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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