WIP
This commit is contained in:
@@ -37,6 +37,7 @@ extern bool NewMin; // pass to main ino = minute ready to print
|
|||||||
extern bool NewHour; // pass to main ino = Hour ready to print
|
extern bool NewHour; // pass to main ino = Hour ready to print
|
||||||
extern time_t Loc_t; // pass to main ino = Local timestamp
|
extern time_t Loc_t; // pass to main ino = Local timestamp
|
||||||
|
|
||||||
|
extern volatile unsigned long tmr_SQW, tmr_PPS;
|
||||||
// call from main ino, GPS_RTC_Clock.h
|
// call from main ino, GPS_RTC_Clock.h
|
||||||
void GPS_RTC_Clock_setup();
|
void GPS_RTC_Clock_setup();
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,15 @@ LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|||||||
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
|
||||||
|
|
||||||
|
unsigned long TMR_FPS;
|
||||||
|
|
||||||
bool LCD_Simple_clock;
|
bool LCD_Simple_clock;
|
||||||
|
|
||||||
void RTCtoLCD(bool ClockType = LCD_Simple_clock) {
|
void RTCtoLCD(bool ClockType = LCD_Simple_clock) {
|
||||||
if (millis() < 2000) ClockType = true;
|
if (!NewSec && !NewMin && !NewHour) return;
|
||||||
else if (!NewSec && !NewMin && !NewHour) return;
|
|
||||||
char Clock[9];
|
char Clock[9];
|
||||||
char segment[3];
|
char segment[3];
|
||||||
|
char message[50];
|
||||||
|
|
||||||
if (ClockType) {
|
if (ClockType) {
|
||||||
snprintf(Clock, sizeof(Clock), "%.2u:%.2u:%.2u", hour(Loc_t), minute(Loc_t), second(Loc_t));
|
snprintf(Clock, sizeof(Clock), "%.2u:%.2u:%.2u", hour(Loc_t), minute(Loc_t), second(Loc_t));
|
||||||
@@ -40,16 +42,22 @@ void RTCtoLCD(bool ClockType = LCD_Simple_clock) {
|
|||||||
lcd.setCursor(6, 0);
|
lcd.setCursor(6, 0);
|
||||||
lcd.print(segment);
|
lcd.print(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NewMin) {
|
if (NewMin) {
|
||||||
snprintf(segment, sizeof(segment),"%.2u", minute(Loc_t));
|
snprintf(segment, sizeof(segment),"%.2u", minute(Loc_t));
|
||||||
lcd.setCursor(3, 0);
|
lcd.setCursor(3, 0);
|
||||||
lcd.print(segment);
|
lcd.print(segment);
|
||||||
}
|
|
||||||
if (NewHour) {
|
|
||||||
snprintf(segment, sizeof(segment),"%.2u", hour(Loc_t));
|
snprintf(segment, sizeof(segment),"%.2u", hour(Loc_t));
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
lcd.print(segment);
|
lcd.print(segment);
|
||||||
}
|
}
|
||||||
|
//Serial.print("DEBUG[RTCtoLCD] millis(): "); Serial.println(micros());
|
||||||
|
// long drift = tmr_PPS - tmr_SQW;
|
||||||
|
//Serial.println("DEBUG[RTCtoLCD] Difference PPS - SQW: " + String(drift) + "[" + String(tmr_PPS) + "]" + "[" + String(tmr_SQW) + "]");
|
||||||
|
// lcd.setCursor(15, 1);
|
||||||
|
// lcd.print((micros() - tmr_PPS < 2000000) ? "P" : "p"); // Выводим "P" или "p" на 16 позиции в зависимости от условия
|
||||||
|
// snprintf(message, sizeof(message), "micros: %d, tmr_PPS: %d", millis(), tmr_PPS);
|
||||||
|
// Serial.println(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -85,8 +93,27 @@ void loop() { // the loop function runs over and over again forever
|
|||||||
RTCtoLCD();
|
RTCtoLCD();
|
||||||
PrintSec();
|
PrintSec();
|
||||||
PrintHour();
|
PrintHour();
|
||||||
|
chkFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////
|
||||||
|
|
||||||
|
void chkFPS() {
|
||||||
|
int FPS;
|
||||||
|
if (millis() - TMR_FPS > 1000) {
|
||||||
|
Serial.println(TMR_FPS);
|
||||||
|
Serial.println(millis());
|
||||||
|
TMR_FPS = millis();
|
||||||
|
Serial.print("DEBUG[chkFPS] "); Serial.println(FPS);
|
||||||
|
FPS = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FPS++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrintSec() { // print time if new second
|
void PrintSec() { // print time if new second
|
||||||
if (NewSec) { //
|
if (NewSec) { //
|
||||||
NewSec = false; // remove flag, do only once every sec
|
NewSec = false; // remove flag, do only once every sec
|
||||||
|
|||||||
22
GPS_com.cpp
22
GPS_com.cpp
@@ -10,10 +10,11 @@
|
|||||||
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
|
#include <TimeLib.h> // https://github.com/PaulStoffregen/Time
|
||||||
#include "GPS_com.h"
|
#include "GPS_com.h"
|
||||||
#include "RTC_com.h" // to set the RTC
|
#include "RTC_com.h" // to set the RTC
|
||||||
|
#include "Serial_AdjustBaud.h" // for adjust serial port baudrate
|
||||||
|
|
||||||
#define cfg_pin_GPS_PPS 2;
|
#define cfg_pin_GPS_PPS 2
|
||||||
//#define cfg_pin_GPS_Rx 4;
|
#define cfg_pin_GPS_Rx 8
|
||||||
//#define cfg_pin_GPS_Tx 5;
|
//#define cfg_pin_GPS_Tx 9;
|
||||||
|
|
||||||
// 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
|
||||||
@@ -22,9 +23,12 @@ static int pulse_count = 0;
|
|||||||
static time_t gps_seconds_t = 0; // GPS time
|
static time_t gps_seconds_t = 0; // GPS time
|
||||||
static byte gps_sats = 0;
|
static byte gps_sats = 0;
|
||||||
volatile bool GPS_sec = false; // flag for GPS-PPS
|
volatile bool GPS_sec = false; // flag for GPS-PPS
|
||||||
|
volatile unsigned long tmr_PPS;
|
||||||
|
|
||||||
// set interrupt flag
|
// set interrupt flag
|
||||||
void gps_interrupt() {
|
void gps_interrupt() {
|
||||||
|
tmr_PPS = micros();
|
||||||
|
Serial.print("DEBUG[INT] GPS interrupt: "); Serial.println(tmr_PPS);
|
||||||
//Serial.print("DEBUG[INT] GPS interrupt "); Serial.println(micros());
|
//Serial.print("DEBUG[INT] GPS interrupt "); Serial.println(micros());
|
||||||
GPS_sec = true;
|
GPS_sec = true;
|
||||||
}
|
}
|
||||||
@@ -32,7 +36,7 @@ void gps_interrupt() {
|
|||||||
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 <AltSoftSerial.h>
|
//#include <AltSoftSerial.h>
|
||||||
#include <GPSport.h> // use only for soft-serial
|
#include <GPSport.h> // use only for soft-serial
|
||||||
//#define gpsPort Serial
|
//#define gpsPort Serial
|
||||||
//#define GPS_PORT_NAME "Serial"
|
//#define GPS_PORT_NAME "Serial"
|
||||||
@@ -67,11 +71,18 @@ const long POSIX_Y2K_offset = 946684800; // = 10957 days = 30 years, NeoTime (G
|
|||||||
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
|
const long offset_135 = 123456; // = 135 seconds, simple test for timezone
|
||||||
|
const char baud19200 [] PROGMEM = "PUBX,41,1,3,3,19200,0";
|
||||||
|
|
||||||
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(19200); // set PC to same baudrate for debug messages
|
gpsPort.begin(9600); // set PC to same baudrate for debug messages
|
||||||
|
gps.send_P(&gpsPort, (const __FlashStringHelper *) baud19200);
|
||||||
|
gpsPort.flush();
|
||||||
|
delay(100);
|
||||||
|
gpsPort.end();
|
||||||
|
gpsPort.begin(19200);
|
||||||
GPS_ON();
|
GPS_ON();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +102,7 @@ void GPS_PPS() { // do something on the flip of the GPS second
|
|||||||
// 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;
|
// gps_seconds_t += offset_135;
|
||||||
|
Serial.println("DEBUG[GPS_PPS] difference PPS - SQW: " + String(tmr_PPS - tmr_SQW));
|
||||||
SetRTC(gps_seconds_t); // sync RTC with GPS
|
SetRTC(gps_seconds_t); // sync RTC with GPS
|
||||||
GPS_OFF();
|
GPS_OFF();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,10 @@ bool SyncErr = true;
|
|||||||
DS3232RTC myRTC(0x68); // cfg_
|
DS3232RTC myRTC(0x68); // cfg_
|
||||||
volatile bool RTC_sec = false; // flag for PseudoPPS
|
volatile bool RTC_sec = false; // flag for PseudoPPS
|
||||||
static unsigned long RTCMillis; // blinking timer
|
static unsigned long RTCMillis; // blinking timer
|
||||||
|
volatile unsigned long tmr_SQW;
|
||||||
|
|
||||||
void rtc_interrupt() {
|
void rtc_interrupt() {
|
||||||
|
tmr_SQW = micros();
|
||||||
//Serial.print("DEBUG[INT] RTC interrupt "); Serial.println(micros());
|
//Serial.print("DEBUG[INT] RTC interrupt "); Serial.println(micros());
|
||||||
RTCMillis = millis();
|
RTCMillis = millis();
|
||||||
RTC_sec = true;
|
RTC_sec = true;
|
||||||
|
|||||||
49
Serial_AdjustBaud.h
Normal file
49
Serial_AdjustBaud.h
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Функция для вычисления и возврата скорости передачи данных (baud rate) на основе полученного входного пина.
|
||||||
|
*
|
||||||
|
* @param recpin входной пин для определения скорости передачи данных
|
||||||
|
*
|
||||||
|
* @return рассчитанная скорость передачи данных на основе измеренной ширины нулевого бита
|
||||||
|
*/
|
||||||
|
|
||||||
|
long detRate(int recpin){
|
||||||
|
long baud, x, rate = 10000;
|
||||||
|
|
||||||
|
// Цикл для измерения ширины нулевого бита
|
||||||
|
for (int i = 0; i < 15; i++){
|
||||||
|
// Ожидание начала низкого бита
|
||||||
|
while(digitalRead(recpin) == 1)
|
||||||
|
x = pulseIn(recpin, LOW); // Измерение ширины следующего нулевого бита
|
||||||
|
rate = x < rate ? x : rate; // Обновление минимальной ширины нулевого бита
|
||||||
|
}
|
||||||
|
|
||||||
|
// Определение скорости передачи данных на основе измеренной ширины нулевого бита
|
||||||
|
if (rate < 12)
|
||||||
|
baud = 115200;
|
||||||
|
else if (rate < 20)
|
||||||
|
baud = 57600;
|
||||||
|
else if (rate < 29)
|
||||||
|
baud = 38400;
|
||||||
|
else if (rate < 40)
|
||||||
|
baud = 28800;
|
||||||
|
else if (rate < 60)
|
||||||
|
baud = 19200;
|
||||||
|
else if (rate < 80)
|
||||||
|
baud = 14400;
|
||||||
|
else if (rate < 150)
|
||||||
|
baud = 9600;
|
||||||
|
else if (rate < 300)
|
||||||
|
baud = 4800;
|
||||||
|
else if (rate < 600)
|
||||||
|
baud = 2400;
|
||||||
|
else if (rate < 1200)
|
||||||
|
baud = 1200;
|
||||||
|
else if (rate < 2400)
|
||||||
|
baud = 600;
|
||||||
|
else if (rate < 4800)
|
||||||
|
baud = 300;
|
||||||
|
else
|
||||||
|
baud = 0;
|
||||||
|
|
||||||
|
return baud; // Возврат рассчитанной скорости передачи данных
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user