Knowing the time?

I am working with Mikal Hart’s inverse geocache code and trying to integrate some of this other code to show the time. From his website I have found:

http://arduiniana.org/libraries/tinygps/

Date/time cracking
For more convenient access to date/time use this:
int year;
byte month, day, hour, minutes, second, hundredths;
unsigned long fix_age;

gps.crack_datetime(&year, &month, &day,
&hour, &minute, &second, &hundredths, &fix_age);

But when I try to integrate it into the code below, I keep getting errors. Can you suggest how the best way to integrate is? What I am wanting to do is show the date and time on the serial monitor and maybe even on the display.

Thank you for your help.

Chip

#include <EEPROM.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>

void PowerOff();

/* Setup Interfaces, Constants and some Variables */
TinyGPS gps;
SoftwareSerial ss(2,3);
SoftwareSerial lcd(4, 5);
static const float DEST_LAT = 32.54933;  // Geofest In The Park
static const float DEST_LONG = -85.47613;  // 
static const int RADIUS = 50; // meters
static const int MAX_ATTEMPT = 50;
static const int EEPROM_OFFSET = 100;
static const int power = 8; // mosfet switch control
char c=0;
int attempt_counter;

void setup()
{
  // Make sure MOSFET Power switch pin 8 is OUTPUT and HIGH
  pinMode(power, OUTPUT);
  digitalWrite(power, HIGH);
  // Make sure GPS is ON and LCD defined */
  pinMode(19, OUTPUT);  
  digitalWrite(19, LOW);
  Serial.begin(9600);
  Serial.print("TinyGPS to SoftLCD Term");
  Serial.println();
  lcd.begin(9600);
  lcd.write(17);
  lcd.write(12);
  ss.begin(9600);
  attempt_counter = EEPROM.read(EEPROM_OFFSET);
  if (attempt_counter == 0xFF) // brand new EEPROM?
  attempt_counter = 0;
  ++attempt_counter;
  
  if (attempt_counter < 5)
  {
    lcd.println("Inverse Geocache");
    lcd.println("Version 2.4.003 ");
    delay(4000);
  
    lcd.write(12);
    delay(1000);
    lcd.println("Ur Mission      ");
    lcd.println("is to find GZ!! ");
    delay(4000);
  
    lcd.write(12);
    delay(1000);
    lcd.println("U Have 50 tries ");
    lcd.println("Before Lock-up  ");
    delay(4000);
  }
  if (attempt_counter >= MAX_ATTEMPT)
  {
  lcd.write(12);
  delay(1000);
  lcd.println("Sorry No More   ");
  lcd.println("Attempts Allowed");
  delay(5000);
  PowerOff();
  }
  lcd.write(12);
  delay(1000);
  lcd.println("This is try # ");
  lcd.write(142);
  lcd.print(attempt_counter);
  delay(2000);
  EEPROM.write(EEPROM_OFFSET, attempt_counter);
  lcd.write(148);
  lcd.println("Seeking Signal..");
  delay(2000);
}

void loop()
{
  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
 for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
       delay(5);
      c = ss.read();
//    Serial.print(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
       // Serial.println(newData);
    }
  }

  if (newData)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
    float distance_meters = TinyGPS::distance_between(flat, flon, DEST_LAT, DEST_LONG);

      /* Are we close?? */
      if (distance_meters <= RADIUS)
      {
        lcd.write(12);
        delay(1000);
        lcd.println("Good Job!!      ");
        lcd.println("Access Granted!!");
        delay(3000);
        lcd.write(212);
        lcd.write(217);
        lcd.write(227);
        lcd.write(212);
        lcd.write(217);
        lcd.write(227);
        lcd.write(214);
        lcd.write(219);
        lcd.write(230);
        lcd.write(12);
        delay(2000);
        lcd.println("Padlock1:<<  799");
        lcd.println("Padlock2:>>  825");
        delay(20000);
      }
      else
      {
        /* We are not very far */
        lcd.write(12);
        delay(1000);
        lcd.println("Distance: ");
        if (distance_meters < 1000)
        {
          lcd.write(138);
          lcd.print((int)distance_meters);
          lcd.write(141);
          lcd.println(" m.");
          delay(2000);
        }
        else
        {
          /* We are further away... */
          lcd.write(138);
          lcd.print((int)(distance_meters / 1000));
          lcd.write(141);
          lcd.println("km.");
          delay(2000);
        }  
        lcd.write(12);
        delay(1000);
        lcd.println("-Access Denied!-");
        delay(1000);
        lcd.write(212);
        lcd.write(217);
        lcd.write(220);
        lcd.write(214);
        lcd.write(215);
        lcd.write(220);
        lcd.write(12);
        delay(2000);
        lcd.println("-Access Denied!-");
        delay(1000);
        lcd.write(212);
        lcd.write(217);
        lcd.write(220);
        lcd.write(214);
        lcd.write(215);
        lcd.write(220);
        delay(2000);
      }
     PowerOff();  
  }
  /* Turn off after 2 minutes */
    if (millis() >= 120000)
  { 
    lcd.write(12);
    delay(1000);
    lcd.println("Must Go Outside!");
    lcd.println("Duh!!!!!!!!!!!! ");
   // lcd.print(millis()/1000);
    delay(2000);
    PowerOff(); 
  }
  
  gps.stats(&chars, &sentences, &failed);
  Serial.print(" CHARS=");
  Serial.print(chars);
  Serial.print(" SENTENCES=");
  Serial.print(sentences);
  Serial.print(" CSUM ERR=");
  Serial.println(failed);
   
}

