Arduino crashes when I try to "use" a variable

Hi. I'm working with 977 lines of code and a number of libraries (uploading to a Mega2560), however my problem is rather simple.

I have char arrays all over my code and am experiencing no problem with them.

However my latest code revision I've defined the following:

char zonevect[120] = {' ','\0'};

(line 141)

It compiles okay, but crashes the Arduino when I do anything with it, e.g.

Serial.println(zonevect);

(line 879)

or

zonevect[0] = 'Z';

When I say "crashes the Arduino", the compile and upload succeeds, but the sketch doesn't start, and the Arduino pin13 LED remains on.

If I comment-out the line where I try to e.g. print the variable to serial, the sketch runs just fine.

** just tried to post my full sketch, however I hit the forum post character limit! **

Any answers, or would it be more helpful if I upload the sketch to another place for you to see?

Thanks!

Can't tell from snippets.

Attach your code.

(deleted)

Here’s the code.

please be gentle I’m using this project to learn as I go, so I would very much appreciate any other constructive criticism!

mega-control.zip (9.21 KB)

I should add: I'm "using" the other similar character array defined in line 142 (zonesmsg[120]) and this is causing me no problems. Which is why I'm so confused! It's been driving me nuts.

char zonename[120] = {' ','\0'};        // Zone name (to be received from OpenHAB)
char zonevect[120] = {' ','\0'};        // Zone vector (to be received from OpenHAB)
char zonesmsg[120] = {' ','\0'};        // Zone startup message (to be received from OpenHAB)
char zonepmsg[120] = {' ','\0'};        // Zone pager message (to be received from OpenHAB)

// settings
int circuitCount = 2;
char lightSceneNames [5][30] = {"--", "--", "--", "--", "--"};
char audioFaveNames [5][30] = {"--", "--", "--", "--", "--"};



// OPTIMISE THIS
char buff[120];

120+120+120+120+150+150+120=900 bytes of RAM, plus a ton of strings using up RAM

if (foundtitle == 1) u8g.drawStr(0, 10, "title: Y");
    else u8g.drawStr(0, 10, "title: N");
    if (foundartist == 1) u8g.drawStr(0, 20, "artist: Y");
    else u8g.drawStr(0, 20, "artist: N");
    if (founddate == 1) u8g.drawStr(0, 30, "date: Y");
    else u8g.drawStr(0, 30, "date: N");
    if (foundvol == 1) u8g.drawStr(0, 40, "vol: Y");
    else u8g.drawStr(0, 40, "vol: N");
    if (foundplaystatus == 1) u8g.drawStr(0, 50, "plstts: Y");
    else u8g.drawStr(0, 50, "plstts: N");
    if (foundcurrenttemp == 1) u8g.drawStr(0, 60, "c-temp: Y");
    else u8g.drawStr(0, 60, "c-temp: N");
    if (foundcircuitcount == 1) u8g.drawStr(58, 10, "c-cnt: Y");
    else u8g.drawStr(58, 10, "c-cnt: N");
    if (foundcircuit1name == 1) u8g.drawStr(58, 20, "c1-name: Y");
    else u8g.drawStr(58, 20, "c1-name: N");
    if (foundcircuit2name == 1) u8g.drawStr(58, 30, "c2-name: Y");
    else u8g.drawStr(58, 30, "c2-name: N");
    if (foundcircuit3name == 1) u8g.drawStr(58, 40, "c3-name: Y");
    else u8g.drawStr(58, 40, "c3-name: N");
    if (foundcircuit4name == 1) u8g.drawStr(58, 50, "c4-name: Y");
    else u8g.drawStr(58, 50, "c4-name: N");
    if (foundcircuit5name == 1) u8g.drawStr(58, 60, "c5-name: Y");
    else u8g.drawStr(58, 60, "c5-name: N");
    if (foundcircuit6name == 1) u8g.drawStr(125, 10, "c6-name: Y");
    else u8g.drawStr(125, 10, "c6-name: N");

Learn to love the F() macro, which can store all of those fixed strings outside of RAM.

Oh gawd. Just looked briefly at memory types in the Arduino. I was blythely coding with no regard for SRAM, assuming I only needed to keep below the program storage space level of 256k for the Mega.

I told you I was using this project to learn!

Thanks for the clues. Also thanks MorganS for pointing me towards F() macro.