Hello all
I am rebuilding my saltwater aquarium system controlled by an arduino after a move to a new home.
During the move i lost the flash drive i had my working sketch stored on.Now i am trying to rebuild the sketch from what files i can find on the internet that i used to get it working.Right now i am working on the lcd display of time and date.
The sketch i used is from the time library i have inserted the name of the system "The Coleman Reef" in the first row of the LCD, "Time" followed by the numeric display of the current time on the second row of the LCD, and "Date" followed by the numeric display of the current date on the third row of the LCD. These items all display correctly on the LCD except for the inclusion of
: then the minute of the hour when the TimeRTCSet sketch was uploaded:
on the first line after the aquarium name.
This is what displays
The Coleman Reef:42:
and :the current minute after the current date on the third line
This is what displays
Date 8/27/2016:the current minute:
I have looked for my mistake but have yet to find it if someone has the time to look at the sketch i am using and give me a hint to what and where i need to look to cure this problem it would be greatly appreciated.
Below is the sketch code
/*
* TimeRTCSet.pde
* example code illustrating Time library with Real Time Clock.
*
* RTC clock is set in response to serial port time message
* A Processing example sketch to set the time is inclided in the download
*/
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal_I2C.h>
//LCD definitions
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE); // 20x4 character lcd settings.
void setup() {
Serial.begin(9600);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
lcd.begin(20,4);
lcd.setCursor(0,0);
lcd.print("The Coleman Reef");
}
void loop()
{
if(Serial.available())
{
time_t t = processSyncMessage();
if(t >0)
{
RTC.set(t); // set the RTC and the system time to the received value
setTime(t);
}
}
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
lcd.setCursor(0,1);
lcd.print("Time");
lcd.print(" ");
lcd.print(hour());
printDigits(minute());
printDigits(second());
lcd.setCursor(0,2);
lcd.print("Date");
lcd.print(" ");
lcd.print(month());
lcd.print(" /");
lcd.print(day());
lcd.print("/ ");
lcd.print(year());
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}
/* code to process time sync messages from the serial port */
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 'T' // Header tag for serial time sync message
time_t processSyncMessage() {
// return the time if a valid sync message is received on the serial port.
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
c = Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
return pctime;
}
}
return 0;
}
Thanks for any help
James