Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By SteveSpencer
#28848 While experimenting with a NeoPixel strip, I discovered that the library appears not to work if you target 160MHz rather than the stock 80MHz. After a little digging, I discovered that providing I didn't call show in the setup function, it worked thereafter.

Digging around in the core code, rather than the library, I realised that code in setup runs at 80MHz, while code in loop runs at the faster speed.

Rather than modify the core to change this, I added the following into my setup function:
Code: Select all#if defined(ESP8266)
extern void preloop_update_frequency();
#endif
void setup()
{
#if defined(ESP8266)
     preloop_update_frequency();
#endif

// rest of code as usual.

}


This resolves the issue. What was happening was that the setup code was calling 'show' and stretching the pulses it sent by a factor of two, which I saw as turning the 0 bits into 1 bits.

A more appropriate fix might be to change core_esp8266_main.cpp from:

Code: Select allstatic void loop_wrapper() {
    static bool setup_done = false;
    if(!setup_done) {
        setup();
        setup_done = true;
    }
    preloop_update_frequency();
    loop();
    esp_schedule();
}


to

Code: Select allstatic void loop_wrapper() {
    static bool setup_done = false;
    preloop_update_frequency();
    if(!setup_done) {
        setup();
        setup_done = true;
    }
    loop();
    esp_schedule();
}


I confess, however, I do not know whether this might adversely affect other timer/frequency based stuff.
User avatar
By SteveSpencer
#30196 Hi JP

The function is part of the Arduino core for ESP8266.
When you compile a sketch (to keep the Arduino terminology), one of the things you can specify is the CPU speed, either 80MHz or 160MHz. Since a number of other things can cause the CPU clock to be dropped back to 80MHz (apparently), this function is used internally wrapping around your loop function to ensure that the CPU is running faster if that's what you wanted.

Hope that helps.

Steve