I'm trying to do what must be a common objective: save experimental data to SD in CSV format to use in Excel. But I can't find all needed code in tutorials or help examples or StackOverflow
My code list below is long but that is because of careful comments and long variable names.
Problems are at ???, mainly the string length calculation, how to prepare data, how to append each type of datum to string.
I'm getting several data from each trial.
Data are mix of int, float, char and string.
My approach is to get all values into a string (with rounding, pad and commas) then open SD file and append the single string.
(repeat for each trial)
Examples in Learn C tutorial, from what I see, only save a hard-coded string.Data are mix of int, float, char and string.
My approach is to get all values into a string (with rounding, pad and commas) then open SD file and append the single string.
(repeat for each trial)
My code list below is long but that is because of careful comments and long variable names.
Problems are at ???, mainly the string length calculation, how to prepare data, how to append each type of datum to string.
/* StoreDataStringver22.c Goal: Concatenate experimental data to string as CSV Then append to SD file and transfer to Excel Notes: Data types = int, float, char, string Goal is the string "dataFullRecord" w/commas Data are each fixed length Unsolved issues round/truncate ints and floats to defined length Convert each type to string Concatenate */ #include "simpletools.h" // Include simple tools int main() // Main function { // Vars to hold data for each trial until written int datum1_Int; // 4 digits always (pad as needed) float datum2_Float; // 5 digits always (need pad) +1 for DP? char datum3_Char; // 1 character always char datum4_String[3]; // 3 character always // might need constant for Comma or Return // String to hold all data of one trial // ??? Size in bytes of total string // int 4 // float 5 +1 for DP? // char 1 // String[3] 3 plus +1 for terminating 0? // Commas 3 // Return added to string or auto by SD append? char dataFullRecord[17]; //no Return character // Get data from experiment - dummy values here [indent] datum1_Int = 12; // round/pad to 4 digits datum2_Float = 9.876543; // round/pad to 5 digits datum3_Char = "A"; // datum4_String[4] = "June"; //always 4 char ?+1 for terminal 0 [/indent] // Build string // how to concatenate? // how to round/pad int & float to fixed length? // how to convert int & float to string? // best way to include commas? // need Return character? // Attempt #6 error: doesn't know function strCopy strCopy(dataFullRecord[](), cstr(round(datum1_int,3)) strCopy(dataFullRecord[](), ",") strCopy(dataFullRecord[](), cstr(round(datum2_float,4)) strCopy(dataFullRecord[](), ",") strCopy(dataFullRecord[](), datum3_char) strCopy(dataFullRecord[](), ",") strCopy(dataFullRecord[](), datum4_string[]) }