I am working on a small home project 'glucose meter' via non invasive techniques. I am using four sensors like RGB color sensor, two multi-wavelength photo diodes (A & B) and temperature sensor (K-Type Thermocouple). I am using Multi Regression algorithm to estimate Glucose level in human body by calculate all four readings from sensors.
I am using ESP32 and I am saving all my sensors data in a CSV file (or text) after taking more than 20 calibration data from my family and friends. I can read this file after writing but I am facing a problem in reading all calibration data from this text/CSV file in the following particular manner.
Y,Sensor1,Sensor2,Sensor3,Sensor4
92,103,25,65,9875
91,104,26,62,9805
105,92,30,66,9600
150,60,40,75,9233
...,...,...,.....
Above pattern indicates 'Y' values (Blood Sugar value mg/dl) and corresponding sensors value on that time. I am facing problem in reading these object like:
Y1 = 92, S1 = 103, S2 = 25, S3 = 65, S4 = 9875
Y2 = 91, S1 = 104, S2 = 26, S3 = 62, S4 = 9805
....................AND so forth..............
Y1000 = XX, S1 = XX, S2 = XX, S3 = XX, S4 = XX
Can any one help me how would I read and categorize each sensor values from the text/CSV File?
Thanks.
2 Answers 2
Let's say you want to read this line from the file.
92,103,25,65,9875
code is
String one_line_data = file.readStringUntill("\n");
int y,s1, s2, s3, s4;
sscanf(one_line_data.c_str(), "%d,%d,%d,%d,%d", &y, &s1, &s2, &s3, &s4);
this way to read the one line of data from file you can expand to multiple line based on application.
Function file.parseInt(), will skip non numeric characters and then parse the number stopping on non numering character. So you need only call file.parseInt() for every value in row, process the data and then loop to next row.
Y1 = file.parseInt();
S1 = file.parseInt();
S2 = file.parseInt();
S3 = file.parseInt();
S4 = file.parseInt();
Explore related questions
See similar questions with these tags.