Pages: [1]   Go Down
Author Topic: TMP036 on DUE loss of accuracy on long delays  (Read 1776 times)
0 Members and 1 Guest are viewing this topic.
Geneva
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Good things come to those who wait better things come to those that don't
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
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);
}

Monitor reading with no delay

Code:
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:
[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
Code:
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]
Logged

Alex

White River Junction, Vermont USA
Offline Offline
Full Member
***
Karma: 5
Posts: 106
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps this applies to you:
    
Re: analogRead on DUE produces erratic results when requests are long between
(http://forum.arduino.cc/index.php?topic=186122.msg1379538#msg1379538)

-Chris
Logged

Geneva
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Good things come to those who wait better things come to those that don't
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Alex

Geneva
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Good things come to those who wait better things come to those that don't
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
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);
 }
Logged

Alex

Pages: [1]   Go Up
Jump to: