Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

OpenAccess RTC functions

OpenAccess RTC functions

These declares are for the i2c eeprom and realtime clock:

//I2C stuff
#include <Wire.h> // Needed for I2C Connection to the DS1307 date/time chip
#include <DS1307.h> // DS1307 RTC Clock/Date/Time chip library
#include <E24C1024.h> // Needed for the onboard EEPROM
uint8_t second, minute, hour, dayOfWeek, dayOfMonth, month, year; // Global RTC clock variables. Can be set using DS1307.getDate function.
DS1307 ; // RTC Instance

Those are used in their own functions, this one takes commands from the serial and does RTC things with them:

// uses RTC
//format: RTC;<0=write, 1=read>;<second, 0-59 (write only)>;<minute,0-59 (write only)>;<hour, 1-23 (write only)>;<dayOfWeek, 1-7 (write only)>;<dayOfMonth, 1-28/29/30/31 (write only)>;<month, 1-12 (write only)>;<year, 0-99 (write only)>
void SCmd_rtc()
{
char *arg;
//Serial.println(“rtc”);
arg = SCmd.next();
if (arg != NULL)
{
if(atoi(arg))
{
//Serial.println(“read rtc”);
//logDate();
Serial.println(logDate());//should be logging?
}
else
{
//Serial.println(“write rtc”);
arg = SCmd.next();
if (arg != NULL)
{
second=atoi(arg);
}
else
{
//Serial.println(“No second argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
minute=atoi(arg);
}
else
{
//Serial.println(“No minute argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
hour=atoi(arg);
}
else
{
//Serial.println(“No hour argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
dayOfWeek=atoi(arg);
}
else
{
//Serial.println(“No dow argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
dayOfMonth=atoi(arg);
}
else
{
//Serial.println(“No dom argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
month=atoi(arg);
}
else
{
//Serial.println(“No month argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
year=atoi(arg);
}
else
{
//Serial.println(“No year argument”);
}
ds1307.setDateDs1307(second,minute,hour,dayOfWeek,dayOfMonth,month,year);
/* Sets the date/time (needed once at commissioning)
uint8_t second // 0-59
uint8_t minute // 0-59
uint8_t hour // 1-23
uint8_t dayOfWeek // 1-7
uint8_t dayOfMonth // 1-28/29/30/31
uint8_t month // 1-12
uint8_t year // 0-99
*/
}
}
else
{
//Serial.println(“No arguments”);
}
}

This next one returns the date in a print/logable form and is used all over the code to timestamp things:

String logDate()
{
String date;
ds1307.getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
date+=”20″;//hack
date+=year;
date+=”-“;
if(month < 10)
{
date+=”0″;
}
date+=month;
date+=”-“;
if(dayOfMonth < 10)
{
date+=”0″;
}
date+=dayOfMonth;
date+=’T’;
if(hour < 10)
{
date+=”0″;
}
date+=hour;
date+=”:”;
if(minute < 10)
{
date+=”0″;
}
date+=minute;
date+=”:”;
if(second < 10)
{
date+=”0″;
}
date+=second;
date+=” “;
switch(dayOfWeek){
case 1:
{
date+=”SUN”;
break;
}
case 2:
{
date+=”MON”;
break;
}
case 3:
{
date+=”TUE”;
break;
}
case 4:
{
date+=”WED”;
break;
}
case 5:
{
date+=”THU”;
break;
}
case 6:
{
date+=”FRI”;
break;
}
case 7:
{
date+=”SAT”;
break;
}
}
return date;
}

That’s it, that’s what the RTC is for: timestamps on things. This is part of the greater OpenAccess project.

Read more Here

Pinned onto

Related Pins

Arduino Stopwatch
Arduino Stopwatch
App note: General overview of IR transmission in free ambient
App note: General overview of IR transmission in free ambient
Sonicare toothbrush teardown: microcontroller, H bridge, and inductive charging
Sonicare toothbrush teardown: microcontroller, H bridge, and inductive charging
App note: Using Vishay infrared receivers in a Wi-Fi environment
App note: Using Vishay infrared receivers in a Wi-Fi environment
Skill Sunday: Uploading to your Arduino via a Network
Skill Sunday: Uploading to your Arduino via a Network
One Phase Power Meter
One Phase Power Meter
WiFi Toilet Vacancy Sensor
WiFi Toilet Vacancy Sensor
HAL 9000 reimagined as a useless machine
HAL 9000 reimagined as a useless machine
Using the XMEGA Clock System
Using the XMEGA Clock System
An Arduino VU meter for classrooms
An Arduino VU meter for classrooms
DIY Calculator
DIY Calculator
Build your own robotic vacuum from scratch
Build your own robotic vacuum from scratch
An animatronic talking takeout container
An animatronic talking takeout container
Restoring a Xerox Alto day 7: experiments with disk and Ethernet emulators
Restoring a Xerox Alto day 7: experiments with disk and Ethernet emulators
IDE 1.6.12 released with Sierra support and more
IDE 1.6.12 released with Sierra support and more
IoT Propane Tank
IoT Propane Tank
Industry Standard Single-Ended Current Mode PWM Controller
Industry Standard Single-Ended Current Mode PWM Controller
Wifi enabled 8×64  pixel  LED  matrix display
Wifi enabled 8×64 pixel LED matrix display
Arduino Disco Lights
Arduino Disco Lights
PIXIE is an Arduino-based NeoPixel watch
PIXIE is an Arduino-based NeoPixel watch

Top


Shares