Good afternoon!
I am an undergraduate student pursuing a Chemistry degree and I am working with a professor to program and deploy Dissolved Oxygen (D.O.) sensors.
Currently, Both temperature and the D.O. sensor have been incorporated. Right now I am trying to add date and time so we can record changes in levels of oxygen over time. Although the time intervals between each measurement are accurate, the date keeps showing up 01/01/1970. The time library was added and I am using an epoch converter to calculate the number of seconds from 1970 to the date.
As a side note, if the time serial does not work, would it be a good idea to use a chip such as DS3231 to measure the time instead of trying to set it up in the same code?
Please find the code below, I only included the section of time as the whole code exceeds the allowed length. Thank you in advance for your time and help.
Sebastian Garcia-Medina
#include <SoftwareSerial.h> //we have to include the SoftwareSerial library, or else we can't use it.
#define rx 2 //define what pin rx is going to be.
#define tx 3 //define what pin Tx is going to be.
#include <Time.h>
#define TIME_HEADER "T" // Header tag for serial time sync message
#define TIME_REQUEST 7 // ASCII bell character requests a time sync message
//----------------------------------------------------------------------------------------------------------------------------------------
void digitalClockDisplay(){
Serial.print("x ");
Serial.print(month());
Serial.print("/");
Serial.print(day());
Serial.print("/");
Serial.print(year());
Serial.print(" ");
Serial.print(hour());
printDigits(minute());
printDigits(second());
}
//----------------------------------------------------------------------------------------------------------------------------------------
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);
}
//----------------------------------------------------------------------------------------------------------------------------------------
void processSyncMessage() {
unsigned long pctime;
const unsigned long DEFAULT_TIME = 1451935763; // Jan 1 2013
if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013)
setTime(pctime); // Sync Arduino clock to the time received on the serial port
}
}
}
//----------------------------------------------------------------------------------------------------------------------------------------
time_t requestSync(){
Serial.write(TIME_REQUEST);
return 0; // the time will be sent later in response to serial mesg
}