So I am in the process of a project that has 2047 stored inside of a const char* array. I am having some strange issues and I cannot seem to come up with a solution. I originally thought it was out of bounds errors but I am thinking it is not based on the testing that I did.
The problem is that as soon as I try to access it. For the sake of shortening the code and showing the error I shortened the list of words and minimized the code, but the actual list has 2048 words. As soon as I compile with the following I get out of memory errors. I am using an Arduino Mega. Does anyone have any ideas whats wrong? I tried with PROGMEM and non PROGMEM and still get the errors
Arduino: 1.8.10 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Sketch uses 18154 bytes (7%) of program storage space. Maximum is 253952 bytes.
Global variables use 11930 bytes (145%) of dynamic memory, leaving -3738 bytes for local variables. Maximum is 8192 bytes.
Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.
Error compiling for board Arduino Mega or Mega 2560.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
//With these lines in the program will not upload/compile because of memory errors.
int wordIndex = random(0,2047);
Serial.println(words[wordIndex ]);
[code]
//With these lines in the program runs fine and displays the word using the integer 54.
int wordIndex = random(0,2047);
Serial.println(words[54]);
PGM_P const words[2048] PROGMEM =
{ "PLACEBO", "ENTIRE", "UNDER", "MUSE", "D", "SUPPER", "LIGHT", "CARRIER",
"SHOULD", "HUMAN", "AWARD", "RECORDS", "PLUTO", "WORM", "PAUL", "EAT", "TREE", "MOMMY",
"COUNTRY", "STORY", "LAY", "BUSINESS", "SENT", "HIGHWAY", "APPLE", "RABBIT", "FOLIAGE", "WIDE"
};
void setup()
{
Serial.begin(115200);
}
void loop()
{
//This is the line the causes issues
int wordIndex = random(0,2047);
Serial.println((char*)words[wordIndex]);
}