Note that the following code must be run at every boot for this to work, because of the repeated-start requirement:
sudo su -c 'echo "Y" > /sys/module/i2c_bcm2708/parameters/combined'
Note that the following code must be run at every boot for this to work, because of the repeated-start requirement:
sudo su -c 'echo "Y" > /sys/module/i2c_bcm2708/parameters/combined'
#!/usr/bin/env python3 | |
from adafruit.i2c import Adafruit_I2C | |
class Melexis: | |
def __init__(self, addr=0x5A, fahrenheit=False): | |
self._i2c = Adafruit_I2C(addr) | |
self.mode = fahrenheit | |
def readAmbient(self): | |
return self._readTemp(0x06) | |
def readObject(self): | |
return self._readTemp(0x07) | |
def readObject2(self): | |
return self._readTemp(0x08) | |
def getDifference(self): | |
"""Returns how much warmer the object is than the ambient | |
temperature.""" | |
return self.readObject() - sensor.readAmbient() | |
def _readTemp(self, reg): | |
temp = self._i2c.readS16(reg) | |
temp = temp * .02 - 273.15 | |
if self.mode: | |
return (temp * 9 / 5) + 32 | |
else: | |
return temp | |
if __name__ == "__main__": | |
sensor = Melexis(fahrenheit=True) | |
t = sensor.readObject() | |
print("Object: {}ºF ({}ºF warmer than the ambient temperature)".format( | |
round(t, 3), round(sensor.getDifference(), 3))) |
Thanks for the great help all.
This code works fine for me.
`
`