OK so I am trying to log voltage and amperage to a SD card. I originally logged this data only with a sample number every five seconds. The code worked great however I really wanted to have the actual time of day logged. The first setup used an uno with an Ethernet shield. Since I couldn't use the DS1307 on SPI and the SD card on the Ethernet shield at the same time I purchased a stand alone SD card writer and decided to re-write my code. I got all the separate pieces working individually but as I try and put it all together I have run into an issue when I try and save the time to an int. Below is my code:
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC; //DS1307 Real Time Clock
// int voltage_pin = 2;
// int amperage_pin = 1;
void setup()
{
Serial.begin(57600); //Start serial comms
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT Running!");
}
}
void loop()
{
DateTime now = RTC.now();
Serial.println(now.year(), DEC);
int tyear = (now.year);
Serial.println(tyear);
delay(5000);
}
Basically I hope to take the int and write it to a string and save it to the log file. I added the serial println as a little debugging.
I open the serial monitor and get the following
2012
10
Basically I can see that the RTC is hooked up correctly and it shows the right year. What I cant figure out is how to store it to an int. I have tried all kinds of things and I all ways get 10.
I would really appreciate any help.