I have a large program I'm working on for a FIREBEETLE ESP32-E with a 2-dimensional array declared and initiated globally at the top of the code. when I accessed the array the code didn't function as expected, I printed the values to console and the contents was garbage.
So I created a simple sketch below with a single dimension array to try to see where I was going wrong....but the problem persisted in this simple sketch?!?!?
int times[] = {0,130,255,255};
void setup() {
Serial.begin(115200);
Serial.println("Array Test");
times[0] = 0; // I added to see if setting a value here made a difference
}
void loop() {
int one = times[0];
int two = times[1];
Serial.print("Direct access to 1st Value is: ");
Serial.println(times[0],DEC);
Serial.print("Direct access to 2nd Value is:");
Serial.println(times[1],DEC);
Serial.print("accessing int one: ");
Serial.println(one);
Serial.print("accessing int two ");
Serial.println(two);
delay(2000);
}
The code in the main loop prints this to console:
Direct access to 1st Value is: 620773686
Direct access to 2nd Value is:-1306523032
accessing int one: 620773686
accessing int two -1306523032
It doesn't seem to matter where I try setting array values, they always come back wrong.
If I declare the array as being length 4, that doesn't help.
if I declare the array as "const int" then the value are correct, but this doesn't help me as I need to change the values.
If I try running this same simple sketch on a Arduino 33 IOT then the code works fine resulting in the expected values printed to console:
Direct access to 1st Value is: 0
Direct access to 2nd Value is: 130
accessing int one: 0
accessing int two 130
Am I missing something(pretty sure that I am), or could this be a board library bug?
Hopefully someone can help point me in the right direction.