I have a piece of code like so:
const int PINS[] PROGMEM = {
D1, //GPIO5
D2, //GPIO4
D3, //GPIO0
D5, //GPIO14
D6, //GPIO12
D7 //GPIO13
};
Serial.begin(115200);
for(int i=0; i<MAX_INPUTS; i++){
Serial.print(PINS[i]);
pinMode(PINS[i], INPUT_PULLUP);
}
This runs ok, but I don’t need Serial.print() for troubleshooting anymore…so I remove it.
Now I’m getting stack errors and endless reboot cycles:
Decoding stack results
0x40209e54: loop_wrapper() at C:\Users\Dazed\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 180
I think Serial.print() is perhaps casting the variable in some way that causes pinMode to accept it.
inserting a delay(10) or delay(200) instead does not fix the crash. Commenting out the pinmode line fixes the crash.
I have also tried the following (which worked):
const int PINS[] PROGMEM = {
D1, //GPIO5
D2, //GPIO4
D3, //GPIO0
D5, //GPIO14
D6, //GPIO12
D7 //GPIO13
};
Serial.begin(115200);
for(int i=0; i<MAX_INPUTS; i++){
//Serial.print(PINS[i]);
//pinMode(PINS[i], INPUT_PULLUP);
}
int i = 0;
pinMode(PINS[i], INPUT_PULLUP);
pinMode(PINS[1], INPUT_PULLUP);
pinMode(PINS[2], INPUT_PULLUP);
It may seem strange to reference pins through an array object, but this makes it very easy to:
A) configure which pins or how many to read via web interface
B) indicate whether they are meant to be normally closed or normally open
C) iterate through them and apply de-bounce filtering before triggering a response
I’d like to understand what Serial.print() might be doing that causes looped pinmode to say “Yup, looks good” or how that’s different from the later code. I’m guessing this relates to pointer handling or maybe type casting somewhere along the way…but I don’t actually understand what’s really happening.