/* Called to shut off the system using the Mosfet Power switch */
 void PowerOff()
{
  lcd.write(12);
  delay(1000);
  lcd.println("Power Off Now!  ");
  lcd.println("Bye!            ");
  delay(4000);
  lcd.write(18);
  delay(1000);
  lcd.write(21);
    
  /* Bring Mosfet Power switch control pin LOW to turn off */
  digitalWrite(power, LOW);

  /* This is the back door.  If we get here, then the battery power */
  /* is being bypassed by the USB port. We'll wait 30 seconds and   */
  /* then grant access. */
  delay(10000);
    
  /* Reset the attempt counter */
  Serial.println("Counter is reset to 0"); 
  EEPROM.write(EEPROM_OFFSET, 0);
  
  
  /* Exit the program for real */
  exit(1);
}

Did you read the post labelled “Read this before posting a programming question”?

Why not?

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the # button above the posting area.

I keep getting errors.

What errors?

How to use this forum

I am sorry for not using the correct format. That is my fault. Thank you Mr. Gammon for telling me what to do.

The error I get is invalid use of void expression.

I have included the code that I was using while trying to figure this out.

/* This is my second Inverse Geocaching device using a Li-Poly GPS Arduino Clone Board.
   It requires the use of SoftwareSerial and Mikal's TinyGPS library (for the GPS chip), 
   assumes that you have a 9600-baud serial GPS device hooked up on pins 2(rx) and 3(tx)
   and a Parallax 3-wire serial 2 x 16 LCD on Pin 5..
   Written by Marc Tessier. Released on 9/25/2012.
*/

#include <EEPROM.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>

void PowerOff();

/* Setup Interfaces, Constants and some Variables */
TinyGPS gps;
SoftwareSerial ss(2,3);
SoftwareSerial lcd(4, 5);
static const float DEST_LAT = 32.54933;  // Geofest In The Park
static const float DEST_LONG = -85.47613;  // 
static const int RADIUS = 50; // meters
static const int MAX_ATTEMPT = 50;
static const int EEPROM_OFFSET = 100;
static const int power = 8; // mosfet switch control
char c=0;
int attempt_counter;
int year;
byte month, day, hour, minutes, second, hundredths;
unsigned long fix_age;


void setup()
{
  // Make sure MOSFET Power switch pin 8 is OUTPUT and HIGH
  pinMode(power, OUTPUT);
  digitalWrite(power, HIGH);
  // Make sure GPS is ON and LCD defined */
  pinMode(19, OUTPUT);  
  digitalWrite(19, LOW);
  Serial.begin(9600);
  Serial.print("TinyGPS to SoftLCD Term");
  Serial.println();
  lcd.begin(9600);
  lcd.write(17);
  lcd.write(12);
  ss.begin(9600);
  attempt_counter = EEPROM.read(EEPROM_OFFSET);
  if (attempt_counter == 0xFF) // brand new EEPROM?
  attempt_counter = 0;
  ++attempt_counter;
  
  if (attempt_counter < 5)
  {
    lcd.println("Inverse Geocache");
    lcd.println("Version 2.4.003 ");
    delay(4000);
  
    lcd.write(12);
    delay(1000);
    lcd.println("Ur Mission      ");
    lcd.println("is to find GZ!! ");
    delay(4000);
  
    lcd.write(12);
    delay(1000);
    lcd.println("U Have 50 tries ");
    lcd.println("Before Lock-up  ");
    delay(4000);
  }
  if (attempt_counter >= MAX_ATTEMPT)
  {
  lcd.write(12);
  delay(1000);
  lcd.println("Sorry No More   ");
  lcd.println("Attempts Allowed");
  delay(5000);
  PowerOff();
  }
  lcd.write(12);
  delay(1000);
  lcd.println("This is try # ");
  lcd.write(142);
  lcd.print(attempt_counter);
  delay(2000);
  EEPROM.write(EEPROM_OFFSET, attempt_counter);
  lcd.write(148);
  lcd.println("Seeking Signal..");
  delay(2000);
}

