Hi,
I've created a small datalogger that read 16bit integers from a CAN network and I want to store them as 16bit itegers using the sd.write(byte) see code below. I don't know what I'm doing wrong, but the file will not initialize. I'm greatful for any help I can get. In the code below I've tried to initialize the file in four sequences in order to save RAM.
Also, in order to save RAM memory I would like to read one integer at a time by using the SD.seek(position) and read the integer value by SD.PEEK(). Will that work?
Thanks' for your help.
//_______________________________Initialize SD card and files_________________________
void initSdCard(void){
uint16_t zeroValue = 0;
if (SD.exists(logFileName)) {
lcd.print(logFileName); lcd.print(" exists.");
delay(2000);
}
else {
lcd.print(logFileName);
lcd.print(" doesn't exist.");
// open a new file and immediately close it:
delay(1000);
lcd.print("Creating ");
lcd.print(logFileName);
lcd.print("...");
polarFile = SD.open(logFileName, FILE_WRITE);
polarFile.close();
delay(500); //_____________Wait to close file_____________
lcd.print("file created");
delay(1500);
lcd.clear();
//____________________________Write the the matrix. 72 columns (numberOfWindDirectionColumns) by 40 rows (numberOfWindSpeedRows)_____________________
//____________________________ fileFramSize = 10, used to avoid have the complete matrix in flash (limited memory)
for(uint8_t frameNo=1; frameNo < (numberOfWindSpeedRows / fileFrameSize); frameNo++){
uint16_t cellNo = 0;
Serial.print("first loop started"); //*******************
delay(500);
File polarFile = SD.open(logFileName, FILE_WRITE);
if (polarFile) {
Serial.print(logFileName); //******************
Serial.println("opened"); //********************'
for(uint8_t row=1;row < (fileFrameSize+1); row++){
Serial.println("second loop");
for(uint8_t column=1; column < (numberOfWindDirectionColumns); column++){
// polarFile.write(word(row,column),2); //row is the high byte and column is the
polarFile.write(row); // One 16 bit data consists of row (windDir) high byte and
polarFile.write(column); // column (windSpeed) low byte
cellNo++;
delay(10);
}
}
}
polarFile.close();
Serial.println("File closed");
}
lcd.print(logFileName);
lcd.print(" initiated OK");
}
}