Low memory available: Logging GPS&Accelerometer in Arduino Uno

Hi everyone

I’m still new to arduino.
I’m trying to log GPS, Accelerometer, and 2 Analog inputs data into an SD card.

My setup is:
Arduino Uno R3
Arduino 9 Axes Motion Shield
Adafruit Ultimate GPS Logger Shield

I basically took the shield_sdlog example from the Adafruit GPS library and added another bit from the Accelerometer example of the NAxisMotion library.

When I compile, I get the following message:

Sketch uses 24492 bytes (75%) of program storage space. Maximum is 32256 bytes.
Global variables use 1754 bytes (85%) of dynamic memory, leaving 294 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

The file to write on appears to open succesfully.
Checking the free RAM, it appears there are always 229 bytes free (I’m not sure I’m checking this correctly, though).
Everything appears to run smoothly.
However, when I list the files in the SD card, the file I just created doesn’t exist.

Has anyone dealt with this or similar problem?
Besides changing my code, is there anything I could use? Maybe some smaller libraries?
I’m restricted to use the Uno board. Do you think it doesn’t have enough memory to run these two shields simultaneously?

Thank you

Code attached

shield_sdlog_acc.ino (8.68 KB)

I’m restricted to use the Uno board. Do you think it doesn’t have enough memory to run these two shields simultaneously?

Yes. NeoGPS will shrink your program quite a bit. It has an example SD logger. I have attached a sketch, modified to use NeoGPS and NeoSWSerial.

SoftwareSerial is the worst choice for a second serial port, because it disables interrupts for long periods of time. This will interfere with other parts of your sketch. And if you want a faster update rate, you will need all the CPU time you can get.

Instead of writing the raw NMEA data, this sketch writes a few of the parsed GPS pieces: date, time, lat/lon, altitude and speed. Notice that it makes sure the values are valid before it tries to write them. If they are not valid, it just leaves an empty CSV field.

BTW, I think you need to use logfile.print (text) instead of logfile.write (binary).

The original sketch uses 27068 bytes of program space and 1837 bytes of RAM.
The NeoGPS version uses 27202 bytes of program space and 1428 bytes of RAM, saving ~400 bytes of RAM.

If you want to try it, NeoGPS and NeoSWSerial are available from the Arduino IDE Library Manager, under the menu Sketch → Include Library → Manage Libraries.


P.S. There is a lengthy post here about logging GPS, BNO055, wheel speed sensors and steering angle to an SD card at 100Hz. That link is the most recent version of his sketch.

adanur.ino (7.26 KB)

Thank you

It’s working now :slight_smile:

I made some further modifications.

I’m attaching the code in case someone needs it.

SDLog_Full.ino (13.3 KB)