Hi All,
I am trying to write float numbers to an SD card in a binary format, but the SD library write() function
only supports byte, char and string formats.
Is there a simple way of converting float numbers to binary? I have tried using unions in the form below:
SdFat sd; //file system object
SdFile dataFile; //log file
void writePoint(); {
union{byte uBytes[4]; float uFloat;} dataPoint;
dataFile.open("datalog.bin", FILE_WRITE);
dataPoint.uFloat = 3.14;
dataFile.write(dataPoint.uBytes, 4);
dataFile.close();
}
For some reason this code keeps crashing. Any suggestions on a solution? Thanks!