Go Down

Topic: I2C LCD and GPS as a clock (Read 149 times) previous topic - next topic

politxillo

Hi everybody,
i've just recieved my U-blox neo6m Gps module for arduino, and i've already got an I2C LCD (4x20) (which works o 0x3F) display, now i want to connect them to show in the display the time (until millisecconds) HH:MM:SS;SS, but i don't know how to do it. Could somebody teach me a little bit?
Thnx!

ChrisTenone

Hi politixillo,

What is your background - that is, what projects have you done before? Have you ever used a gps module, do you have a library for communicating with it? Have you hooked up the LCD and displayed text and numbers on it? How about serial (gps devices communicate with regular serial) - what Arduino are you going to use with it?

Answers to these questions will determine how to help you.
Wubba lubba dub dub!

politxillo

Hi politixillo,

What is your background - that is, what projects have you done before? Have you ever used a gps module, do you have a library for communicating with it? Have you hooked up the LCD and displayed text and numbers on it? How about serial (gps devices communicate with regular serial) - what Arduino are you going to use with it?

Answers to these questions will determine how to help you.

Hi,
Thanks for taking a look at my thread,
i've done some easy projects before, like displaying some text in the I2C LCD text when a metal detector turn to high voltage: The GPS module is the very first time I use it, but I know the basic about NMEA protocol, in fact this morning I displayed the NMEA in the serial monitor of my computer just to be shure that i've soldered right the pins of the GPS module. I've download TinyGPS library to control and "clear" the NMEA sentences it gives the module to me (but i don't know nothing about the library). And finally i'm using an UNO.

mrburnette

#3
Aug 30, 2016, 09:49 pm Last Edit: Aug 30, 2016, 09:50 pm by mrburnette
You'll find a number of GPS clock projects here. 

You can easily see how the Adafruit GPS lib is used and I have the formatting in the shetch.


Ray

politxillo

You'll find a number of GPS clock projects here. 

You can easily see how the Adafruit GPS lib is used and I have the formatting in the shetch.


Ray
wow, this one https://www.hackster.io/rayburne/5-billion-arduino-gps-clock-for-25-496a20?ref=user&ref_id=506&offset=40 looks amazing, i'd like to know how to do this but just with a 4x20 LCD display, I supose the big LCD display it uses an I2C too.

mrburnette

<...>
i'd like to know how to do this but just with a 4x20 LCD display, I supose the big LCD display it uses an I2C too.
The graphic LCD is about $6 from China and is SPI.

I have built a clock specifically for the wife based on this OLED display that operates like an 1802 LCD.  I used one of those inexpensive Chinese I2C adapters. The full source is attached.

I suspect that the bulk of the code can be hacked for your 4-line I2C display.
//   Connect the GPS TX (transmit) pin to Digital 3 input

Good luck! 


/dev

Quote from: mrburnette
You can easily see how the Adafruit GPS lib is used
Have you looked at NeoGPS yet?  The Adafruit_GPS with SoftwareSerial is a particularly inefficient combination.  Just for fun, I have attached a version of your sketch that uses NeoGPS and NeoSWSerial.  The program size is about 1600 bytes smaller, and it uses 700 fewer bytes of RAM (only 575 used).  :o  

Other things to note:

*  NeoGPS has flags to indicate that the date/time is not valid yet.  If the GPS receiver does not have good reception, those fields will be empty.  Maybe it's something you want to check and display a message?

*  SoftwareSerial blocks all other code when RX chars are being received.  That's not crucial for this app, since there is only one source of incoming data.  If you have other apps with other input devices (or SD logging), NeoSWSerial will help with performance and reliability.  And if you have a choice of pins in the future, you might want to consider pins 8 & 9 for the GPS.  That would let you use AltSoftSerial, which is even better.

*  It doesn't use the String class, which was only used for day and month names.  Again, not crucial because the names are constants, but it accounts for the 1600 byte savings in the program space (and a little RAM).  And it's probably best if the OP, a beginner, doesn't start out using them.  Those names are still in RAM, BTW.

*  It uses the F macro for double-quoted strings.  This saved more than 100 bytes of RAM in the prints, both to Serial and the lcd.  It works with the Streaming operators, too.

*  It uses the classic UNIX technique for Date/Time calculations.  Leap years, local time zones, 2- and 4-digit years, and DST are fully accommodated.  Calendar math is performed in seconds, then converted to a time struct with hours, minutes, etc.  See Time.h and Time.cpp

*  The DST switch is checked all the time; you don't have to reset for it to take effect.

...and a few other coding tricks sprinkled in that you might like...  :)

Cheers,
/dev

politxillo

#7
Aug 31, 2016, 11:41 am Last Edit: Aug 31, 2016, 12:46 pm by politxillo
Hello again, yesterday I finally got a code which also do what I want, it's not so tricky (but still hard to typ it for me  >:(  ) and the result is pretty good. The LCD shows the time with Hours, Minutes, Seconds, and decimals. The clock gets updated every seccond while the GPS is fixed, but I would like to she the hundreths runing there in the LCD, not only the secconds, could somebody take a look at it? I think i'm near to what I need  :D
I use TinyGPS library for the module and New Liquid Crystal one for the LCD
Code: [Select]
#include <SoftwareSerial.h>//incluimos SoftwareSerial
#include <TinyGPS.h>//incluimos TinyGPS
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x3F // <<----- Add your address here.  Find it from I2C Scanner
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

TinyGPS gps;//Declaramos el objeto gps
SoftwareSerial serialgps(4,3);//Declaramos el pin 4 Tx y 3 Rx
//Declaramos la variables para la obtención de datos
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long chars;
unsigned short sentences, failed_checksum;

void setup()
{

lcd.begin(20,4);//Iniciamos el puerto serie
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
serialgps.begin(9600);//Iniciamos el puerto serie del gps
//Imprimimos:
lcd.setCursor(0,0);
lcd.print("Buscando GPS");
}

void loop()
{
while(serialgps.available())
{
int c = serialgps.read();
if(gps.encode(c))
{
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
lcd.setCursor(0,0);
lcd.print(" Hora: "); lcd.print(hour, DEC); lcd.print(":");
lcd.print(minute, DEC); lcd.print(":"); lcd.print(second, DEC);
lcd.print("."); lcd.print(hundredths, DEC);
gps.stats(&chars, &sentences, &failed_checksum);
}
}
}

mrburnette

Have you looked at NeoGPS yet?  The Adafruit_GPS with SoftwareSerial is a particularly inefficient combination.  Just for fun, I have attached a version of your sketch that uses NeoGPS and NeoSWSerial.  The program size is about 1600 bytes smaller, and it uses 700 fewer bytes of RAM (only 575 used).  :o 
<...>
@ /dev

NeoGPS is the obvious winner - thanks for bringing it to my attention.  Less resources is definitely a plus.  Very nicely integrates into the code which is quiet ugly right now because it was originally written long ago for use with the ILI9340 graphic display and I hacked the character-based I2C OLED as my wife requires a high-contrast display that is not as busy as the initial graphic multi-color one.


Regards,

Ray

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy