Arduino + I2C + Ublox GPS insufficient memory because of global variables

I’ve just managed to compile GPS code for Arduino Nano + I2C 2004 lcd + GPS device, but get the the note:

“Sketch uses 10590 bytes (73%) of program storage space. Maximum is 14336 bytes.
Global variables use 793 bytes (77%) of dynamic memory, leaving 231 bytes for local variables. Maximum is 1024 bytes. Low memory available, stability problems may occur.”

How should i change the code to release the memory?

Code:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 10, TXPin = 9;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
lcd.begin(20, 4);
lcd.begin(20,4); 
lcd.setCursor(5,0); 
lcd.print("Text");
lcd.setCursor(8,1);  
lcd.print("****");
lcd.setCursor(3,2);  
lcd.print("Text");
lcd.setCursor(8,3);  
lcd.print("****");
delay(4000);
lcd.clear();
delay(1000);
}
void loop()
{
 Serial.begin(115200);
ss.begin(GPSBaud);
while (ss.available() > 0)
  if (gps.encode(ss.read()))
    displayInfo();

if (millis() > 5000 && gps.charsProcessed() < 10)
{
  lcd.print(F("No GPS detected"));
  while(true);
}
}

void displayInfo()
{   
if (gps.location.isValid())
{
  lcd.setCursor(0,0);
  lcd.print(gps.satellites.value());
  delay(2800);
  lcd.print("Lat=");
  lcd.print(gps.location.lat(), 6);
  lcd.setCursor(0,1);
  lcd.print("Lng=");
  lcd.print(gps.location.lng(), 6);    
  delay(3000);
  lcd.setCursor(0,2);
  lcd.print(gps.date.value());
  lcd.setCursor(0,3);
  lcd.print(gps.time.value());
  lcd.print("          ");
  lcd.setCursor(0,3);
  delay(1000); 
  lcd.print(gps.speed.kmph());
  lcd.print(" km/h   ");
  lcd.setCursor(0,2);
  lcd.print(gps.course.deg());
  lcd.print("°  ");
  lcd.setCursor(0,1);
  lcd.print(gps.altitude.meters());
  lcd.print(" m  ");
}
else
{
 lcd.setCursor(0,0);
 lcd.print("No GPS data");
 lcd.print("                ");
 delay(3000);
}   }

Using the F macro to put all of those string literals in flash would help.

Please edit your post to add code tags, as described in the "How to use this forum" post.

Post the complete error message. Global variables are most likely not the problem.

I've just managed to compile GPS code for Arduino Nano + I2C 2004 lcd + GPS device, but get the the note:

Sketch uses 10590 bytes (73%) of program storage space. Maximum is 14336 bytes" Global variables use 793 bytes (77%) of dynamic memory, leaving 231 bytes for local variables. Maximum is 1024 bytes.

So the IDE is set up for an Arduino with 16K of Flash and 1K of RAM.

I thought a Nano had 32K of Flash and 2K of RAM.

Good point. The OP chose the wrong board.

Correct, I have had problems with the test code. Maybe I should stop uploading through USB, because RX/TX-lines are part of the schematic.

Maybe I should stop uploading through USB, because RX/TX-lines are part of the schematic.

Maybe you get a simpler hobby, like hang-gliding without a glider, because that response has nothing to do with the statements made/questions asked.

srnet: So the IDE is set up for an Arduino with 16K of Flash and 1K of RAM.

I thought a Nano had 32K of Flash and 2K of RAM.

There are Nanos with the ATmega168 and Arduino AVR Boards has a Tools > Processor > ATmega168 option. So it's possible Tbird200 does have the correct board selected. Only Tbird200 can tell us which microcontroller is on their Nano (it's written on the large square black chip on the top of the board).

Tbird200: Correct, I have had problems with the test code. Maybe I should stop uploading through USB, because RX/TX-lines are part of the schematic.

I don't understand what you mean by that. If you mean you're considering using an ISP programmer to upload sketches to your Nano so you can free up the 2 kB reserved for the bootloader that allows uploading over the Nano's USB jack, that will give you more program memory, but it won't free up any dynamic memory, which is what you're asking about. You could also switch to using the optiboot bootloader on the Nano and free up 1.5 kB of program memory while still being able to upload over its USB jack. Again, that won't free up any dynamic memory though.