Help to get a simple LCD text string to work in the middle of GPS sketch


Well I have a “Mutt” of a gps/data logging/ lcd project here which I combined my own plus parts of sample sketches to make a gps datalogger that logs to an sd card and outputs coordinates on the LCD. The entire system works awesome except one part.

I added a simple toggle switch to pin 16 so that I can halt the logging of coordinates to the sd card and it does exactly what I want but I cannot for the life of me, figure out why I cannot display the word “PAUSED” on my LCD during this part of the code.

Now, At the bottom of the void loop it prints the coordinates out perfectly to the lcd. I can also I can clear the display with lcd.print" " where I want it to read “Paused” but if I try to add any text other than spaces, The program just locks up and wont even begin logging. Why is this?

Here is the entire working code and comments (about 2/3 down in the sketch) where I want to show the text “PAUSED” while the pin is set HIGH.
Sure would like to know whats going on here and why its doing this.

Thanks in Advance

#include <SPI.h>
#include <LCDKeypad.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <avr/sleep.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 9, 4, 5, 6, 3);

// Ladyada's logger modified by Bill Greiman to use the SdFat library

SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true
/* set to true to only log to SD when GPS has a fix, for debugging, keep it false */
#define LOG_FIXONLY false  

// Set the pins used
#define chipSelect 10
#define ledPin 13

File logfile;

// read a Hex value and return the decimal equivalent
uint8_t parseHex(char c) {
  if (c < '0')
    return 0;
  if (c <= '9')
    return c - '0';
  if (c < 'A')
    return 0;
  if (c <= 'F')
    return (c - 'A')+10;

// blink out an error code
void error(uint8_t errno) {

  while(1) {
    uint8_t i;
    for (i=0; i<errno; i++) {
      digitalWrite(ledPin, HIGH);
      digitalWrite(ledPin, LOW);
    for (i=errno; i<10; i++) {

void setup() {
  pinMode(14, INPUT); // Pin for the button-  Analog pins use 
  lcd.begin(16, 2);
  lcd.print("Starting New Log");
  lcd.print("                "); //Clear the LCD
  lcd.print("                ");

  Serial.println("\r\nUltimate GPSlogger Shield");
  pinMode(ledPin, OUTPUT);

  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {      
    Serial.println("Card init. failed!");
  char filename[15];
  strcpy(filename, "GPSLOG00.TXT");
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = '0' + i/10;
    filename[7] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {

  logfile =, FILE_WRITE);
  if( ! logfile ) {
    Serial.print("Couldnt create "); Serial.println(filename);
  //lcd.print("Log: "); lcd.println(filename);
  Serial.print("Writing to "); Serial.println(filename);
  // connect to the GPS at the desired rate

  // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  // uncomment this line to turn on only the "minimum recommended" data

  // Set the update rate
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 or 5 Hz update rate

  // Turn off updates on antenna status, if the firmware permits it

void loop() {
 //======================== Below is where the pause switch is set======================================
  int BUTTON = digitalRead(16); //   this is used for the pause button
  if (BUTTON == HIGH) {
    lcd.print("                "); // This is where I would like to print 'Paused" to the LCD.   Spaces work but add any text and it locks up!
    lcd.print("                ");
  //=================================== END of Pause Switch========================================
  char c =;
  if (GPSECHO)
     if (c)   Serial.print(c);

  if (GPS.newNMEAreceived()) {
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another 
    // Sentence parsed! 
    if (LOG_FIXONLY && !GPS.fix) {
        Serial.print("No Fix");

    //  log it!
    char *stringptr = GPS.lastNMEA();
    uint8_t stringsize = strlen(stringptr);
    if (stringsize != logfile.write((uint8_t *)stringptr, stringsize))    //write the string to the SD file
    if (strstr(stringptr, "RMC"))   logfile.flush();
   lcd.print("Lat: "); 
   lcd.print(GPS.latitude, 4);
   lcd.setCursor(0, 1);
   lcd.print("Long: ");
   lcd.print(GPS.longitude, 4); 

The problem sounds like it is caused by running out of memory. Granted that a series of spaces should take the same space as a series of characters....

Try using the F() macro for your string constants as inSerial.println(F("This string will be stored in flash memory"));


I dont think I understand. The issue is with printing to the lcd shield and as you said, I can put the spaces in with no issues. I'm really not concerned with the serial monitor output to show and I actually tried to delet all the plain serial output code to see if that may be the case. No help at all.

I may need to look into the data type last night I was able to get a single character to show in the lcd when I tried to declare a "char" variable with single quotes, but it only one of the characters in my text string... and it was just flashing away.

So confused about this little glitch!

What kind of Arduino are you using?

Before rejecting UKHeliBob's advice, I think you ought to heed it. Only if it proves not to help should you say so.

I dont think I understand. The issue is with printing to the lcd shield

Granted that the example I gave related to Serial output but the advice is also valid for output to the LCD and must be worth trying.

UK and Paul,

Didn't mean to be dismissive of your suggestion, I guess I should have said I don't understand what the F() macro does. I'm pretty new to this and I never heard of it before. I was however referring to the serial output but without knowing that it could be used with the LCD as well. I'm going to look into F() later tonight and try to figure out how to use it in my application and will check back in.


Have you got your pin 14 and 16 confused. Your first post does not make sense.

Where you have your two identical strings of blanks there, the compiler will realise they are the same, and store only one copy of the string of blanks in the code, and both of the print statements will use the same string.

When you put some text into it, the two strings become different, so the compiler has to store both strings in the code separately. That will take up more space than storing one string and referring to it in two places.