Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Community Manager
1,254 Views

Different mraa.aio read value between SDCard.1.0.4.tar.gz and iot-devkit-latest-mmcblkp0.direct

Hey all - I recently switched from the SD Card image <<span style="font-size: 10pt; line-height: 1.5em;">SDCard.1.0.4.tar> from <</span>https://downloadcenter.intel.com/download/24355/Intel-Arduino-IDE-1-6-0 Download Intel® Arduino IDE 1.6.0 >, where I had to build and install MRAA to read sensor values with Python to the IoT-DevKit Latest image.

When I read the pin value of a TMP36 what used to work fine is now off by 200°F. Any ideas why?

Code:

# !/usr/bin/env python import mraa import sys import time tempPin = mraa.Aio(0) print(mraa.getVersion()) while 1: tempMV = float(tempPin.read()) print "Analog Read: " + str(tempMV) voltage = (tempMV * 5.0) / 1024.0 print "Voltage: " + str(voltage) tempC= (voltage - 0.5 ) * 100 tempF= (tempC * 9.0 / 5.0) + 32.0 print "Temperature F: " + str(round(tempF)) time.sleep(10)

Output

root@galileo:~# ./temp.py v0.7.2 Analog Read: 363.0 Voltage: 1.7724609375 Temperature F: 261.0

Sys info

root@galileo:~# uname -a

Linux galileo 3.8.7-yocto-standard # 1 Tue Jun 9 22:07:14 GMT 2015 i586 GNU/Linux

root@galileo:~# cat /etc/version

201506210418

 

And the wiring (it's not an arduino Yun, but you get the idea).

 

Thanks!

-Joe

 

7 Replies
Highlighted
Community Manager
8 Views

Additional data point. I downloaded iot-devkit-201510010757-mmcblkp0-galileo.direct , ran opkg update/upgrade and the same output . As an aside, the number of releases on the Galileo with little easy to find information on what differentiates them is ... confusing.

New output:

root@galileo:~# uname -a

Linux galileo 3.8.7-yocto-standard # 1 Tue Sep 29 22:16:33 GMT 2015 i586 GNU/Linux

root@galileo:~# cat /etc/version

201510010732

root@galileo:~# ./temp.py

v0.8.1

Analog Read: 372.0

Voltage: 1.81640625

Temperature F: 269.0

 

-Joe

 

0 Kudos
Highlighted
Community Manager
8 Views

Hmm the mystery continues. I uploaded a sketch to read the temperature and the output is fine via the serial console. The code I used was from an Adafruit example: https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor .

I also tried a second TMP36 I had with identical results, So I am pretty sure it is something I am doing on the Python/Linux side.

Any thoughts would be appreciated.

Cheers,

-Joe

0 Kudos
Highlighted
Employee
8 Views

Hi Joe,

Now that you have one working code, you could start comparing step by step both codes

For example, check the ADC lectures from both codes, step by step of all the operations used in the code and finally the result. There could be an error in one of the operations, it could be with a parenthesis or something related.

Regards,

Charlie

0 Kudos
Highlighted
Community Manager
8 Views

Hey Charlie - Thanks for responding. I think I explained poorly, the arduino code works, not the python code. If I needed Arduino code to work I would just use a $19 Arduino

My impression was I could access the value of an analog sensor by using the mraa library via python without having to load a corresponding sketch.

The python code is unchanged, I copied it from one SD card to the other. The output of mraa.Aio read() on the Iot-DevKit image is not the same as that on the SD-Card.1.0.4.tar.gz image with the same wiring, hardware and code. I can literally power off, switch SD cards and reboot and get different results just because of the distribution.

Maybe it is uncommon to use python to read analog sensors on the Galileo?

Is there a method similar to the Arduino Yun's bridge to communicate between the sketch output and the linux side?

Cheers,

-Joe

0 Kudos
Employee
8 Views

Hi Joe,

What I wanted to say is that you could start checking the differences in the lines of both codes. For example you can put a print statement after every data acquisition and after every operation in order to debug step by step of your code. With this you could see where the error is.

You should be able to read analog values using the Galileo and the MRAA library.

I saw you have: voltage = (tempMV * 5.0) / 1024.0. Are you using the Galileo Gen2? If you do, add in your python code the line: tempPin.setBit(10), if you are on Galileo Gen1, add tempPin.setBit(12). You should have something like:

# !/usr/bin/env python

import mraa

import sys

import time

tempPin = mraa.Aio(0)

print(mraa.getVersion())

tempPin.setBit(10) # If you are using Galileo Gen2

....

 

Let us know if this works.

Regards,

Charlie

0 Kudos
Highlighted
Community Manager
8 Views

Hey Charlie - Thanks for the idea. Unfortunately this doesn't work for me. I am using a Gen 2 Galileo. I guess the more appropriate question is "How to read analog values with iot dev kit image and python?" I should start a new thread.

As an additional data point I tried this with a traditional LM335 as well as the TMP36. Both times I can read from an Arduino sketch fine, but not python. But still confused as to why the SDCard image read fine and the iot dev kit one did not.

Cheers,

-Joe

0 Kudos
Highlighted
Employee
8 Views

Just to follow up on this, Joe opened this new thread:

0 Kudos