- Code: Select all
from Adafruit_I2C import Adafruit_I2C
class TMP102 :
i2c = None
def __init__(self, address=0x48, mode=1, debug=False):
self.i2c = Adafruit_I2C(address)
self.address = address
self.debug = debug
# Make sure the specified mode is in the appropriate range
if ((mode < 0) | (mode > 3)):
print "Invalid Mode: Using STANDARD by default"
self.mode = self.__BMP085_STANDARD
self.mode = mode
"Reads the raw (uncompensated) temperature from the sensor"
raw = self.i2c.readU16(0x48) #The TMP102 returns 12-bits, I think
print "DBG: Raw Temp: 0x%04X (%d)" % (raw & 0xFFFF, raw)
"Gets the compensated temperature in degrees celcius"
RawBytes = self.readRawTemp() #get the temp from readRawTemp (above)
temp =float(RawBytes) * (float(0.0625) / 16.0) # dividing by 16 accomplishes the bit-shift
print "DBG: Calibrated temperature = %f C" % temp
You can see that it is still based off of the code for the BMP085.
I don't know if we have anyone that is really good at stylistic issues. I'm probably going to stick with one way and just consistently write that way, but:
Stylistically, should I create a 12-bit read entry in the I2C library, or stick with my current work which creates a new class to handle the behind the scenes math?
Is there a way that is more expected? My goal is to have some hardware and software that anyone can use easily. I know that I'm stuck too far into the weeds to see what is easy to use.