I am trying to create a header for my CSV file before I start logging data. My data logs later when I want it to but when I attempt to open the file here and set the header it does not work. Can anyone see my mistake?
void setup() {
pinMode(programpin, OUTPUT);
Wire.begin();
lcd.begin(16, 2); // initiate LCD
// initialize serial communication at 9600 bits per second
Serial.begin(9600); // baud rate for computer serial communication
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
pinMode(chipSelect, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
if (dataFile) {
File dataFile = SD.open(filename);
dataFile.println("Event,Time,Date");
dataFile.close();
}
else
{
Serial.println("Couldn't open log file");
return;
}
RTC.begin();
if (! RTC.isrunning()) {
lcd.print("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
// uncomment it & upload to set the time, date and start run the RTC!
RTC.adjust(DateTime(__DATE__, __TIME__));
}
clearPrintTitle();
}
The program compiles and works. Later a loop is called that opens the file logs data and closes. that works it opens logs closes but the header in setup doesn't.
The code is exactly the same for the two I just figured in the set up it'll only call once so it won't make numerous lines of the header where as the loop based writing to the SD will do it over and over.
What do you see, if anything, if you Serial.println() the data ?
How about printing a character, say ">", before the data on the LCD. Do you see the ">" ?
How many rows of data and of what length are in the files ? There is not much room on the average LCD but we cannot tell how many rows and columns it has from the code snippet that you have posted.
I thought maybe what I could create two files and then call both to be read but set the cursor in between calling each one. That way it would display both of them. If I succeed I will pass this information on.