I have all the code for my project that should work but currently, the sketch uses 150% of my nano's dynamic memory and therefore cannot upload, I would appreciate any help and advice as to how to reduce it. I have attached the code.
Looking over the U8g2 library, if you can live with 8x8 fonts, text only, and no graphics, it can be run without a memory buffer. Have a look at the examples under U8g2 > u8x8. That, along with the F() micro for the print statements, gets the memory usage down to 91%, still too close for comfort.
Go through all your variables, and see if you can save some space there. I have not looked at the code closely, but things like minutes and seconds rarely need to be an integer, byte will usually suffice for something that will never go negative and never exceed 60. There are some other variables that you only use once, such as the global integer variable sensorValue, where you store the value read from the analog port, but then only use it once to calculate the voltage on the analog port, which you then store in a float variable, which again is only used once in a comparison for an if statement. (granted, you do this twice, once in setup and once in loop). If you are never going to use the variables anywhere else, putting the analogRead() directly in the if statement would give the same results and save six bytes of memory.
I have now got the sketch down to 111% by removing the SD library and related code. I have tried the F() macro trick to further reduce the dynamic memory use but would prefer some graphics and font freedom if possible as the project is reporting information to the screen to be read while rowing. I have attached the new code, please could someone help with the F () macro trick or other memory saving advice.
eh what is all this 'debug' Serial communication doing in there ?
what are you doing with variable 'm' here ?
{
uint32_t m = micros(); //Main timer initialization
u8g2.clearBuffer(); // clear the internal memory
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(0, 0, "Initializing..."); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
delay(3000);
secdelay.start(1000); //Start secondary timer delay (1 Second)
u8g2.clearBuffer(); // clear the internal memory
}
i suppose the compiler does nothing with it..
You haven't changed a lot of the 16-bit variables into 8-bit ones as was suggested.
And somehow i think you actually should be able to put the font(s) into progmem that could be your biggest saving.
Sadly that also chucked up a fair amount of bugs because I tried to change them all but it meant changing the screen definition and when I did that how the manual said, it wasn't recognised.
Oops yeah that's another testing thing that could probably come out I'll try that now
Deva_Rishi:
And somehow i think you actually should be able to put the font(s) into progmem that could be your biggest saving.
Looking over the library, the actual fonts are stored in PROGMEM, and there is a section in the library wiki about saving flash memory space by only specifying portions of a font (such as letters, numbers, etc).
You can save a good deal of memory by changing from a frame buffer to a page buffer, that takes your memory usage down to 67%, but you will need to modify the display commands a bit. I'm not familiar with the library or the display, there is a considerable amount of information on the wiki page.