0

I have a nice sketch running which monitors a few things and displays output on an OLED display. Now I want to save the data to an SD card, but with or without the card module attached I'm getting constant reboots when I add 1 single line of code:

#include <SD.h>

Any idea what may be happening?

Stephen York
  • 121
  • 5

1 Answers1

2

The following libraries are probably used:

  • SD Card, using a buffer of 512 bytes (see also the comment of DataFiddler below).
  • SSD1306 OLED library, using a buffer of 1,024 bytes
  • Serial, using a buffer of 128 bytes (64 for RX, 64 for TX, see comment of Majenko below)

Since there is only 2,048 bytes of SRAM in an Arduino, this leaves 384 bytes. If you actually READ a file you are already above the maximum.

Your own global variables also will consume a considerable amount of SRAM.

Than, if you execute your sketch, parameters and local variables are stored on the stack (in SRAM), so even if your program starts well, it might/will run in problems when calling functions.

Michel Keijzers
  • 13,014
  • 7
  • 41
  • 58