void loop()
{
  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
 for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
       delay(5);
      c = ss.read();
//    Serial.print(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
       // Serial.println(newData);
    }
  }

  if (newData)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
    float distance_meters = TinyGPS::distance_between(flat, flon, DEST_LAT, DEST_LONG);
    Serial.print(gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &fix_age));

      /* Are we close?? */
      if (distance_meters <= RADIUS)
      {
        lcd.write(12);
        delay(1000);
        lcd.println("Good Job!!      ");
        lcd.println("Access Granted!!");
        delay(3000);
        lcd.write(212);
        lcd.write(217);
        lcd.write(227);
        lcd.write(212);
        lcd.write(217);
        lcd.write(227);
        lcd.write(214);
        lcd.write(219);
        lcd.write(230);
        lcd.write(12);
        delay(2000);
        lcd.println("Padlock1:<<  799");
        lcd.println("Padlock2:>>  825");
        delay(20000);
      }
      else
      {
        /* We are not very far */
        lcd.write(12);
        delay(1000);
        lcd.println("Distance: ");
        if (distance_meters < 1000)
        {
          lcd.write(138);
          lcd.print((int)distance_meters);
          lcd.write(141);
          lcd.println(" m.");
          delay(2000);
        }
        else
        {
          /* We are further away... */
          lcd.write(138);
          lcd.print((int)(distance_meters / 1000));
          lcd.write(141);
          lcd.println("km.");
          delay(2000);
        }  
        lcd.write(12);
        delay(1000);
        lcd.println("-Access Denied!-");
        delay(1000);
        lcd.write(212);
        lcd.write(217);
        lcd.write(220);
        lcd.write(214);
        lcd.write(215);
        lcd.write(220);
        lcd.write(12);
        delay(2000);
        lcd.println("-Access Denied!-");
        delay(1000);
        lcd.write(212);
        lcd.write(217);
        lcd.write(220);
        lcd.write(214);
        lcd.write(215);
        lcd.write(220);
        delay(2000);
      }
     PowerOff();  
  }
  /* Turn off after 2 minutes */
    if (millis() >= 120000)
  { 
    lcd.write(12);
    delay(1000);
    lcd.println("Must Go Outside!");
    lcd.println("Duh!!!!!!!!!!!! ");
   // lcd.print(millis()/1000);
    delay(2000);
    PowerOff(); 
  }
  
  gps.stats(&chars, &sentences, &failed);
  Serial.print(" CHARS=");
  Serial.print(chars);
  Serial.print(" SENTENCES=");
  Serial.print(sentences);
  Serial.print(" CSUM ERR=");
  Serial.println(failed);
   
}

/* Called to shut off the system using the Mosfet Power switch */
 void PowerOff()
{
  lcd.write(12);
  delay(1000);
  lcd.println("Power Off Now!  ");
  lcd.println("Bye!            ");
  delay(4000);
  lcd.write(18);
  delay(1000);
  lcd.write(21);
    
  /* Bring Mosfet Power switch control pin LOW to turn off */
  digitalWrite(power, LOW);

  /* This is the back door.  If we get here, then the battery power */
  /* is being bypassed by the USB port. We'll wait 30 seconds and   */
  /* then grant access. */
  delay(10000);
    
  /* Reset the attempt counter */
  Serial.println("Counter is reset to 0"); 
  EEPROM.write(EEPROM_OFFSET, 0);
  
  
  /* Exit the program for real */
  exit(1);
}

I Guess the next line gives you the void error

Serial.print(gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &fix_age));

The gps.crack_datetime function fills the variables mentioned with the right values, but it’s not a function you can print.

gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &fix_age);
Serial.print (year);
Serial.print ("-");
Serial.print (month);
etc. etc...

This should work better, although I can’t really tell since I have no GPS, I just checked the examples of the library.

By the way, there’s another problem as well, you won’t get any info from the gps.

You’re using the softwareserial library, which can only monitor the incoming data of one softwareserial-port at the same time. Since you last opened the softwareserial lcd-port, arduino now monitors the LCD for incoming data and does nothing with info sent by the gps.

With multiple softwareserial ports, you need to use the listen() command of the library in you sketch to select which one gets monitored.

You could also use a single softwareserial port. You’re not reading any info from LCD, you’re not sending any info to GPS and both use the same baudrate. So… it should be possible to connect both devices to the same softwareserial port.

chipthomas: The error I get is invalid use of void expression.

Can you post the actual error message from the compiler?

This is what I get.

Inverse_Code_With_Added_Date_Time_Code.ino: In function 'void loop()': Inverse_Code_With_Added_Date_Time_Code:124: error: invalid use of void expression

Simpson_Jr: I Guess the next line gives you the void error

Serial.print(gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &fix_age));

The gps.crack_datetime function fills the variables mentioned with the right values, but it's not a function you can print.

gps.crack_datetime(&year, &month, &day, &hour, &minutes, &second, &hundredths, &fix_age);
Serial.print (year);
Serial.print ("-");
Serial.print (month);
etc. etc...

This should work better, although I can't really tell since I have no GPS, I just checked the examples of the library.

By the way, there's another problem as well, you won't get any info from the gps.

You're using the softwareserial library, which can only monitor the incoming data of one softwareserial-port at the same time. Since you last opened the softwareserial lcd-port, arduino now monitors the LCD for incoming data and does nothing with info sent by the gps.

With multiple softwareserial ports, you need to use the listen() command of the library in you sketch to select which one gets monitored.

You could also use a single softwareserial port. You're not reading any info from LCD, you're not sending any info to GPS and both use the same baudrate. So... it should be possible to connect both devices to the same softwareserial port.

You know what, I remember that now that you say that.