Memory

The Arduino Uno has a minuscule amount of RAM (aka dynamic memory), only 2048 bytes. After compiling a sketch, the IDE will note how much is used vs. how much is left over for global variables (which, as I understand it, only gets used up once the program starts running).

If memory runs out during execution, things generally go haywire, with no warning messages or indication of what might be wrong. One symptom I’ve noticed is gibberish in the bottom right side of the OLED display, as shown in the image above.

The reason for this is that this display allocates 1024 bytes of RAM at runtime, and if the program runs out of memory, it will start to get written over. The fix is easy- just reduce the size of the program in every way you can. Use Ints instead of Floats. Comment out all unnecessary serial display messages. Another good trick is using Macro F.

In my example, I gradually reduced program size using the above methods until the gibberish went away.

The ESP32 has 260X more RAM than the Uno, so this becomes a non-issue in most cases.