I'm trying to use the Data Logger with an Arduino Uno to write data to an SD card along with the date.
I wrote a simple sketch to test out the code and I'm not all that good at it and I get an error as seen in the attached file. I also am including the entire sketch and would appreciate any help. I don't know if there are any other errors beyond what shown so if anyone sees any please let me know.
Thanks,
Tom
Code: Select all
//Initialise LCD display
#include <SPI.h> // Include SPI library (needed for the SD card)
#include <SD.h> // Include SD library
#include "RTClib.h" // Include RTC Library
File myFile;
//Setup Variables
int data =1;
float DateTime;
int chipSelect = 10; // chipselect pin for the SD card reader
void setup()
{
Serial.begin(9600); //Start the serial connection
// Check for SD card initialization
while (!Serial) {; // wait for serial port to connect. Needed for native USB port only
{
Serial.print("Initializing SD card...");
if (!SD.begin()) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
}
void loop()
{
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(data);
// SD Card Write
//open the file.
myFile = SD.open("RTCtest.txt", FILE_WRITE);
//write to file
if (myFile)
{
Serial.print("Writing to RTCtest.txt...");
myFile.print(now.year(), DEC);
myFile..print('/');
myFile..print(now.month(), DEC);
myFile..print('/');
myFile..print(now.day(), DEC);
myFile.l.print(" (");
myFile..print(") ");
myFile..print(now.hour(), DEC);
myFile..print(':');
myFile..print(now.minute(), DEC);
myFile..print(':');
myFile..print(now.second(), DEC);
myFile.print("Data ,");
myFile.println(data);
//close the file
myFile.close();
Serial.println("done.");
}
else
{
// if the file didn't open, print an error:
Serial.println("error opening Weather.txt file");
}
}