Can you spare a 200 bytes? When enabling Serial is enough to crash an Arduino app
I have an old piece of Arduino code that doesn't work if I enable Serial Output. The code consists of 3 main pieces:
- Ethernet/Web server
- Neopixel driver
- 5110 LCD display
The code runs fine if I disable Serial output or if I remove the 5100 LCD display code and libraries. Note that the Arduino doesn't actually boot correctly and initialize the displays so this is even before any web server requests. I couldn't figure out what was happening until I looked at the compiler output. It turns out that Serial() reserves about 200 bytes for input/output buffers. This makes sense but pushed me over the edge. I don't have a good way to figure out the minimum I need but obviously, 234 bytes isn't enough.
Code Used
Compiler Messages
This is the Arduino compiler output with just the following line in the code or commented out. These numbers were captured after moving all constant strings to PROGMEM. That recovered about 80 bytes. So it seems like this particular program needs 300 to 350 bytes to run correctly
With Serial Disabled
The important number here is 431 bytes left for runtime variables when Serial.enable() is commented out.
Sketch uses 28296 bytes (87%) of program storage space.
Maximum is 32256 bytes.
Global variables use 1617 bytes (78%) of dynamic memory,
leaving 431 bytes for local variables.
Maximum is 2048 bytes.
With Serial Enabled
The important part here is the 234 bytes left for runtime variables when Serial.enable() is invoked.
Sketch uses 29278 bytes (90%) of program storage space.
Maximum is 32256 bytes.
Global variables use 1814 bytes (88%) of dynamic memory,
leaving 234 bytes for local variables.
Maximum is 2048 bytes.
Comments
Post a Comment