Hello,
I use the following code to print the time (given by a GPS module) in an I2C LCD when a body cuts a photocell, but it only shows until secconds (hundreths remain always at 00), do somebody know how to accurate this until hundreths? I supose something must be tpuched with GPS updating rate but idk nothing about changing that.
#include <SoftwareSerial.h>//incluimos SoftwareSerial
#include <TinyGPS.h>//incluimos TinyGPS
#include <Wire.h>
#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
const int PIRPin= 2;
//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
pinMode(PIRPin, INPUT);
serialgps.begin(9600);//Iniciamos el puerto serie del gps
//Imprimimos:
lcd.setCursor(0,0);
lcd.print("Buscando GPS");
}
void loop()
{
int value= digitalRead(PIRPin);
if (value == HIGH)
{
while(serialgps.available())
{
int c = serialgps.read();
if(gps.encode(c))
{
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
lcd.clear();
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);
}
}
}
}
Depends on your GPS. Your best bet is to use the 1 Hz output of the GPS as an interrupt, record the micros() value at that time and keep track of hundredths yourself.
KeithRB:
Depends on your GPS. Your best bet is to use the 1 Hz output of the GPS as an interrupt, record the micros() value at that time and keep track of hundredths yourself.
could you please tell me a little bit more anout how to do that? My Gps module is an U-Blox Neo 6M which has RX and TX outputs.
(look for "Maximum Navigation update rate" in the datasheet)
you can get 5 Hz, I think default is 1Hz
?How to modify the update rate
Start the u-center to configure the settings of Port and Baud rate
Select View->Messages View, and then a window will pop out. Select UBX->CFG(Config)->RATE(Rates)
Enter “200” in the option Measurement Period
Click the button Send to transmit the command to the GPS module. Now, the update rate is modified to 5Hz.
For data save on power down, select UBX->CFG(Config)->CFG(Configuration)
Select the option Save current configuration, and then choose the option 2-I2C-EEPROM in the Devices box.
Click the button Send to save the current configuration to EEPROM.
Because I want to do 2 devices with EXACTLY the same time (hundreths included) and GPS time is the more reliable one.
Are you connecting one GPS to two devices? If you are using two GPS units, any assumption you make about accuracy will be wrong, unless you assume that the will be different.
For what? The GPS will not report the time to the level of accuracy that the OP wants. The price of the GPS is from the U-blox web site, when you want to order 1.
I do, i actually have the GPS transmitting in the port serie with a blink sketch in the arduino but the u center doesn't recognasy any device in the com3 port