рабочий код. отображение часов согласно часового пояса MSK на LCD. GPS(19200) и RTC работают.
This commit is contained in:
135
2024-07-22 01:53:34 +03:00
parent b56f705f05
commit 1ae6e04559
5 changed files with 74 additions and 46 deletions

View File

@@ -25,6 +25,7 @@ void GPS_RTC_Clock_setup() {
RTC_setup(); RTC_setup();
GPS_setup(); GPS_setup();
TZ_setup(); TZ_setup();
Serial.println("DEBUG[GPS_RTC_Clock_setup] done");
} }
void GPS_RTC_Clock_loop() { void GPS_RTC_Clock_loop() {

View File

@@ -19,26 +19,59 @@
SoftDMD dmd(2, 1); SoftDMD dmd(2, 1);
LiquidCrystal_I2C lcd(0x27, 16, 2); LiquidCrystal_I2C lcd(0x27, 16, 2);
unsigned long tmr_Blink;
char TempBuf[5] = "99.9"; // demo value char TempBuf[5] = "99.9"; // demo value
char HumiBuf[3] = "99"; // demo value char HumiBuf[3] = "99"; // demo value
bool LCD_Simple_clock;
void RTCtoLCD(bool ClockType = LCD_Simple_clock) {
if (millis() < 2000) ClockType = true;
else if (!NewSec && !NewMin && !NewHour) return;
char Clock[9];
char segment[3];
if (ClockType) {
snprintf(Clock, sizeof(Clock), "%.2u:%.2u:%.2u", hour(Loc_t), minute(Loc_t), second(Loc_t));
lcd.setCursor(0,0);
lcd.print(Clock);
}
else if (NewSec) {
snprintf(segment, sizeof(segment),"%.2u", second(Loc_t));
lcd.setCursor(6, 0);
lcd.print(segment);
}
if (NewMin) {
snprintf(segment, sizeof(segment),"%.2u", minute(Loc_t));
lcd.setCursor(3, 0);
lcd.print(segment);
}
if (NewHour) {
snprintf(segment, sizeof(segment),"%.2u", hour(Loc_t));
lcd.setCursor(0, 0);
lcd.print(segment);
}
}
void setup() { // the setup function runs once when you press reset or power the board void setup() { // the setup function runs once when you press reset or power the board
GPS_RTC_Clock_setup(); // first in setup
//Matrix_setup(); // LED display
dmd.setBrightness(5);
dmd.selectFont(Font_Chrono1);
dmd.begin();
dmd.clearScreen();
// LCD // LCD
lcd.init(); // Инициализация дисплея lcd.init(); // Инициализация дисплея
lcd.clear(); lcd.clear();
lcd.backlight(); lcd.backlight();
lcd.setCursor(0,0);
lcd.print("DEBUG[setup()]");
delay(500);
Serial.begin(19200); // = 9600, must be same as GPS for debug Serial.begin(19200); // = 9600, must be same as GPS for debug
Serial.println(); // flush serial Serial.println(); // flush serial
Serial.println("-Arduino Reboot-"); // debug Serial.println("-Arduino Reboot-"); // debug
GPS_RTC_Clock_setup(); // first in setup
//Matrix_setup(); // LED display
//dmd.setBrightness(5);
//dmd.selectFont(Font_Chrono1);
//dmd.begin();
//dmd.clearScreen();
lcd.setCursor(0, 0);
lcd.print(" ");
} }
void loop() { // the loop function runs over and over again forever void loop() { // the loop function runs over and over again forever
@@ -49,18 +82,9 @@ void loop() { // the loop function runs over and over again forever
// } // }
GPS_RTC_Clock_loop(); // first in loop GPS_RTC_Clock_loop(); // first in loop
//PrintSec(); RTCtoLCD();
//PrintHour(); PrintSec();
if (NewSec) { PrintHour();
RTCtoLCD();
}
}
void RTCtoLCD() {
char sz[32];
sprintf(sz, "%02d:%02d:%02d ", hour(Loc_t), minute(Loc_t), second(Loc_t));
lcd.setCursor(0,0);
lcd.print(sz);
} }
void PrintSec() { // print time if new second void PrintSec() { // print time if new second
@@ -68,16 +92,16 @@ void PrintSec() { // print time if new second
NewSec = false; // remove flag, do only once every sec NewSec = false; // remove flag, do only once every sec
char startmarker = '<'; char startmarker = '<';
char endmarker = '>'; char endmarker = '>';
Serial.print(startmarker); // for remote display via RS485 //Serial.print(startmarker); // for remote display via RS485
Serial.print(Loc_t); // for remote display via RS485 //Serial.print(Loc_t); // for remote display via RS485
Serial.println(endmarker); // for remote display via RS485 //Serial.println(endmarker); // for remote display via RS485
char TimeBuf[9]; // time string buffer, max n-1 char char TimeBuf[9]; // time string buffer, max n-1 char
snprintf(TimeBuf, sizeof(TimeBuf), "%.2u:%.2u:%.2u", // https://cplusplus.com/reference/cstdio/printf/ snprintf(TimeBuf, sizeof(TimeBuf), "%.2u:%.2u:%.2u", // https://cplusplus.com/reference/cstdio/printf/
hour(Loc_t), minute(Loc_t), second(Loc_t)); // time 24h format hour(Loc_t), minute(Loc_t), second(Loc_t)); // time 24h format
Serial.print("Time: "); // debug //Serial.print("Time: "); // debug
Serial.println(TimeBuf); // debug //Serial.println(TimeBuf); // debug
Print_time_zone(TimeBuf); // print to LED Matrix //Print_time_zone(TimeBuf); // print to LED Matrix
PrintMin(); PrintMin();
} }
} }
@@ -109,7 +133,7 @@ void PrintMin() {
snprintf(TextBuf, sizeof(TextBuf), " Err "); snprintf(TextBuf, sizeof(TextBuf), " Err ");
} }
} }
Print_date_zone(TextBuf); // print to LED Matrix //Print_date_zone(TextBuf); // print to LED Matrix
if (NewMin) { // print date if new minute if (NewMin) { // print date if new minute
NewMin = false; // remove flag, do only once every min NewMin = false; // remove flag, do only once every min
@@ -117,15 +141,15 @@ void PrintMin() {
// long date version // long date version
snprintf(DateBuf, sizeof(DateBuf), "%s %.2u-%s-%u W%.2u", snprintf(DateBuf, sizeof(DateBuf), "%s %.2u-%s-%u W%.2u",
dayShortStrLoc(weekday(Loc_t)), day(Loc_t), monthShortStrLoc(month(Loc_t)), year(Loc_t), ISOWeekNumber(Loc_t)); dayShortStrLoc(weekday(Loc_t)), day(Loc_t), monthShortStrLoc(month(Loc_t)), year(Loc_t), ISOWeekNumber(Loc_t));
Serial.print("Date long: "); // debug //Serial.print("Date long: "); // debug
Serial.println(DateBuf); // debug //Serial.println(DateBuf); // debug
} }
} }
void PrintHour() { // do if new hour void PrintHour() { // do if new hour
if (NewHour) { // if (NewHour) { //
NewHour = false; // remove flag, do only once every hour NewHour = false; // remove flag, do only once every hour
Serial.println("bring out the Cuckoo ;-)"); // debug //Serial.println("bring out the Cuckoo ;-)"); // debug
} }
} }

