TMP036 on DUE loss of accuracy on long delays

HI,

I'm running a basic sketch where I'm reading the temp for an TMP036. With my UNO I can set delay(15000) and it returns the proper value loop after loop.

When I uplaod the sketch to my DUE and adapt it to a 3.3v read on my analogue pin, the board reads the first loop correctly and then after 15000 milli secs the second and follwing loops read an analogue pin voltage much lower than it should.

Here's the sketch with no delay;

int sensorPin = 2;
float sensorValue,temperature,voltage;

void setup() {
  Serial.begin(115200);
  }
  
void loop() {
  sensorValue = analogRead(sensorPin);
  Serial.print("Sensor Raw value: ");
  Serial.print(sensorValue);
  voltage = (sensorValue * 3.3) / 1024.0;
  Serial.print(" Voltage at 3.3v: ");
  Serial.print(voltage);
  temperature = (voltage - 0.5) * 100;
  Serial.print(" Temperature Arduino monitor: ");
  Serial.println(temperature);
}

Monitor reading with no delay

Sensor Raw value: 235.00 Voltage at 3.3v: 0.76 Temperature Arduino monitor: 25.73
Sensor Raw value: 234.00 Voltage at 3.3v: 0.75 Temperature Arduino monitor: 25.41
Sensor Raw value: 234.00 Voltage at 3.3v: 0.75 Temperature Arduino monitor: 25.41
Sensor Raw value: 234.00 Voltage at 3.3v: 0.75 Temperature Arduino monitor: 25.41
Sensor Raw value: 234.00 Voltage at 3.3v: 0.75 Temperature Arduino monitor: 25.41
Sensor Raw value: 235.00 Voltage at 3.3v: 0.76 Temperature Arduino monitor: 25.73
Sensor Raw value: 234.00 Voltage at 3.3v: 0.75 Temperature Arduino monitor: 25.41
Sensor Raw value: 235.00 Voltage at 3.3v: 0.76 Temperature Arduino monitor: 25.73
Sensor Raw value: 235.00 Voltage at 3.3v: 0.76 Temperature Arduino monitor: 25.73

And now the sketch and monitor reading with a Delay(15000);

[code]
int sensorPin = 2;
float sensorValue,temperature,voltage;

void setup() {
  Serial.begin(115200);
  }
  
void loop() {
  sensorValue = analogRead(sensorPin);
  Serial.print("Sensor Raw value: ");
  Serial.print(sensorValue);
  voltage = (sensorValue * 3.3) / 1024.0;
  Serial.print(" Voltage at 3.3v: ");
  Serial.print(voltage);
  temperature = (voltage - 0.5) * 100;
  Serial.print(" Temperature Arduino monitor: ");
  Serial.println(temperature);
  delay(15000);
}

Monitor

Sensor Raw value: 232.00 Voltage at 3.3v: 0.75 Temperature Arduino monitor: 24.77
Sensor Raw value: 71.00 Voltage at 3.3v: 0.23 Temperature Arduino monitor: -27.12
Sensor Raw value: 71.00 Voltage at 3.3v: 0.23 Temperature Arduino monitor: -27.12
Sensor Raw value: 71.00 Voltage at 3.3v: 0.23 Temperature Arduino monitor: -27.12

Any idea why the due is loosing voltage during the delay?
[/code]

Perhaps this applies to you:

Re: analogRead on DUE produces erratic results when requests are long between
(analogRead on DUE produces erratic results when requests are long between/Solved - #8 by chriskner - Arduino Due - Arduino Forum)

-Chris

Hi Chris,

Thank you for sharing: Looks very much as I'm going to parse some dummy values at initiation in order to workaround this issue.

Will post findings for those following.

Cheers,
alex

Hi,

For the sake of following up I thought Id drop a line to explain how I worked around the inaccuracies I was getting on my DUE on the second loop and the following ones. What was happening, my sensor read was accurate at the first loop and then the following ones were randomish...

The trick I found was to run a calibrate loop at the beginning of the main loop of the sketch, reading a different pin than the sensor's pin 20 times before reading the final sensor value.

void setup() {
  //setup parameters
  }

//testread function, a basic analogue read on the PIN10
void testread (void) {
		calibrate = analogRead(10);
}  
  
void loop() {
  for(int x = 0; x < 20; x++){ //read pin 10 twenty times
  testread();
  }
  sensorValue = analogRead(sensorPin); //read the value of the sensor in this case PIN2
  //the rest of your code
  delay(15000);
 }