storing numbers larger than 255 in SD card (Arduino YUN)

Hey guys!

I am trying to store a number larger than 255 (ex. -24818) in my microSD card which is in the Arduino Yun. I am using the Bridge Library and the FileSystem library to read and write my numbers into a file.

If anyone wants to know what I am doing, I am storing an array of 64 numbers (which are larger than 255) into a file on the Arduino Yun's microSD.


Can you show us your sketch, or is there an example sketch I could try ? Do you want to write the data as readable text or as a binary number ?

Define a union of an array of say 16 bit ints, and a char array which is the total size of the array of ints. Then loop through the array one char at a time, reading or writing to the file. Here’s how I did it for an array of 6 ints that I read and write from/to EEPROM. You need to modify it to read/write to an open, named file.

union compassCalVals
 int16_t v[6];
 unsigned char uc[6 * sizeof(int16_t)];
} cv;


 for (size_t i = 0; i < sizeof(cv); i++)
 cv.uc[i] = + calBaseAddress);

I access each of the 6 ints in the union as cv.v[0], cv.v[1], …