Hi
Im trying to make a simple datalogger using my Datalogger shield with RTC module V1.0 on top of my Arduino Uno. I have made a simple code which i tought would continously log data to my SD card. But i have an issues. I have a SD card adapter with a Micro SDHC FAT 32 card inside.
-Once i have it open im able to send information and close the file. Then the program cannot open it again. Unless I reupload the program to the Arduino. Then it will be able to send the information once, and not be able to open again.
The program is just a simple variable that changes "Voltage" that i want to log repeatedly. I have seen examples where you always open the file, write, and then close it. So i dont see where the issue is.
Would appreciate it alot if anyone could help me. I have a feeling its a quick fix.
#include <SD.h>
#include <SPI.h>
int Voltage=500; //Defined simulated variable
int chipSelect = 10; //cs or the save select pin from the sd shield is connected to 10.
File (mySensorData); // Creating my file
void setup() {
Serial.begin(9600);
SD.begin(chipSelect);
}
void loop() {
mySensorData=SD.open("HI.txt",FILE_WRITE); //Opening the "HI" file to write
if (!mySensorData) {
Serial.println("Could not open file.");} // Sending this line if i cannot open the file
mySensorData.println(Voltage);//Printing the Voltage variable to the SD card
mySensorData.println("Hello World");
mySensorData.close(); // Closing the file im writing to
Serial.println(Voltage); //Serial printing the variable to keep track
Voltage=Voltage+10; //Adding 10 to the variable to see if the variable changes
delay(1000);
}
I have slowed it down now using both a while(!mySensorData) line where it waits until i have the file open. And a delay at the end of my loop for 1 sec. Still im only able to log the data once. Is there anything im missing here?
Hi
I believe that is how its working now, or should be atleast.
I've moddified the code abit to make sure it has enough time to open the file.
Still it wont open again after the first cycle. I've seen other people opening and closing the file in the loop.
It seems like like the FILE_APPEND was not in scope and therefore couldn't use it.
But i tried using mySensorData.seek(EOF) and i found something interesting.
When running the code below i got back that it found it the first cycle. And i managed to log to the file. The second cycle it also found it, but this time i couldn't log to the file. The rest of the cycles it couldn't find the file and i still couldn't log. Not really sure what to do next. Thank you for your suggestion.
I was using my arduino uno with the Data logging shield v1.0. When i swapped the shield for an ethernet W5100 shield with a micro SD port. It worked right away with the same code.
So in conclusion the first shield was broken i think.
Sorry for bad phrasing.