teensy 3.1

Status
Not open for further replies.
i am having an issue with liquid crystal serial output from gps. this is the example code from the library timegps with liquid crystal spliced in where i thought it should go based on my very rough understanding.
I am not new to coding, I'm just not very good at it. this is on a teensy3.1 so i can learn and also i don't need that much brain power or speed for this first iteration. i am just trying to learn and also use what i have atm. Once i get this working i will start to change it to see if i can get more information displayed and or add hardware to change info displayed ( like button trigger to change info)

gps module:Adafruit Ultimate GPS Breakout V3
teensy 3.1
16x2 lcd white on blue

everything is wired up correctly, i can run hello world and i also get the gps d&t on the monitor.

p.s. i could have some names wrong i.e. lcd is looking for the wrong serial output?

Code:
/*
 * TimeGPS.pde
 */
#include <TimeLib.h>
#include <TinyGPS.h> 
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

TinyGPS gps; 

#define SerialGPS Serial1

// Offset (UTC)
const int offset = -5;   // dst
//const int offset = -6;  // cst 
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Ideally, it should be possible to learn the time zone
// based on the GPS position data.  However, that would
// require a complex library, probably incorporating some
// sort of database using Eric Muller's time zone shape
// maps, at http://efele.net/maps/tz/

time_t prevDisplay = 0;

void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);
  SerialGPS.begin(9600);
  Serial.println("Waiting for GPS time ... ");
}

void loop()
{
  while (SerialGPS.available()) 
  {
    if (gps.encode(SerialGPS.read())) 
    {
      unsigned long age;
      int Year;
      byte Month, Day, Hour, Minute, Second;
      gps.crack_datetime(&Year, &Month, &Day, &Hour, &Minute, &Second, NULL, &age);
      if (age < 500) 
      {
        setTime(Hour, Minute, Second, Day, Month, Year);
        adjustTime(offset * SECS_PER_HOUR);
      }
    }
  }
  if (timeStatus()!= timeNotSet) 
  {
    if (now() != prevDisplay) 
    {
      prevDisplay = now();
      digitalClockDisplay();  
    }
  }
  if (Serial.available()) 
  {
    delay(100);
    lcd.clear();
    while (Serial.available() > 0) 
    {
      lcd.write(Serial.read());
    }
  }
}


void digitalClockDisplay()
{
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits) 
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

edit. To whom it may concern, i confirm that mcafee does not play nice with the Arduino ide.
 
update: i have added to my code and the lcd now reads waitng for time. i guess i just don't understand what commands/code to use to make the teensy send the data from the gps to the lcd. as i might have said earlier i already tried using just the lcd serial example but that didn't work either.


Code:
#include <TimeLib.h>
#include <TinyGPS.h> 
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>

TinyGPS gps; 

#define SerialGPS Serial1

// Offset (UTC)
const int offset = -5;   // dst
//const int offset = -6;  // cst 
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Ideally, it should be possible to learn the time zone
// based on the GPS position data.  However, that would
// require a complex library, probably incorporating some
// sort of database using Eric Muller's time zone shape
// maps, at http://efele.net/maps/tz/

time_t prevDisplay = 0;

void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);
  SerialGPS.begin(9600);
  [U]lcd.print("waiting for time");[/U]
  Serial.println("Waiting for GPS time ... ");
}

void loop()
{
  while (SerialGPS.available()) 
  {
    if (gps.encode(SerialGPS.read())) 
    {
      unsigned long age;
      int Year;
      byte Month, Day, Hour, Minute, Second;
      gps.crack_datetime(&Year, &Month, &Day, &Hour, &Minute, &Second, NULL, &age);
      if (age < 500) 
      {
        setTime(Hour, Minute, Second, Day, Month, Year);
        adjustTime(offset * SECS_PER_HOUR);
      }
    }
  }
  if (timeStatus()!= timeNotSet) 
  {
    if (now() != prevDisplay) 
    {
      prevDisplay = now();
      digitalClockDisplay();
      
    }
  }
  
if (Serial.available()) 
  {
    delay(100);
    lcd.clear();
    while (SerialGPS.available()) 
    {
      lcd.write(SerialGPS.available());
    }
  }
}
void digitalClockDisplay()
{
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits) 
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}
 
Status
Not open for further replies.
Back
Top