I've been trying to interpret the errors and alter the code accordingly only to realize that there's a couple essential commands missing. I will have to crack open my C++ book.
Code:
#include <Arduino.h>
#include <VMA430_GPS.h>
#include <DS1302.h>
#include <LiquidCrystal.h>
#include <TimeLib.h> // For time-handling functions
#include <SoftwareSerial.h>
const byte rxPin = 0;
const byte txPin = 1;
// Initialize GPS and RTC modules
const VMA430_GPS gps (SoftwareSerial 0, 1);
const DS1302 rtc (2, 3, 4); // Pins for the DS1302
const LiquidCrystal lcd (5, 6, 7, 8, 9, 10, 11); // Pins for LCD, may need revising
const int timeZone = -8; // Pacific Standard Time (PST)
bool gpsLocked = false;
time_t prevDisplay = 0;
int cyclesUntilSync = 20;
time_t dstStart = 0;
time_t dstEnd = 0;
int currentYear = 0;
void setup() {
lcd.begin(20, 2); // 20x2 LCD initialization
Serial.begin(9600); // For serial debugging
gps.begin(9600); // Initialize GPS at 9600 baud
rtc.writeProtect(false); // Allow RTC writes
rtc.halt(false); // Start the RTC
// Set an initial time (for example purposes)
Time t(2024, 1, 1, 1, 0, 0, Time::kMonday);
rtc.time(t); // Set the RTC time
setSyncProvider(timeSync); // Use GPS/RTC for syncing
setSyncInterval(180); // Sync interval
}
void loop() {
// Process GPS data
while (gps.available()) {
int c = gps.read();
gps.encode(c);
}
if (timeStatus() != timeNotSet && now() != prevDisplay) {
prevDisplay = now();
updateDST(); // Update DST based on the current date
// Display local and UTC times
displayLocalTime();
displayUTC();
delay(1000); // Update every second
}
}
void setup () {
String dayAsString(const Time::Day)
switch (day)
case Time::kSunday: return "SU";
case Time::kMonday: return "MO";
case Time::kTuesday: return "TU";
case Time::kWednesday: return "WE";
case Time::kThursday: return "TH";
case Time::kFriday: return "FR";
case Time::kSaturday: return "SA";
}
void displayLocalTime() {
time_t localT = localTime();
char buf[20];
sprintf(buf, "A%02d:%02d:%02d%s%02d-%02d-%02d", hour(localT), minute(localT), second(localT), dayAsString(localT), day(localT), month(localT), year(localT));
lcd.setCursor(0, 0); // First row
lcd.print(buf);
}
void displayUTC() {
time_t utcT = now();
char buf[20];
sprintf(buf, "u%02d:%02d:%02d%s%02d-%02d-%02d", hour(utcT), minute(utcT), second(utcT), dayAsString(utcT), day(utcT), month(utcT), year(utcT));
lcd.setCursor(0, 1); // Second row
lcd.print(buf);
}
time_t timeSync() {
tmElements_t tm;
unsigned long fixAge;
int yr;
gpsLocked = false;
gps.crack_datetime(&yr, &tm.Month, &tm.Day, &tm.Hour, &tm.dayAsString, &tm.Minute, &tm.Second, NULL, &fixAge);
if (fixAge == gps::GPS_INVALID_FIX_TIME) {
Serial.println("No GPS fix, using RTC");
return rtc ();
} else if (fixAge > 2000) {
Serial.println("GPS offline, using RTC");
return rtc ();
} else {
gpsLocked = true;
tm.Year = yr - 1970;
time_t t = makeTime(tm);
return t;
}
}
// Time adjustment for DST
time_t localTime() {
time_t t = now();
if updateDST t += SECS_PER_HOUR;
return t + timeZone * SECS_PER_HOUR;
}
Errors:
Arduino: 1.8.19 (Linux), Board: "Arduino Uno"
Warning: platform.txt from core 'Arduino AVR Boards' contains deprecated compiler.path={runtime.tools.avr-gcc.path}/bin/, automatically converted to compiler.path=/usr/bin/. Consider upgrading this core.
clock:12:38: error: expected ‘,’ or ‘...’ before numeric constant
const VMA430_GPS gps (SoftwareSerial 0, 1);
^
/home/brycow/Arduino/clock/clock.ino: In function ‘void setup()’:
/home/brycow/Arduino/clock/clock.ino:25:18: warning: passing ‘const LiquidCrystal’ as ‘this’ argument discards qualifiers [-fpermissive]
lcd.begin(20, 2); // 20x2 LCD initialization
^
In file included from /home/brycow/Arduino/clock/clock.ino:5:0:
/home/brycow/Arduino/libraries/LiquidCrystal-1.0.7/src/LiquidCrystal.h:62:8: note: in call to ‘void LiquidCrystal::begin(uint8_t, uint8_t, uint8_t)’
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
^
clock:27:7: error: request for member ‘begin’ in ‘gps’, which is of non-class type ‘const VMA430_GPS(SoftwareSerial)’
gps.begin(9600); // Initialize GPS at 9600 baud
^
/home/brycow/Arduino/clock/clock.ino:28:25: warning: passing ‘const DS1302’ as ‘this’ argument discards qualifiers [-fpermissive]
rtc.writeProtect(false); // Allow RTC writes
^
In file included from /home/brycow/Arduino/clock/clock.ino:4:0:
/home/brycow/Arduino/libraries/arduino-ds1302-master/DS1302.h:78:8: note: in call to ‘void DS1302::writeProtect(bool)’
void writeProtect(bool enable);
^
/home/brycow/Arduino/clock/clock.ino:29:17: warning: passing ‘const DS1302’ as ‘this’ argument discards qualifiers [-fpermissive]
rtc.halt(false); // Start the RTC
^
In file included from /home/brycow/Arduino/clock/clock.ino:4:0:
/home/brycow/Arduino/libraries/arduino-ds1302-master/DS1302.h:93:8: note: in call to ‘void DS1302::halt(bool)’
void halt(bool value);
^
/home/brycow/Arduino/clock/clock.ino:33:13: warning: passing ‘const DS1302’ as ‘this’ argument discards qualifiers [-fpermissive]
rtc.time(t); // Set the RTC time
^
In file included from /home/brycow/Arduino/clock/clock.ino:4:0:
/home/brycow/Arduino/libraries/arduino-ds1302-master/DS1302.h:109:8: note: in call to ‘void DS1302::time(Time)’
void time(Time t);
^
/home/brycow/Arduino/clock/clock.ino: In function ‘void loop()’:
clock:40:14: error: request for member ‘available’ in ‘gps’, which is of non-class type ‘const VMA430_GPS(SoftwareSerial)’
while (gps.available()) {
^
clock:41:17: error: request for member ‘read’ in ‘gps’, which is of non-class type ‘const VMA430_GPS(SoftwareSerial)’
int c = gps.read();
^
clock:42:9: error: request for member ‘encode’ in ‘gps’, which is of non-class type ‘const VMA430_GPS(SoftwareSerial)’
gps.encode(c);
^
clock:47:15: error: ‘updateDST’ was not declared in this scope
updateDST(); // Update DST based on the current date
^
/home/brycow/Arduino/clock/clock.ino: In function ‘void setup()’:
clock:56:6: error: redefinition of ‘void setup()’
void setup () {
^
/home/brycow/Arduino/clock/clock.ino:24:6: note: ‘void setup()’ previously defined here
void setup() {
^
clock:58:1: error: expected initializer before ‘switch’
switch (day)
^
clock:60:1: error: case label ‘kMonday’ not within a switch statement
case Time::kMonday: return "MO";
^
/home/brycow/Arduino/clock/clock.ino:60:28: warning: return-statement with a value, in function returning 'void' [-fpermissive]
case Time::kMonday: return "MO";
^
clock:61:1: error: case label ‘kTuesday’ not within a switch statement
case Time::kTuesday: return "TU";
^
/home/brycow/Arduino/clock/clock.ino:61:29: warning: return-statement with a value, in function returning 'void' [-fpermissive]
case Time::kTuesday: return "TU";
^
clock:62:1: error: case label ‘kWednesday’ not within a switch statement
case Time::kWednesday: return "WE";
^
/home/brycow/Arduino/clock/clock.ino:62:31: warning: return-statement with a value, in function returning 'void' [-fpermissive]
case Time::kWednesday: return "WE";
^
clock:63:1: error: case label ‘kThursday’ not within a switch statement
case Time::kThursday: return "TH";
^
/home/brycow/Arduino/clock/clock.ino:63:30: warning: return-statement with a value, in function returning 'void' [-fpermissive]
case Time::kThursday: return "TH";
^
clock:64:1: error: case label ‘kFriday’ not within a switch statement
case Time::kFriday: return "FR";
^
/home/brycow/Arduino/clock/clock.ino:64:28: warning: return-statement with a value, in function returning 'void' [-fpermissive]
case Time::kFriday: return "FR";
^
clock:65:1: error: case label ‘kSaturday’ not within a switch statement
case Time::kSaturday: return "SA";
^
/home/brycow/Arduino/clock/clock.ino:65:30: warning: return-statement with a value, in function returning 'void' [-fpermissive]
case Time::kSaturday: return "SA";
^
/home/brycow/Arduino/clock/clock.ino: In function ‘void displayLocalTime()’:
clock:71:115: error: ‘dayAsString’ was not declared in this scope
sprintf(buf, "A%02d:%02d:%02d%s%02d-%02d-%02d", hour(localT), minute(localT), second(localT), dayAsString(localT), day(localT), month(localT), year(localT));
^
/home/brycow/Arduino/clock/clock.ino:72:21: warning: passing ‘const LiquidCrystal’ as ‘this’ argument discards qualifiers [-fpermissive]
lcd.setCursor(0, 0); // First row
^
In file included from /home/brycow/Arduino/clock/clock.ino:5:0:
/home/brycow/Arduino/libraries/LiquidCrystal-1.0.7/src/LiquidCrystal.h:82:8: note: in call to ‘void LiquidCrystal::setCursor(uint8_t, uint8_t)’
void setCursor(uint8_t, uint8_t);
^
/home/brycow/Arduino/clock/clock.ino:73:16: warning: passing ‘const LiquidCrystal’ as ‘this’ argument discards qualifiers [-fpermissive]
lcd.print(buf);
^
In file included from /home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Stream.h:26:0,
from /home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/HardwareSerial.h:29,
from /home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h:233,
from /home/brycow/Arduino/clock/clock.ino:2:
/home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Print.h:67:12: note: in call to ‘size_t Print::print(const char*)’
size_t print(const char[]);
^
/home/brycow/Arduino/clock/clock.ino: In function ‘void displayUTC()’:
clock:79:107: error: ‘dayAsString’ was not declared in this scope
sprintf(buf, "u%02d:%02d:%02d%s%02d-%02d-%02d", hour(utcT), minute(utcT), second(utcT), dayAsString(utcT), day(utcT), month(utcT), year(utcT));
^
/home/brycow/Arduino/clock/clock.ino:80:21: warning: passing ‘const LiquidCrystal’ as ‘this’ argument discards qualifiers [-fpermissive]
lcd.setCursor(0, 1); // Second row
^
In file included from /home/brycow/Arduino/clock/clock.ino:5:0:
/home/brycow/Arduino/libraries/LiquidCrystal-1.0.7/src/LiquidCrystal.h:82:8: note: in call to ‘void LiquidCrystal::setCursor(uint8_t, uint8_t)’
void setCursor(uint8_t, uint8_t);
^
/home/brycow/Arduino/clock/clock.ino:81:16: warning: passing ‘const LiquidCrystal’ as ‘this’ argument discards qualifiers [-fpermissive]
lcd.print(buf);
^
In file included from /home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Stream.h:26:0,
from /home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/HardwareSerial.h:29,
from /home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h:233,
from /home/brycow/Arduino/clock/clock.ino:2:
/home/brycow/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Print.h:67:12: note: in call to ‘size_t Print::print(const char*)’
size_t print(const char[]);
^
/home/brycow/Arduino/clock/clock.ino: In function ‘time_t timeSync()’:
clock:90:7: error: request for member ‘crack_datetime’ in ‘gps’, which is of non-class type ‘const VMA430_GPS(SoftwareSerial)’
gps.crack_datetime(&yr, &tm.Month, &tm.Day, &tm.Hour, &tm.dayAsString, &tm.Minute, &tm.Second, NULL, &fixAge);
^
clock:90:61: error: ‘struct tmElements_t’ has no member named ‘dayAsString’
gps.crack_datetime(&yr, &tm.Month, &tm.Day, &tm.Hour, &tm.dayAsString, &tm.Minute, &tm.Second, NULL, &fixAge);
^
clock:92:17: error: ‘gps’ is not a class, namespace, or enumeration
if (fixAge == gps::GPS_INVALID_FIX_TIME) {
^
clock:94:17: error: no match for call to ‘(const DS1302) ()’
return rtc ();
^
clock:97:17: error: no match for call to ‘(const DS1302) ()’
return rtc ();
^
/home/brycow/Arduino/clock/clock.ino: In function ‘time_t localTime()’:
clock:109:6: error: expected ‘(’ before ‘updateDST’
if updateDST t += SECS_PER_HOUR;
^
exit status 1
expected ‘,’ or ‘...’ before numeric constant
=========
ugh...