Hello everyone,
I am a beginner in this field (Arduino). I have at my disposal an Arduino Mega, a RTC_DS1307, an SD card and a 2.8 TFT LCD resistiv Touch Display. I excette the examples that are in the library SD and they all have good functions. I wish I could read and write the real time on my SD card, but the code I wrote does not work.
Here is the little code I wrote. Can you help me make my Code work?
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
rtc.begin();
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
DateTime now = rtc.now();
Serial.print(rtc.now());
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.print(rtc.now());
myFile.print(",");
myFile.close(); // close the file
}
// if the file didn't open, print an error:
else {
Serial.println("error opening test.txt");
}
delay(1000);
}
I would like to write on my SD card the current time gives by the RTC DS1307 and be able to read that time too. But when I compile my code I get this error:
"exit status 1
no matching function for call to 'HardwareSerial :: print (DateTime)' ".
I would like to write on my SD card the current time gives by the RTC DS1307 and be able to read that time too. But when I compile my code I get this error:
The time is not the same as the DateTime class. The time is the hour, the minute, and the second. Most RTC libraries include methods to get the hour, minute, and second from the RTC. Without knowing where you got RTClib, we can't tell if the class(es) that it defines include those methods, or not.
Hello,
I was able to solve my previous problem. I can record the time on my SD-Card. My current problem is in reading the time record on my SD-Card. I would only like to read the last hour that my SD-Card has to record and not all the content. Indeed I created a file in my SD-card. In this file I record each time the time I press the Start button on my Display. I would like to be able to read only the last hour when I pressed the Start button and not every hour.
I would like to be able to read only the last hour when I pressed the Start button and not every hour.
Suppose the you push the button once a minute, starting at 7:35. Do you want to record only an hour's worth of data, discarding older data? Or, do you want to have separate code to read the file, and only show the last 60 minutes of data? Does that 60 minute window end now? Or does it end at the time of the last record in the file?
Clear requirements are easy to implement. Vague hand waving is hard(er) to implement.
In fact all my programming is related to a Maschine that performs thermal resistance tests on the LEDS. Pressing the Start button signals the start of the test. Each test has a specific duration and several (for example 1000 hours, 500 hours ...). All start times are saved in a file on the SD-Card. I would just like to read each time the start time of the test in court.