Hallo
die Zeit wird auf einem LCD angezeigt, momentan lasse ich den seriellen Monitor mitlaufen. Wenn sie wieder mehrere satelliten hat, stelle ich den mitschnitt hier rein.
Das ganz soll einen millisekunden genauen Sync -impuls minütlich am Pin9 erzeugen, zur synchronisierung von Zeitnahmeuhren. An Pin2 liegt , Transistor verstärkt, das PPS Signal vom GPSmodul (Sekundentakt).
Leider momentan nur ein gpsmodul zur Hand.
Sketch ist aus dem adafruit Beispiel 'gewachsen'
#include <SoftwareSerial.h>
//#include <Wire.h>
#include <Adafruit_GPS.h>
#include <LiquidCrystal.h>
const int rs = 11, en = 10, d4 = 6, d5 = 5, d6 = 4, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// output pin 9, sqw interruptpin 2
const byte interruptPin = 2;
const byte outputPin = 9;
int lastminute;
int lastsecond;
int c;
bool output;
int hours;
int minutes;
int seconds;
bool insync = false;
bool set();
void enableGPSInterrupt();
#define HOUR_OFFSET +1 //MEZ
SoftwareSerial gpsSerial(8, 7); // GPS breakout/shield will use a
// software serial connection with
// TX = pin 8 and RX = pin 7.
Adafruit_GPS gps(&gpsSerial);
void setup() {
pinMode(outputPin, OUTPUT); //ausgang sync
pinMode(interruptPin, INPUT_PULLUP); // PPS GPS
// Setup Serial port to print debug output.
Serial.begin(115200);
Serial.println("Clock starting!");
lcd.begin(16, 2);
lcd.print("starting up");
gps.begin(9600);
// Configure GPS to onlu output minimum data (location, time, fix).
gps.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// Use a 10 hz, ten times a second, update rate.
gps.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
// Enable the interrupt to parse GPS data.
//enableGPSInterrupt(); Versuch ohne int
attachInterrupt(digitalPinToInterrupt(interruptPin), count, FALLING);
lcd.setCursor(0, 1);
char lcderror[16];
sprintf(lcderror, " - no GPS! - ");
lcd.print(lcderror);
//insync = false;
}
void loop() {
// Check if GPS has new data and parse it.
// gps.read im loop anstatt per int
gps.read();
if (gps.newNMEAreceived()) gps.parse(gps.lastNMEA());
if ((insync == false) && (gps.year != 0)) {
hours = gps.hour + HOUR_OFFSET; // Add hour offset to convert from UTC // to local time.
// Handle when UTC + offset wraps around to a negative or > 23 value
if (hours < 0) {
hours = 24 + hours;
}
if (hours > 23) {
hours = 24 - hours;
}
seconds = gps.seconds;
minutes = gps.minute;
Serial.print(gps.hour);
Serial.print(':');
Serial.print(gps.minute);
Serial.print(':');
Serial.println(gps.seconds);
insync = true;
} //snyc
//LCD befüllen
if (lastsecond != seconds) {
lcd.setCursor(0, 1);
// Serial.println(seconds);
char lcdout[16];
sprintf(lcdout, "%02u:%02u:%02u MEZ", hours, minutes, seconds);
lcd.print(lcdout);
if (seconds == 1) {
digitalWrite(outputPin, LOW); // ende sync impuls
output = false;
}
lastsecond = seconds;
if (seconds != gps.seconds) insync = false;
}
// Uhr laufen lassen
if (seconds == 59) output = true;
if (seconds >= 60) {
minutes++;
seconds = 0;
lcd.clear();
char lcdout[16];
sprintf(lcdout, "Fix/Q:%01u/%01u Sat.%01u", gps.fix, gps.fixquality, gps.satellites);
lcd.print(lcdout);
}
if (minutes == 60) {
hours++;
minutes = 0;
}
if (hours == 24) hours = 0;
} //loop
void count() {
seconds++;
if (output) digitalWrite(outputPin, HIGH);
}
SIGNAL(TIMER0_COMPA_vect) { //momentan auskommentiert, aufruf in loop
// Use a timer interrupt once a millisecond to check for new GPS data.
// This piggybacks on Arduino's internal clock timer for the millis()
// function.
gps.read();
}
void enableGPSInterrupt() { //momentan auskommentiert, aufruf in loop
// Function to enable the timer interrupt that will parse GPS data.
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF; //0XAF = 175
TIMSK0 |= _BV(OCIE0A);
}