Hi,
I have been ‘playing’ with datalogging and getting some results. I have tried tweaking the code but just don’t know enough yet to get it right… hoping someone might have a couple of mo’s to point me in the right direction.
The two things I am trying to achieve are:
Include the YEAR in the date (not coming out right at the mo - I think it is something to do with the buffer? - Year was not in the original code)
Change the sample time from 1 second to 5 seconds (eventually I would like to use a variable to set the sample time in seconds… or maybe its already doing this?)
Thanks for any help - I am learning… slowly
The data as output at the moment:
01/03//0, 17:05:24, 016
01/03//0, 17:05:25, 015
01/03//0, 17:05:26, 016
01/03/30, 17:05:27, 015
01/03/30, 17:05:28, 015
The Sketch:
#include "FileLogger.h"
#include "DS1307.h"
#include <WProgram.h>
#include <Wire.h>
#define Timing 0
#define Accept 1
#define Record 2
byte start[7]= { 'B','e','g','i','n',0x0D,0x0A};
byte buffer[23];
int temp;
byte ASCII[10]={'0','1','2','3','4','5','6','7','8','9'};
unsigned char result;
unsigned char state;
int time=0;
int now=0;
int oldtime=0;
void setup(void)
{
result = FileLogger::append("data.txt", start, 7);//Initial the SD Card
while(result) result = FileLogger::append("data.txt", start, 7);
RTC.stop();
RTC.set(DS1307_MIN,05); //set the minutes
RTC.set(DS1307_HR,17); //set the hours
RTC.set(DS1307_DATE,01); //set the date
RTC.set(DS1307_MTH,03); //set the month
RTC.set(DS1307_YR,10); //set the year
RTC.start();
}
void loop(void)
{
switch(state)
{
case Timing:
time=RTC.get(DS1307_SEC,true);
delay(200);
if(time!=oldtime)
{
oldtime=time;
temp=RTC.get(DS1307_DATE,false);
buffer[0]=ASCII[(temp/10)];
buffer[1]=ASCII[(temp%10)];
buffer[2]='/';
temp=RTC.get(DS1307_MTH,false);
buffer[3]=ASCII[(temp/10)];
buffer[4]=ASCII[(temp%10)];
buffer[5]='/';
temp=RTC.get(DS1307_YR,false);
buffer[6]=ASCII[(temp/10)];
buffer[7]=ASCII[(temp%10)];
buffer[8]=',';
temp=RTC.get(DS1307_HR,false);
buffer[9]=ASCII[(temp/10)];
buffer[10]=ASCII[(temp%10)];
buffer[11]=':';
temp=RTC.get(DS1307_MIN,false);
buffer[12]=ASCII[(temp/10)];
buffer[13]=ASCII[(temp%10)];
buffer[14]=':';
//temp=RTC.get(DS1307_SEC,false);
buffer[15]=ASCII[(time/10)];
buffer[16]=ASCII[(time%10)];
buffer[17]=',';
state=Accept;
}
break;
case Accept:
temp=analogRead(0);
buffer[18]=ASCII[(temp/100)];
buffer[19]=ASCII[((temp%100)/10)];
buffer[20]=ASCII[(temp%10)];
buffer[21]=0x0D;
buffer[22]=0x0A;
state=Record;
break;
case Record:
result = FileLogger::append("data.txt", buffer, 23);
if (result==0)
{
state=Timing;
}
break;
default:
state=Timing;
break;
}
}