Reputation: 489
I have configured temperature sensor with intel edison. I am trying to read temperature sensor values using following python code
import mraa
import time
import sys
import math
tmp = mraa.Gpio(2)
tmp.dir(mraa.DIR_IN)
i=0
while i<100:
print "Let's talk about Temperature %s." % tmp.read()
time. sleep(3)
i+=1
exit()
But this code is return always 0 as reading value.
I am new to intel edison and python. So any help will be appreciating. Thanks
Upvotes: 2
Views: 1191
Reputation: 156
mraa is a low level skeleton library for I/O communication. In case of a basic analog sensor it will do the job, but I would recommend you to use upm instead.
import time
import pyupm_grove as grove
# Create the temperature sensor object using AIO pin 0
temp = grove.GroveTemp(0)
for i in range(0, 10):
celsius = temp.value()
fahrenheit = celsius * 9.0/5.0 + 32.0;
print "%d degrees Celsius, or %d degrees Fahrenheit" \
% (celsius, fahrenheit)
time.sleep(1)
# Delete the temperature sensor object
del temp
If it does n't work, you may need to update the libraries
echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
opkg update
opkg upgrade libmraa0
opkg upgrade upm
Upvotes: 2