Low memory available

Hello,
My project is to display GPS data in an OLED screen. My components are the Arduino UNO, Adafruit Ultimate GPS Logger Shield, and an Adafruit 128X64 OLED Screen.

I keep running into a low memory error during verification. It reads: “Global variables use 2,158 bytes (105%) of dynamic memory, leaving -110 bytes for local variables. Maximum is 2,048 bytes”

I was building the code by slowly blending the codes from the GPS shield with the code from the OLED screen. I verify every step of the way, and I ran into trouble right off the gate.

When I’ve included all the libraries I need, I’m at roughly 50% of dynamic memory. Then when I add the “#define” for the different pins used (see below), I run out of memory. Fair disclosure: I’m a complete newbie to this. I don’t know what or why certain things take up more space (currently trying to investigate).

I would greatly appreciate any suggestions or alternative code.

#include <SPI.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <avr/sleep.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_MOSI   0
#define OLED_CLK   1
#define OLED_DC    2
#define OLED_CS    3
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);


void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

As you have no code of your own there, you can only modify the libraries in an attempt to reduce the ram usage.

Looks like your collection of libraries are best suited for a Mega2560, with 8k of ram.

128X64 OLED Screen.

Graphics screens use lots of memory. I mean, that's 8K pixels right there... Support for SD card is also relatively expensive.

Then when I add the "#define" for the different pins used (see below), I run out of memory

No hash defines do not use any extra memory.

Grumpy_Mike: No hash defines do not use any extra memory.

It'd be the declaration after them that uses the extra memory.

pYro_65:

Grumpy_Mike: No hash defines do not use any extra memory.

It'd be the declaration after them that uses the extra memory.

No. There is no difference in memory usage between using a #define and actually writing the constant in where you need it.

Grumpy_Mike: No. There is no difference in memory usage between using a #define and actually writing the constant in where you need it.

You have no argument from me there, I said: "It'd be the declaration after them that uses the extra memory." Which is referring to the declaration of the variable 'display', not the defines.

:)