1 2 Previous Next 15 Replies Latest reply on Jul 30, 2015 4:08 PM by CMata_Intel

# ADC analogue pin value too high

Hi All,

I'm using a AD TMP36 temperature sensor. When I measure the voltage on the output pin it is about 700mV.

The TMP36 has an offset of 500mV to account for negative temperatures and produces 10mV per 1 degree Celsius.

So at 700mV I get a temperature of 20C which is correct.

However my pin reading from my galileo gen 2 is 168.

If I've got a 10 bit adc (1024 steps) then 1 step is equal to 5000mV/1024 ~= 5mv

So 168*5mV = 840mV

Subtracting the offset and dividing by 10 gives a temperature of 34 degrees C.

What an I doing wrong??

Cheers.

• ###### 1. Re: ADC analogue pin value too high

Hi warmour ;

How are you testing this? Are you using the Arduino IDE or are you using MRAA? Or another tool to get the ADC value?

Regards;

CMata

• ###### 2. Re: ADC analogue pin value too high

Hi CMata,

I am using MRAA in a c++ code build in eclipse.

When the tmp36 is connected to Galileo my multimeter reads 1.35v and when it is not connected it reads 0.7v

Cheers.

• ###### 3. Re: ADC analogue pin value too high

Some further information...

I've tried this without the ad card version of Linux, and used the ardunio interface and a usb cable to monitor the serial output. I see

A0 = 140

A1 - A5 = 136

Is this normal?

Cheers

• ###### 4. Re: ADC analogue pin value too high

Also I reboot Linux as card version and the multimeter consistently read 0.7v

However the MRAA still reports a pin value that is too high, about 170

Cheers.

• ###### 5. Re: ADC analogue pin value too high

Hi warmour

I'm sorry for the delay in my response. Do you have the firmware updated?

Which MRAA version are you using?

On MRAA you are receiving 168 and in the Arduino IDE 140, is this right?

Also, what are the lectures when you read a 0V or 5V value, you can use the pins in the board to test this. Are you receiving the data successfully?

Regards;

CMata

• ###### 6. Re: ADC analogue pin value too high

Hi All, CMata,

I was looking for some help in relation to TMP36 readings too high and I found this post that actually describe perfectly the issue I 'm seeing on my Galileo Gen2

Hope you can help me.

When I measure the Vout pin of TMP36 I get this:

• Not connected to Galileo G2 = 0.722 V (22°C) that make sense!
• Connected to Galileo G2 = 1.03 V (53.03°C) ADC value 844 (12 bit resolution)

Formulas

Volts to °C Formula: (Vout - 0.5)*100

Library and IDE

Library: MRAA (updated)

MRAA Version: v0.7.3

Code: Javascript

IDE: Intel XDK IoT

Component: TMP 36

Component Connection:

Code

var m    = require('mraa');

console.log('MRAA Version: ' + m.getVersion());

var a0   = new m.Aio(0);

a0.setBit(12);

setInterval(function(){

},5000);

var val = (val_1*5.0)/4096;

var Temp = (val-0.5)*100;

console.log(">>Analog A0        Volts:     "         +String(val) +" V");

console.log(">>Analog A0        Temp:     " +String(Temp) +"°C");

console.log(">");

}

Results

MRAA Version: v0.7.3

>>Analog A0      Volts:    1.0302734375 V

>>Analog A0      Temp:     53.02734375°C

>

>>Analog A0      Volts:    1.0302734375 V

>>Analog A0      Temp:     53.02734375°C

>

>>Analog A0      Volts: 1.0302734375 V

>>Analog A0      Temp:     53.02734375°C

Tests

I use the pins on board to send 0V and 5V to A0

0V

New System Time: Fri Jul 24 2015 15:41:16 GMT+0000 (UTC)

>>Analog A0      Volts:    0 V

>>Analog A0      Temp:     -50°C

5V

>>Analog A0      Volts:    4.9951171875 V

>>Analog A0      Temp:     449.51171875°C

• ###### 7. Re: ADC analogue pin value too high

by the way it is working fine with Arduino IDE 1.6

void setup() {

Serial.begin(9600);

}

void loop() {

float Temp = (Volts-0.5)*100;

Serial.print(", ");

Serial.print(Volts);

Serial.print(", ");

Serial.println(Temp);

delay(1000);

}

• ###### 8. Re: ADC analogue pin value too high

Have you ran the Arduino sketch and the JS script at the same time? Are you getting the same voltage readings in both routines? If it works on the Arduino IDE, could be an errror in the code that we could be missing or it could be related to MRAA, could you run both routines at the same time and let me know if you are receiving the same measurements?

Regards,

Charlie

• ###### 9. Re: ADC analogue pin value too high

efernandezflores wrote:

by the way it is working fine with Arduino IDE 1.6

void setup() {

Serial.begin(9600);

}

void loop() {

float Temp = (Volts-0.5)*100;

Serial.print(", ");

Serial.print(Volts);

Serial.print(", ");

Serial.println(Temp);

delay(1000);

}

