Hey everyone, Im doing a small datalogger with the adxl377 but when trying to log data to the sd card it
s no good.
Here is the sketch I`m using any sugestions or help are welcome and thanks
#include <SD.h>
const int CS = 10;
File logfile;
long idd = 0;
long ids = 0;
long idm = 0;
long idh = 0;
int set = 1;
void error(char *str)
{
Serial.print("error");
Serial.println(str);
}
void setup() {
// open a serial connection
Serial.begin(115200);
pinMode(CS, OUTPUT);
if(!SD.begin(CS))
{
Serial.println("Card Failure");
return;
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.TSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
}
if (logfile) {
logfile.print("Tiempo");
logfile.print("\t");
logfile.print("X");
logfile.print("\t");
logfile.print("Y");
logfile.print("\t");
logfile.println("Z");
break;
}
}
Serial.print("Logging to: ");
Serial.println(filename);
}
void loop() {
if (set == 1) {
ids = ids + 1;
}
if (ids > 59) {
ids = 0;
idm = idm + 1;
}
if (idm > 59) {
idm = 0;
idh = idh + 1;
}
logfile.print(idh);
logfile.print(idm);
logfile.print(ids);
logfile.print("\t");
logfile.print(analogRead(A0));
logfile.print(analogRead(A1));
logfile.println(analogRead(A2));
// change the resolution to 16 bits and read A0
Serial.print("x :");
Serial.print(analogRead(A0));
Serial.print("y :");
Serial.print(analogRead(A1));
Serial.print("z :");
Serial.println(analogRead(A2));
delay(1000);
}
The Sd card Initialize ok but no datas transfered to it, the sensor works correctly and via the serial monitor I get data but no logging to the sd card