I used this code to recall pre calibrated value from eeprom but can’t assign those value to qtr.calibrationOn.minimum.
this shows some garbage value. if i use some other variable instead, then i get correct value
void recallCalibrationValue()
{
qtr.calibrate();
for (uint8_t i = 0; i < SensorCount; i++)
{
storeMinVal[i] = EEPROM.read(addressMin[i]);
storeMinValue[i] = storeMinVal[i] * 4;
qtr.calibrationOn.minimum[i] = storeMinValue[i];
storeMaxVal[i] = EEPROM.read(addressMax[i]);
// storeMaxValue[i] = storeMaxVal[i] * 4;
qtr.calibrationOn.maximum[i] = storeMaxValue[i];
}
delay(100);
}
void printCalibrationValue()
{
for (uint8_t i = 0; i < SensorCount; i++)
{
Serial.print(qtr.calibrationOn.minimum[i]);
Serial.print(' ');
}
Serial.println();
for (uint8_t i = 0; i < SensorCount; i++)
{
Serial.print(qtr.calibrationOn.maximum[i]);
Serial.print(' ');
}
Serial.println();
}
Could you post the simplest complete program that demonstrates the problem, including your code that writes the EEPROM? Also, what Arduino or microcontroller are you using?
Thank you for your reply.
I am trying to make a line follower robot with arduino mega 2560 and qtr sensor.
I try to store calibrated value in EEPROM and then use it later so that i don’t have to calibrate each time i restart my arduino.
But when I check those values of qtr.calibrationOn.minimum and qtr.calibrationOn.maximum in serial monitor, it seems some of the values overwrite others.
here first eight values in the first line comes wrong as it repeats from second line. Heres two function I used.
void calibration()
{
qtr.setTypeAnalog();
qtr.setSensorPins((const uint8_t[]){
0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
SensorCount);
qtr.setEmitterPin(2);
delay(500);
digitalWrite(LED_BUILTIN, HIGH); // turn on Arduino's LED to indicate we are in calibration mode
for (uint16_t i = 0; i < 400; i++)
{
qtr.calibrate();
}
delay(100);
for (uint8_t i = 0; i < SensorCount; i++)
{
minValue[i] = qtr.calibrationOn.minimum[i] / 4;
maxValue[i] = qtr.calibrationOn.maximum[i] / 4;
EEPROM.update(addressMin[i], minValue[i]);
delay(10);
EEPROM.update(addressMax[i], maxValue[i]);
delay(10);
}
digitalWrite(LED_BUILTIN, LOW); // turn off Arduino's LED to indicate we are through with calibration
delay(1000);
}
void recallCalibrationValue()
{
qtr.calibrate();
for (int i = 0; i < SensorCount; i++)
{
qtr.calibrationOn.minimum[i] = EEPROM.read(addressMin[i]) * 4;
qtr.calibrationOn.maximum[i] = EEPROM.read(addressMax[i]) * 4;
}
for (int i = 0; i < SensorCount; i++)
{
Serial.print(qtr.calibrationOn.minimum[i]);
Serial.print("\t");
}
Serial.println();
for (int i = 0; i < SensorCount; i++)
{
Serial.print(qtr.calibrationOn.maximum[i]);
Serial.print("\t");
}
}
Thank you for the extra information, but there is still not enough for me to make any helpful suggestions. Could you please post the simplest complete program (e.g. a full program that would be able to be uploaded to an Arduino as-is) that demonstrates the problem?