I have a two functions within a sketch. The first writes calibration values to an SD card as a csv file. The second function reads the csv file on start up. This is the code for the functions: (The entire sketch is around 3000 lines, so I'll spare you the rest of the code and defining variables. The sketch works, this is just an added feature that has a bug.)
void Read_Calibration_Values_SD() {
float CALValuesTemp[9];
File dataFile = SD.open("CAL_Values.txt");
// if the file is available, read the array data from it
if (dataFile) {
int i = 0;
while (dataFile.available() && i < 9) {
CALValuesTemp[i] = dataFile.parseInt();
i++;
}
dataFile.close();
InAirwayPressureCAL = CALValuesTemp[0]; SerialUSB.print("InAirwayPressureCAL "); SerialUSB.println(InAirwayPressureCAL);
ExpAirwayPressureCAL = CALValuesTemp[1]; SerialUSB.print("ExpAirwayPressureCAL "); SerialUSB.println(ExpAirwayPressureCAL);
GasManifoldPressureCAL = CALValuesTemp[2]; SerialUSB.print("GasManifoldPressureCAL "); SerialUSB.println(GasManifoldPressureCAL);
VoltageCAL = CALValuesTemp[3]; SerialUSB.print("VoltageCAL "); SerialUSB.println(VoltageCAL);
VTCAL = CALValuesTemp[4]; SerialUSB.print("VTCAL "); SerialUSB.println(VTCAL);
VTOrificeCAL_PC = CALValuesTemp[5]; SerialUSB.print("VTOrificeCAL_PC "); SerialUSB.println(VTOrificeCAL_PC);
VTOrificeCAL_VC = CALValuesTemp[6]; SerialUSB.print("VTOrificeCAL_VC "); SerialUSB.println(VTOrificeCAL_VC);
ExtraGasGAIN = CALValuesTemp[7]; SerialUSB.print("ExtraGasGAIN "); SerialUSB.println(ExtraGasGAIN);
}
else SerialUSB.println("No Calibration file found");
}
void Write_Calibration_Values_SD() {
myFile = SD.open("CAL_Values.txt", FILE_WRITE | O_TRUNC); // write alarm to SD card
myFile.print(InAirwayPressureCAL); myFile.print(",");
myFile.print(ExpAirwayPressureCAL); myFile.print(",");
myFile.print(GasManifoldPressureCAL); myFile.print(",");
myFile.print(VoltageCAL); myFile.print(",");
myFile.print(VTCAL); myFile.print(",");
myFile.print(VTOrificeCAL_PC); myFile.print(",");
myFile.print(VTOrificeCAL_VC); myFile.print(",");
myFile.print(ExtraGasGAIN); myFile.print(",");
myFile.close();
SerialUSB.print("Write Calibration Values SD -- ");
SerialUSB.print(InAirwayPressureCAL); SerialUSB.print(",");
SerialUSB.print(ExpAirwayPressureCAL); SerialUSB.print(",");
SerialUSB.print(GasManifoldPressureCAL); SerialUSB.print(",");
SerialUSB.print(VoltageCAL); SerialUSB.print(",");
SerialUSB.print(VTCAL); SerialUSB.print(",");
SerialUSB.print(VTOrificeCAL_PC); SerialUSB.print(",");
SerialUSB.print(VTOrificeCAL_VC); SerialUSB.print(",");
SerialUSB.println(ExtraGasGAIN);
}
The problem I'm having is that when I read the csv file every other value is 0.
This is what's being written to the SD card:
1.00,2.00,1.00,4.00,6.00,3.04,1.03,2.00,
However, this is what's being read by the SD card:
InAirwayPressureCAL 1.00
ExpAirwayPressureCAL 0.00
GasManifoldPressureCAL 2.00
VoltageCAL 0.00
VTCAL 1.00
VTOrificeCAL_PC 0.00
VTOrificeCAL_VC 4.00
ExtraGasGAIN 0.00
Notice every other value is a 0. What's the obvious thing that I'm missing?