with pleasure.
The setup is a standard setup for my different sketches. The output simply outputs a few standard values / tests. Some arduinos use software serial. Software serial does not have a buffer. When you write data to this soft serial port, the arduino blocks for a short time (until the data was written). Therefore it is sometimes interesting to check whether and how large the buffer of a serial connection is. Has nothing to do with your project.
It's very good that you've been busy with bit shifting. With the amount of data it is sensible to make an efficient memory technology. So you have less problems later.
Here is the way I have converted the data and saved:
unsigned long sensorTime = millis();
unsigned int sensor1Value = analogRead(PIN_SENSOR_1);
unsigned int sensor2Value = analogRead(PIN_SENSOR_2);
unsigned int sensor3Value = analogRead(PIN_SENSOR_3);
byte sensor1Byte1 = sensor1Value; //saves first 8 bit
byte sensor1Byte2 = sensor1Value >> 8;//shifts 8 bit to right, left bits will be zero
byte sensor2Byte1 = sensor2Value;
byte sensor2Byte2 = sensor2Value >> 8;
byte sensor3Byte1 = sensor3Value;
byte sensor3Byte2 = sensor3Value >> 8;
//fill byte block to write data efficient to sd card
byte writeBinDataBlock[6]{sensor1Byte1,sensor1Byte2,sensor2Byte1,sensor2Byte2,sensor3Byte1,sensor3Byte2};
//write data and add the number written bytes to debugFileWriteByteCount
debugFileWriteByteCount += file.write(writeBinDataBlock, sizeof(writeBinDataBlock));
U asked for the library to use for sd card's. i have testet several (all from user fat16lib).
There are many libraries that build on each other.
The SD library is almost a wrapper for the other libraries, which are rather low level.
To work quickly without spending much time, most people use the SD library. To work more effectively you should use the SdFat library. To work very effectively, you can work with the SdFatEx library. There are even libraries to work with the the FileAllocationVolume, the FileAllocationCache, ....
As you go to the LowLevel library, the more complicated the work will be, but you "can" work very efficiently.
There are also hidden class and functions to read low level sd card data. On this level you have to worry about the fragmentation of files on the sd card. ![]()
I would recommend using the SdFat library. It is sufficiently fast and you have a lot of control over the work with the sd card. And u can still work with the File class. You do not have to work with SDFile or FatFile.
Please install the SdFat Library with the library manager, search for "sdfat" its written by Bill Greiman!
I have used this as follows:
#include <SPI.h>
#include "SdFat.h"
...
const int PIN_INT_SD_CS = SDCARD_SS_PIN;//the const SDCARD_SS_PIN is only present on Arduino MKRzero with internal sd card reader! Change SDCARD_SS_PIN to ur CS Pin!
...
SdFat sd;
String fileName = "sensor.dat";
File file;
...
//Setup:
Serial.println(" - Init SD Card");
while(!sd.begin(PIN_INT_SD_CS)){ Serial.println(" failed"); delay(1000); } Serial.println(" done");//SDfat
//the while loop waits until the sd card is initialized, if u start the arduino without to insert an sd card, its waiting until u put in the sd card, checking every sec.
...
//Loop / when u start recording:
file = sd.open(fileName, O_WRITE | O_TRUNC);//ATTENTION: resets ur file to 0 bytes, take care. A previous measurement can be overwritten!!! User of ur Project could be angry. ;o)
Just a note: Think of the type of storing the bytes. U have stored ur higher bits in the first byte. I have stored the higher bits in the sec. byte. That's when the people ask for the byte order.
//Little-Endian
byte sensor1Byte1 = sensor1Value;
byte sensor1Byte2 = sensor1Value >> 8;
//Big-Endian
byte sensor1Byte1 = sensor1Value >> 8;
byte sensor1Byte2 = sensor1Value;
At the later convert back into a number this must be taken into account.
I have written a test tool for Win10 to get back the integer sensor values. its very quick and dirty but can read and convert all the data of a 24h measurement in ~20 sec. have tested it with the first 10000 sensor data:
