I have a large lookup array that makes my program too big for the memory on an arduino uno.
The array is static so it seems that the solution is to story that in flash using PROGMEM.
I’ve tried following some guides to doing that but when I try to verify the sketch I get an error:-
Sketch uses 15078 bytes (46%) of program storage space. Maximum is 32256 bytes.
Global variables use 2053 bytes (100%) of dynamic memory, leaving -5 bytes for local variables. Maximum is 2048 bytes.
I’ve extracted the lookup table and some code to serial print the entries into a smaller sketch and that successfully runs but I don’t think it is putting the array into flash, just normal RAM.
the test code is:-
// Creating new struct for lookup table array
// Needed as contains 2 different data types so a normal
// 2d array can't be used
struct pyClass {
long pyNumber;
String pyName;
};
// Lookup table of pyClasses
// Created from 2019 RYA PY Numbers
// Created as Const to save memory
// Max 14 Characters per pyName (otherwise won't fit on display)
const pyClass pyClasses[] PROGMEM = {
// const pyClass pyClasses[] = {
{1111, "420"},
{1112, "2000"},
{907, "29ER"},
{903, "505"},
{1038, "ALBACORE/KSTRL"},
{1027, "BLAZE"},
{1155, "BRITISH MOTH"},
{1138, "BYTE C11"},
{1207, "COMET"},
{1097, "COMET TRIO MK1"},
{969, "CONTENDER"},
{948, "DEVOTI D-ONE"},
{1029, "DEVOTI D-ZERO"},
{1119, "ENTERPRISE"},
{1141, "EUROPE"},
{1051, "FINN"},
{952, "FIREBALL"},
{1172, "FIREFLY"},
{1130, "GP1HADRON H2"},
{1073, "LARK/MEGABYTE"},
{1099, "LASER"},
{1207, "LASER 4.7"},
{1145, "LASER RADIAL"},
{1167, "LIGHTNING 368"},
{980, "MERLIN-ROCKET"},
{1194, "MIRACLE"},
{1390, "MIRROR (D/H)"},
{1380, "MIRROR (S/H)"},
{849, "MUSTO SKIFF"},
{1064, "NATIONAL 12"},
{1104, "OK"},
{1642, "OPTIMIST"},
{928, "OSPREY"},
{1002, "PHANTOM"},
{1051, "ROOSTER 8.1"},
{1004, "RS 100 8.4"},
{981, "RS 100 10.2"},
{1046, "RS 200"},
{970, "RS 300"},
{942, "RS 400"},
{963, "RS 500"},
{916, "RS 600"},
{845, "RS 700"},
{799, "RS 800"},
{1136, "RS AERO 5"},
{1065, "RS AERO 7"},
{1014, "RS AERO 9"},
{1240, "RS FEVA XL"},
{1359, "RS TERA PRO"},
{1438, "RS TERA SPORT"},
{1093, "RS VAREO"},
{1137, "RS VISION"},
{1036, "SCORPION"},
{1074, "SEAFLY"},
{1099, "SNIPE"},
{1143, "SOLO"},
{1089, "SOLUTION"},
{1128, "STREAKER"},
{1077, "SUPERNOVA"},
{1020, "TASAR"},
{1363, "TOPPER"},
{1190, "WANDERER"},
{1102, "WAYFARER"}
};
void setup()
{
Serial.begin(9600);
}
// Main Loop
void loop() {
// Checks every entry in the array until a match to the
// PYNumber is found, updates the ClassName variable
// then exits the function.
// If no match is found then ClassName of "UNKNOWN CLASS"
for (int i = 0; i < sizeof(pyClasses)/sizeof(pyClasses[0]); i++) {
Serial.println(pyClasses[i].pyName);
Serial.println(pyClasses[i].pyNumber);
}
}
Any ideas appreciated :0)