View File

@@ -12,8 +12,8 @@
#include "RTC_com.h" // to set the RTC #include "RTC_com.h" // to set the RTC
#define cfg_pin_GPS_PPS 2; #define cfg_pin_GPS_PPS 2;
#define cfg_pin_GPS_Rx 4; //#define cfg_pin_GPS_Rx 4;
#define cfg_pin_GPS_Tx 5; //#define cfg_pin_GPS_Tx 5;
// add the static modifier to limit visibility of these variables to just this file // add the static modifier to limit visibility of these variables to just this file
static byte GPS_PPS_PIN = cfg_pin_GPS_PPS; // Pin 2 = NANO INT0, GPS PPS interrupt signal on this Pin static byte GPS_PPS_PIN = cfg_pin_GPS_PPS; // Pin 2 = NANO INT0, GPS PPS interrupt signal on this Pin
@@ -25,17 +25,19 @@ volatile bool GPS_sec = false; // flag for GPS-PPS
// set interrupt flag // set interrupt flag
void gps_interrupt() { void gps_interrupt() {
Serial.println("DEBUG[INT] GPS interrupt"); //Serial.print("DEBUG[INT] GPS interrupt "); Serial.println(micros());
GPS_sec = true; GPS_sec = true;
} }
NMEAGPS gps; // This parses the GPS characters NMEAGPS gps; // This parses the GPS characters
gps_fix fix; // This holds on to the latest values gps_fix fix; // This holds on to the latest values
//#include <GPSport.h> // use only for soft-serial
#include <NeoSWSerial.h> #include <AltSoftSerial.h>
NeoSWSerial gpsPort(4, 5); #include <GPSport.h> // use only for soft-serial
//#define gpsPort Serial //#define gpsPort Serial
#define GPS_PORT_NAME "NeoSWSerial(4, 5)" //#define GPS_PORT_NAME "Serial"
#define GPS_PORT_NAME "AltSoftSerial"
#define DEBUG_PORT Serial #define DEBUG_PORT Serial
/***** Notice ******************************************** /***** Notice ********************************************
@@ -64,12 +66,12 @@ NeoSWSerial gpsPort(4, 5);
const long POSIX_Y2K_offset = 946684800; // = 10957 days = 30 years, NeoTime (GPS) & TimeLib (RTC) library use different Epoch year, 2000 & 1970 const long POSIX_Y2K_offset = 946684800; // = 10957 days = 30 years, NeoTime (GPS) & TimeLib (RTC) library use different Epoch year, 2000 & 1970
const long offset_28y = 883612800; // = 10227 days = 28 years, simple test for 2038 bug const long offset_28y = 883612800; // = 10227 days = 28 years, simple test for 2038 bug
const long offset_26w = 15724800; // = 182 days = 26 weeks, simple test for timezone const long offset_26w = 15724800; // = 182 days = 26 weeks, simple test for timezone
const long offset_135 = 123456; // = 135 seconds, simple test for timezone
void GPS_setup() { void GPS_setup() {
pinMode(GPS_PPS_PIN, INPUT_PULLUP); // enable pullup on interrupt pin pinMode(GPS_PPS_PIN, INPUT_PULLUP); // enable pullup on interrupt pin
attachInterrupt(digitalPinToInterrupt(GPS_PPS_PIN), gps_interrupt, RISING); // 100ms HIGH at start of second attachInterrupt(digitalPinToInterrupt(GPS_PPS_PIN), gps_interrupt, RISING); // 100ms HIGH at start of second
GPS_sec = false; GPS_sec = false;
gpsPort.begin(9600); // set PC to same baudrate for debug messages gpsPort.begin(19200); // set PC to same baudrate for debug messages
GPS_ON(); GPS_ON();
} }
@@ -88,6 +90,7 @@ void GPS_PPS() { // do something on the flip of the GPS second
if (gps_seconds_t != 0) { // do only if value is set if (gps_seconds_t != 0) { // do only if value is set
// gps_seconds_t += offset_28y; // debug & testing only! // gps_seconds_t += offset_28y; // debug & testing only!
// gps_seconds_t += offset_26w; // debug & testing only! // gps_seconds_t += offset_26w; // debug & testing only!
// gps_seconds_t += offset_135;
SetRTC(gps_seconds_t); // sync RTC with GPS SetRTC(gps_seconds_t); // sync RTC with GPS
GPS_OFF(); GPS_OFF();
} }

View File

@@ -41,8 +41,8 @@
// Central European Time Zone, directive 2000/84/EC [Bruxelles, Paris, Madrid, Roma, Beograd, Warszawa, Stockholm, Berlin] // Central European Time Zone, directive 2000/84/EC [Bruxelles, Paris, Madrid, Roma, Beograd, Warszawa, Stockholm, Berlin]
// All 3 European timezones change at the same time: 01:00 UTC // All 3 European timezones change at the same time: 01:00 UTC
TimeChangeRule mySTD = { "CET ", Last, Sun, Oct, 3, 60 }; // change to UTC + 1 hours // TimeChangeRule mySTD = { "CET ", Last, Sun, Oct, 3, 60 }; // change to UTC + 1 hours
TimeChangeRule myDST = { "CEST", Last, Sun, Mar, 2, 120 }; // change to UTC + 2 hours // TimeChangeRule myDST = { "CEST", Last, Sun, Mar, 2, 120 }; // change to UTC + 2 hours
// Eastern European Time Zone [Helsinki, Rīga, Kyiv, Αθήνα] // Eastern European Time Zone [Helsinki, Rīga, Kyiv, Αθήνα]
//TimeChangeRule mySTD = { "EET ", Last, Sun, Oct, 4, 120 }; // change to UTC + 2 hours //TimeChangeRule mySTD = { "EET ", Last, Sun, Oct, 4, 120 }; // change to UTC + 2 hours
@@ -53,8 +53,8 @@ TimeChangeRule myDST = { "CEST", Last, Sun, Mar, 2, 120 }; // change to UTC + 2
//TimeChangeRule myDST = { "AEDT", First, Sun, Oct, 2, 660 }; // change to UTC + 11 hours //TimeChangeRule myDST = { "AEDT", First, Sun, Oct, 2, 660 }; // change to UTC + 11 hours
// Москва Standard Time (MSK, does not observe DST) // Москва Standard Time (MSK, does not observe DST)
//TimeChangeRule mySTD = {"MSK ", Last, Sun, Oct, 1, 180}; // allways UTC + 3 hours TimeChangeRule mySTD = {"MSK ", Last, Sun, Oct, 1, 180}; // allways UTC + 3 hours
//TimeChangeRule myDST = {"MSK ", Last, Sun, Mar, 1, 180}; // allways UTC + 3 hours TimeChangeRule myDST = {"MSK ", Last, Sun, Mar, 1, 180}; // allways UTC + 3 hours
// Universal Time Coordinated [UTC] // Universal Time Coordinated [UTC]
//TimeChangeRule mySTD = {"UTC ", Last, Sun, Oct, 1, 0}; //TimeChangeRule mySTD = {"UTC ", Last, Sun, Oct, 1, 0};

View File

@@ -26,7 +26,7 @@ volatile bool RTC_sec = false; // flag for PseudoPPS
static unsigned long RTCMillis; // blinking timer static unsigned long RTCMillis; // blinking timer
void rtc_interrupt() { void rtc_interrupt() {
Serial.println("DEBUG[INT] RTC interrupt"); //Serial.print("DEBUG[INT] RTC interrupt "); Serial.println(micros());
RTCMillis = millis(); RTCMillis = millis();
RTC_sec = true; RTC_sec = true;
} }