HOWTO: use NeoPixel library at 160MHz
Posted: Fri Sep 11, 2015 3:21 am
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:
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:
to
I confess, however, I do not know whether this might adversely affect other timer/frequency based stuff.
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 all
static void loop_wrapper() {
static bool setup_done = false;
if(!setup_done) {
setup();
setup_done = true;
}
preloop_update_frequency();
loop();
esp_schedule();
}
to
Code: Select all
static 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.