This is, indeed, a curious situation. Two points struck me (and I don't have a Gen 2 and don't use MRAA)...using a Voltmeter, you are seeing a substantial increase when the TMP  out line is connected to the Gen2 as compared to disconnected. But, using the Gen 2 and the Arduino sketch above, you are getting a "correct" reading in the sense that AnalogRead() is returning a reasonable value.

Are you getting a correct reading from the meter when running the Arduino sketch? I am hoping that you do and that would be a big clue. If so, then I have a suggestion:

Explicitly set the mode of the analog pin to input before doing the analog read in your MRAA code. Maybe it is just a long shot, but if the pin were initialized (or left) in an output mode, you could conceivably get some unexpected analog read values. The Arduino IDE  code may be doing the correct initialization somewhere along the line but the MRAA code is not -  and that could be the difference. If you try that, please let us know if it has an effect.

• ###### 10. Re: ADC analogue pin value too high

Hi RGee thanks for your response,

I run the sketch (Arduino IDE 1.6) and measure the Vout Pin of TMP36:

Connected to Galileo: 0.729 V

Disconnected from Galileo:  0.739 V

Then I run the code with XDK IoT using MRAA and I get this

Connected to Galileo: 1.012 V

Disconnected from Galileo:  0.739 V

There is a difference of 0.273 V just initializing from MRAA library, now we can at least assume that there is a voltage added by using MRAA library.

Now as I understand Aio class sets the analog pin to read the incoming signal, so it is not necessary to declare the "direction" to IN.

I looked for the GPIO37 folder under /sys/class/gpio/gpio37/direction and it is set to "in" it seems everithing is set accordingly.

What do you think?

• ###### 11. Re: ADC analogue pin value too high

When you change the temperature, is the offset the same? Is it always 0.273V or does it change?

Regards,

Charlie

• ###### 12. Re: ADC analogue pin value too high

efernandezflores wrote:

Hi RGee thanks for your response,

I run the sketch (Arduino IDE 1.6) and measure the Vout Pin of TMP36:

Connected to Galileo: 0.729 V

Disconnected from Galileo:  0.739 V

Then I run the code with XDK IoT using MRAA and I get this

Connected to Galileo: 1.012 V

Disconnected from Galileo:  0.739 V

There is a difference of 0.273 V just initializing from MRAA library, now we can at least assume that there is a voltage added by using MRAA library.

Now as I understand Aio class sets the analog pin to read the incoming signal, so it is not necessary to declare the "direction" to IN.

I looked for the GPIO37 folder under /sys/class/gpio/gpio37/direction and it is set to "in" it seems everithing is set accordingly.

What do you think?

I think that I agree with CMata_Intel that there may be a problem with your MRAA code or, less likely, a problem with the MRAA lib (because something that wrong would have been noted already). It's actually been fun to think about this issue as I am reading a bit about MRAA.

My approach would be to simplify the code as much as possible eliminating unnecessary statements. I secretly still feel that the pin is not being initialized correctly as an analog input because it is just not behaving that way except when you use the arduino sketch where it behaves exactly as it should (pretty much making it very unlikely that the board or the sensor is the problem).

So, I looked around and in this thread Intel Galileo Gen 2 Python code for Analog read gives error after some time · Issue #209 · intel-iot-devkit/mraa · GitHu…

alext-mkrs has a very short program:

import mraa  print("MRAA version is: " + mraa.getVersion())

a0 = mraa.Aio(0)

while True:

print result

Could you try running that and see if you get an appropriate value?

I also note that here mraa: Galileo Gen 2 - Rev H has this statement:

AIO pins are treated as 0-5 in mraa_aio_init() but as 14-19 for everything else. Therefore use mraa_gpio_init(14) to use A0 as a Gpio

Now, that does not have any direct connection that I can see but it makes me wonder if you need the statement var a0   = new m.Aio(0); and if it could be initializing the pin in a way that you don't want. Note that the few lines above do not include the 'new' statement.

I see another short program (by Carlos Mata and I am not sure if that is CMata_Intel)  here Edison/AnalogReadSerial.py at master · MakersTeam/Edison · GitHub that is for Edison with a board but also is not initializing the pin with 'new'. Could you run that one and see the result?

Finally, I apologize if I am making it worse, but MRAA is making me curious.

• ###### 13. Re: ADC analogue pin value too high

yes pretty much the same difference

• ###### 14. Re: ADC analogue pin value too high

Thank you RGee and CMata

I tried removing the new statement and just use

var       a0        = mraa.Aio(0);   but appeared some errors

MRAA Version: v0.7.3

ERROR: /home/root/.node_app_slot/main.js:11

ERROR:                        ^

ERROR: TypeError: Object #<Object> has no method 'read'

at null.<anonymous> (/home/root/.node_app_slot/main.js:9:5)

at wrapper [as _onTimeout] (timers.js:261:14)

at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

I checked the posts you sent me, the only thing is I am using javascript and the method seems to need the statement "new" in order to work.

I could use python but I prefer javascript

do you know if there any other library intead of MRAA for Intel XDK IoT?

i tried johnny-five but it is based on MRAA and i have the same result.

1 2 Previous Next