Programming Strategy vs Memory

probably   Original and basic arduino boards hav low memories that can quickly be saturated when the application objectives are too heavy.
1) Use miminmalists variables types.

2) List and evaluate in advance global variable size. Initialise them when you can

3) List and evaluate in advance dynamic variable and max size

4) Build Step by step and check memory consumption after uploading. 


Issues may occure before you seemed to reach the memory limits.

If there is a bug or if the microcontroller stops with no error message, this means there is a memory issue

 

 

  • Use the F() macro for constant string literals used serial output. For example, here "Test done. Results:" is stored in memory:

    Serial.println("Test done. Results:");
    Serial.println(results);
    

    Here it will be saved in sketch storage instead, freeing up memory:

    Serial.println(F("Test done. Results:"));
    Serial.println(results);
    • Avoid doing String operations if possible. If outputting lots of text to serial, use multiple calls to Serial.print() instead of using string concatenation.

      • Try to reduce the number of string literals in your code.

    • Optimize variables. Remove unused variables and be economical with the data types you use. Don’t use long (4 bytes) if only int (2 bytes) are needed. Don’t use float if only whole numbers will be assigned.

    • Declare variables as locally as possible to save memory:

      • Anything declared at global scope will exist for the entire lifetime of the sketch.
      • Variables that are only used inside one function, can be declared within that function.
      • If a variable needs to be shared between multiple functions, consider passing it as a parameter.
    • Avoid recursive code to reduce memory usage. Use iterative functions instead.

    • Minimize array sizes. Don’t declare larger arrays than needed.

    • Check your libraries to save storage. Avoid including large libraries unless you need to. Save storage by implementing your own code that only does what you need.

    • Store constant data in storage instead of memory with PROGMEM.

    Arduino sketches are written in the Arduino language, which is based on standard C++. Therefore, using general C++ optimization techniques will help.

    Additional options

    • Skip the bootloader. Free up space by uploading your sketch with a hardware programmer, without storing a bootloader on the board.
    • Increase storage space with an SD card.
    • Use a board with more storage and memory.

    Further reading

Case of a MIDI-based Controller Array of 96 Inputs


Source:
MIDI-Based Controller Array for All – Arduno

Hardware:
– Arduino Nano (others work also)
– 1 custom Array of 12×8 Paper-Force-Sensor from PapierLogik Kits
– 8 Resistors 10-50kOhms

 

 Inputs:
Array of 12 digital x 8 Analog plugged to reespectively 12 digital pins and 8 analog pins.
Each of the 8 analof pins is also connected to ground through one of the the 8 resistors.

 

Fairly simple

Application Example on Windows

TO DO

Application example on Android

TO DO WITH OTG