From a5628ba9c6bc2449e71808f488eb20e62415705d Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 9 Jul 2013 22:49:14 -0500 Subject: [PATCH 01/20] also altitude gets units --- Adafruit_BMP085/Adafruit_BMP085_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_BMP085/Adafruit_BMP085_example.py b/Adafruit_BMP085/Adafruit_BMP085_example.py index 5e0d0bef..43524418 100755 --- a/Adafruit_BMP085/Adafruit_BMP085_example.py +++ b/Adafruit_BMP085/Adafruit_BMP085_example.py @@ -22,4 +22,4 @@ print "Temperature: %.2f C" % temp print "Pressure: %.2f hPa" % (pressure / 100.0) -print "Altitude: %.2f" % altitude +print "Altitude: %.2f m" % altitude From 80cacd2d0a47fdf8f954233e9537090215e9d557 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 9 Jul 2013 23:41:37 -0500 Subject: [PATCH 02/20] port of adafruit/Adafruit_TMP006 to python/pi --- Adafruit_TMP006/Adafruit_I2C.py | 1 + Adafruit_TMP006/Adafruit_TMP006.py | 128 +++++++++++++++++++++ Adafruit_TMP006/Adafruit_TMP006_example.py | 25 ++++ 3 files changed, 154 insertions(+) create mode 120000 Adafruit_TMP006/Adafruit_I2C.py create mode 100644 Adafruit_TMP006/Adafruit_TMP006.py create mode 100755 Adafruit_TMP006/Adafruit_TMP006_example.py diff --git a/Adafruit_TMP006/Adafruit_I2C.py b/Adafruit_TMP006/Adafruit_I2C.py new file mode 120000 index 00000000..77f06164 --- /dev/null +++ b/Adafruit_TMP006/Adafruit_I2C.py @@ -0,0 +1 @@ +../Adafruit_I2C/Adafruit_I2C.py \ No newline at end of file diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py new file mode 100644 index 00000000..5f31bf4b --- /dev/null +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -0,0 +1,128 @@ +#!/usr/bin/python + +import time +from Adafruit_I2C import Adafruit_I2C + +# =========================================================================== +# TMP006 Class +# =========================================================================== + +class TMP006 : + i2c = None + + # TMP006 Registers + __TMP006_REG_VOBJ = 0x00 + __TMP006_REG_TAMB = 0x01 + __TMP006_REG_CONFIG = 0x02 + __TMP006_REG_MANID = 0xFE + __TMP006_REG_DEVID = 0xFF + + # CONFIG Register Values + __TMP006_CFG_RESET = 0x8000 + __TMP006_CFG_MODEON = 0x7000 + __TMP006_CFG_1SAMPLE = 0x0000 + __TMP006_CFG_2SAMPLE = 0x0200 + __TMP006_CFG_4SAMPLE = 0x0400 + __TMP006_CFG_8SAMPLE = 0x0600 + __TMP006_CFG_16SAMPLE = 0x0800 + __TMP006_CFG_DRDYEN = 0x0100 + __TMP006_CFG_DRDY = 0x0080 + + # Manufacturer ID + __TMP006_MANID = 0x5449 + + # Device ID + __TMP006_DEVID = 0x0067 + + # Internal Data + __TMP006_B0 = -0.0000294 + __TMP006_B1 = -0.00000057 + __TMP006_B2 = 0.00000000463 + __TMP006_C2 = 13.4 + __TMP006_TREF = 298.15 + __TMP006_A2 = -0.00001678 + __TMP006_A1 = 0.00175 + __TMP006_S0 = 6.4 # * 10^-14 + + # Constructor + def __init__(self, address=0x40, mode=1, debug=False): + self.i2c = Adafruit_I2C(address) + + self.address = address + self.debug = debug + + # Destructor + + + # Start Sampling + def begin(samplerate=self.__TMP006_CFG_16SAMPLE): + self.i2c.readU16(__TMP006_REG_CONFIG, + __TMP006_CFG_MODEON | __TMP006_CFG_DRDYEN | samplerate); + + mid = self.i2c.readU16(self.__TMP006_REG_MANID) + did = self.i2c.readU16(self.__TMP006_REG_DEVID) + + if debug: + print "mid = 0x%x" % mid + print "did = 0x%x" % did + + if mid != __TMP006_MANID: + print "WARN TMP006: Manufacturer ID Mismatch (%04X)" % mid + if did != __TMP006_DEVID: + print "WARN TMP006: Decide ID Mismatch (%04X)" % did + + def readRawDieTemperature(): + "Read the raw die temperature" + raw = self.i2c.readU16(self.__TMP006_REG_TAMB) + raw >>= 2 + if self.debug: + C = raw * 0.03125 + print "Raw Tambient: 0x%04X (%f C)" % (raw, C) + return raw + + def readRawVoltage(): + "Read the raw voltage" + raw = self.i2c.readU16(self.__TMP006_REG_VOBJ) + if self.debug: + v = raw + v *= 156.25 + v /= 1000 + print "Raw voltage: 0x%04X (%f uV)" % (raw, v) + return raw + + def readDieTempC(): + Tdie = self.readRawDieTemperature() + Tdie *= 0.03125 # convert to celsius + if self.debug: + print "Tdie = ", Tdie + return Tdie + + def readObjTempC(): + Tdie = self.readRawDieTemperature() + Vobj = self.readRawVoltage() + Vobj *= 156.25 # 156.25 nV per LSB + Vobj /= 1000 # nV -> uV + Vobj /= 1000 # uV -> mV + Vobj /= 1000 # mV -> V + Tdie *= 0.03125 # convert to celsius + Tdie += 273.15 # convert to kelvin + + if self.debug: + print "Vobj = ", Vobj * 1000000, "uV" + print "Tdie = ", Tdie, " C" + + tdie_tref = Tdie - self.__TMP006_TREF + S = 1 + self.__TMP006_A1 * tdie_tref \ + + self.__TMP006_A2 * tdie_tref * tdie_tref + S *= TMP006_S0 + S /= 10000000 + S /= 10000000 + + Vos = self.__TMP006_B0 + self.__TMP006_B1 * tdie_tref \ + + self.__TMP006_B2 * tdie_tref * tdie_tref + + fVobj = (Vobj - Vos) + self.__TMP006_C2 * (Vobj-Vos)*(Vobj-Vos) + Tobj = sqrt(sqrt(Tdie * Tdie * Tdie * Tdie + fVobj/S)) + + Tobj -= 273.15 # Kelvin -> *C + return Tobj diff --git a/Adafruit_TMP006/Adafruit_TMP006_example.py b/Adafruit_TMP006/Adafruit_TMP006_example.py new file mode 100755 index 00000000..576b308d --- /dev/null +++ b/Adafruit_TMP006/Adafruit_TMP006_example.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +from Adafruit_TMP006 import TMP006 +from time import sleep + +# =========================================================================== +# Example Code +# =========================================================================== + +# Initialise the TMP006 and use defaults +# tmp = TMP006(0x40, debug=True) +tmp = TMP006(0x40) + +# Start sampling +tmp.begin() + +# Wait a short bit for sample averaging +sleep(1.5) + +dietemp = bmp.readDieTempC() +objtemp = bmp.readObjTempC() + +print "Die Temperature: %.2f C" % dietemp +print "Object Temperature: %.2f C" % objtemp + From 4d484357078cf0241a1a777e1f56186fb9f751c5 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 9 Jul 2013 23:48:25 -0500 Subject: [PATCH 03/20] forgot to put self arg --- Adafruit_TMP006/Adafruit_TMP006.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index 5f31bf4b..1eb58269 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -55,14 +55,14 @@ def __init__(self, address=0x40, mode=1, debug=False): # Start Sampling - def begin(samplerate=self.__TMP006_CFG_16SAMPLE): - self.i2c.readU16(__TMP006_REG_CONFIG, - __TMP006_CFG_MODEON | __TMP006_CFG_DRDYEN | samplerate); + def begin(self, samplerate=self.__TMP006_CFG_16SAMPLE): + self.i2c.write16(self.__TMP006_REG_CONFIG, + self.__TMP006_CFG_MODEON | self.__TMP006_CFG_DRDYEN | samplerate); mid = self.i2c.readU16(self.__TMP006_REG_MANID) did = self.i2c.readU16(self.__TMP006_REG_DEVID) - if debug: + if self.debug: print "mid = 0x%x" % mid print "did = 0x%x" % did @@ -71,7 +71,7 @@ def begin(samplerate=self.__TMP006_CFG_16SAMPLE): if did != __TMP006_DEVID: print "WARN TMP006: Decide ID Mismatch (%04X)" % did - def readRawDieTemperature(): + def readRawDieTemperature(self): "Read the raw die temperature" raw = self.i2c.readU16(self.__TMP006_REG_TAMB) raw >>= 2 @@ -80,7 +80,7 @@ def readRawDieTemperature(): print "Raw Tambient: 0x%04X (%f C)" % (raw, C) return raw - def readRawVoltage(): + def readRawVoltage(self): "Read the raw voltage" raw = self.i2c.readU16(self.__TMP006_REG_VOBJ) if self.debug: @@ -90,14 +90,14 @@ def readRawVoltage(): print "Raw voltage: 0x%04X (%f uV)" % (raw, v) return raw - def readDieTempC(): + def readDieTempC(self): Tdie = self.readRawDieTemperature() Tdie *= 0.03125 # convert to celsius if self.debug: print "Tdie = ", Tdie return Tdie - def readObjTempC(): + def readObjTempC(self): Tdie = self.readRawDieTemperature() Vobj = self.readRawVoltage() Vobj *= 156.25 # 156.25 nV per LSB From 6ee446f8959103bc5b393553dfd63b167940bbce Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 9 Jul 2013 23:49:56 -0500 Subject: [PATCH 04/20] forgot to put self arg --- Adafruit_TMP006/Adafruit_TMP006.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index 1eb58269..9753b742 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -66,9 +66,9 @@ def begin(self, samplerate=self.__TMP006_CFG_16SAMPLE): print "mid = 0x%x" % mid print "did = 0x%x" % did - if mid != __TMP006_MANID: + if mid != self.__TMP006_MANID: print "WARN TMP006: Manufacturer ID Mismatch (%04X)" % mid - if did != __TMP006_DEVID: + if did != self.__TMP006_DEVID: print "WARN TMP006: Decide ID Mismatch (%04X)" % did def readRawDieTemperature(self): From 842584f35f609917112fa85b5aa403f5c95ed77c Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 9 Jul 2013 23:51:25 -0500 Subject: [PATCH 05/20] extra self arg --- Adafruit_TMP006/Adafruit_TMP006.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index 9753b742..74a8fcd2 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -55,7 +55,7 @@ def __init__(self, address=0x40, mode=1, debug=False): # Start Sampling - def begin(self, samplerate=self.__TMP006_CFG_16SAMPLE): + def begin(self, samplerate=__TMP006_CFG_16SAMPLE): self.i2c.write16(self.__TMP006_REG_CONFIG, self.__TMP006_CFG_MODEON | self.__TMP006_CFG_DRDYEN | samplerate); From 458000b7e6eb7578a84f91ffa0881d25d6d00ce9 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 9 Jul 2013 23:52:38 -0500 Subject: [PATCH 06/20] tmp not bmp --- Adafruit_TMP006/Adafruit_TMP006_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006_example.py b/Adafruit_TMP006/Adafruit_TMP006_example.py index 576b308d..1b634f70 100755 --- a/Adafruit_TMP006/Adafruit_TMP006_example.py +++ b/Adafruit_TMP006/Adafruit_TMP006_example.py @@ -17,8 +17,8 @@ # Wait a short bit for sample averaging sleep(1.5) -dietemp = bmp.readDieTempC() -objtemp = bmp.readObjTempC() +dietemp = tmp.readDieTempC() +objtemp = tmp.readObjTempC() print "Die Temperature: %.2f C" % dietemp print "Object Temperature: %.2f C" % objtemp From fe8f38e6735799df94cce621220225b3a8953fb0 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 9 Jul 2013 23:53:35 -0500 Subject: [PATCH 07/20] forgot to put self arg --- Adafruit_TMP006/Adafruit_TMP006.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index 74a8fcd2..0d68c778 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -114,7 +114,7 @@ def readObjTempC(self): tdie_tref = Tdie - self.__TMP006_TREF S = 1 + self.__TMP006_A1 * tdie_tref \ + self.__TMP006_A2 * tdie_tref * tdie_tref - S *= TMP006_S0 + S *= self.__TMP006_S0 S /= 10000000 S /= 10000000 From adbf4f45b41311b705b10731cc6deab869f3c398 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Wed, 10 Jul 2013 00:11:26 -0500 Subject: [PATCH 08/20] try using word read for 16bit data reads? cleanup when done. --- Adafruit_I2C/Adafruit_I2C.py | 7 ++++--- Adafruit_TMP006/Adafruit_TMP006.py | 14 ++++++++++---- Adafruit_TMP006/Adafruit_TMP006_example.py | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 3423461d..9c70d764 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -117,9 +117,10 @@ def readS8(self, reg): def readU16(self, reg): "Reads an unsigned 16-bit value from the I2C device" try: - hibyte = self.readU8(reg) - lobyte = self.readU8(reg+1) - result = (hibyte << 8) + lobyte + result = self.bus.read_word_data(self.address, reg) + #hibyte = self.readU8(reg) + #lobyte = self.readU8(reg+1) + #result = (hibyte << 8) + lobyte if (self.debug): print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) return result diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index 0d68c778..f504c5a7 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -2,6 +2,7 @@ import time from Adafruit_I2C import Adafruit_I2C +from math import sqrt # =========================================================================== # TMP006 Class @@ -50,17 +51,22 @@ def __init__(self, address=0x40, mode=1, debug=False): self.address = address self.debug = debug + self.started = false # Destructor - + def __del__(self): + if self.started: + self.i2c.write16(self.__TMP006_REG_CONFIG, 0); # Start Sampling def begin(self, samplerate=__TMP006_CFG_16SAMPLE): self.i2c.write16(self.__TMP006_REG_CONFIG, self.__TMP006_CFG_MODEON | self.__TMP006_CFG_DRDYEN | samplerate); - mid = self.i2c.readU16(self.__TMP006_REG_MANID) - did = self.i2c.readU16(self.__TMP006_REG_DEVID) + self.started = true + + mid = self.i2c.readS16(self.__TMP006_REG_MANID) + did = self.i2c.readS16(self.__TMP006_REG_DEVID) if self.debug: print "mid = 0x%x" % mid @@ -69,7 +75,7 @@ def begin(self, samplerate=__TMP006_CFG_16SAMPLE): if mid != self.__TMP006_MANID: print "WARN TMP006: Manufacturer ID Mismatch (%04X)" % mid if did != self.__TMP006_DEVID: - print "WARN TMP006: Decide ID Mismatch (%04X)" % did + print "WARN TMP006: Device ID Mismatch (%04X)" % did def readRawDieTemperature(self): "Read the raw die temperature" diff --git a/Adafruit_TMP006/Adafruit_TMP006_example.py b/Adafruit_TMP006/Adafruit_TMP006_example.py index 1b634f70..052a8850 100755 --- a/Adafruit_TMP006/Adafruit_TMP006_example.py +++ b/Adafruit_TMP006/Adafruit_TMP006_example.py @@ -15,6 +15,7 @@ tmp.begin() # Wait a short bit for sample averaging +print "Pausing 1.5 s..." sleep(1.5) dietemp = tmp.readDieTempC() From cb935f48b817ad56c70588da62367b934c7196c3 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Wed, 10 Jul 2013 00:14:32 -0500 Subject: [PATCH 09/20] use the unsigned readU16 functions since they now use word read on i2c --- Adafruit_TMP006/Adafruit_TMP006.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index f504c5a7..e3fadac1 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -65,8 +65,8 @@ def begin(self, samplerate=__TMP006_CFG_16SAMPLE): self.started = true - mid = self.i2c.readS16(self.__TMP006_REG_MANID) - did = self.i2c.readS16(self.__TMP006_REG_DEVID) + mid = self.i2c.readU16(self.__TMP006_REG_MANID) + did = self.i2c.readU16(self.__TMP006_REG_DEVID) if self.debug: print "mid = 0x%x" % mid From f2d33f6598ac4fcef29c89aed22c0320ed50da82 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Wed, 10 Jul 2013 00:16:43 -0500 Subject: [PATCH 10/20] swap bytes in readU16 --- Adafruit_I2C/Adafruit_I2C.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 9c70d764..739339ca 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -118,9 +118,9 @@ def readU16(self, reg): "Reads an unsigned 16-bit value from the I2C device" try: result = self.bus.read_word_data(self.address, reg) - #hibyte = self.readU8(reg) - #lobyte = self.readU8(reg+1) - #result = (hibyte << 8) + lobyte + hibyte = 0xff & result + lobyte = 0xff & (result >> 8) + result = (hibyte << 8) | lobyte if (self.debug): print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) return result From 519c69088ce7881e61f2fb1251a836efb6a8c09d Mon Sep 17 00:00:00 2001 From: michael tesch Date: Wed, 10 Jul 2013 00:17:37 -0500 Subject: [PATCH 11/20] True and False are caps in python --- Adafruit_TMP006/Adafruit_TMP006.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index e3fadac1..5545848a 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -51,7 +51,7 @@ def __init__(self, address=0x40, mode=1, debug=False): self.address = address self.debug = debug - self.started = false + self.started = False # Destructor def __del__(self): @@ -63,7 +63,7 @@ def begin(self, samplerate=__TMP006_CFG_16SAMPLE): self.i2c.write16(self.__TMP006_REG_CONFIG, self.__TMP006_CFG_MODEON | self.__TMP006_CFG_DRDYEN | samplerate); - self.started = true + self.started = True mid = self.i2c.readU16(self.__TMP006_REG_MANID) did = self.i2c.readU16(self.__TMP006_REG_DEVID) From 1eff57dc216ad7e89c3525ec7a1df1e66f96c752 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Wed, 10 Jul 2013 00:32:59 -0500 Subject: [PATCH 12/20] registers are signed (according to c++ code) --- Adafruit_TMP006/Adafruit_TMP006.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006.py b/Adafruit_TMP006/Adafruit_TMP006.py index 5545848a..b7256420 100644 --- a/Adafruit_TMP006/Adafruit_TMP006.py +++ b/Adafruit_TMP006/Adafruit_TMP006.py @@ -79,7 +79,7 @@ def begin(self, samplerate=__TMP006_CFG_16SAMPLE): def readRawDieTemperature(self): "Read the raw die temperature" - raw = self.i2c.readU16(self.__TMP006_REG_TAMB) + raw = self.i2c.readS16(self.__TMP006_REG_TAMB) raw >>= 2 if self.debug: C = raw * 0.03125 @@ -88,7 +88,7 @@ def readRawDieTemperature(self): def readRawVoltage(self): "Read the raw voltage" - raw = self.i2c.readU16(self.__TMP006_REG_VOBJ) + raw = self.i2c.readS16(self.__TMP006_REG_VOBJ) if self.debug: v = raw v *= 156.25 From b07e8f1ec4e866057e64a86523cfc85920268a90 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Wed, 10 Jul 2013 00:38:27 -0500 Subject: [PATCH 13/20] also print temps in F for mericans --- Adafruit_TMP006/Adafruit_TMP006_example.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006_example.py b/Adafruit_TMP006/Adafruit_TMP006_example.py index 052a8850..95099569 100755 --- a/Adafruit_TMP006/Adafruit_TMP006_example.py +++ b/Adafruit_TMP006/Adafruit_TMP006_example.py @@ -3,6 +3,9 @@ from Adafruit_TMP006 import TMP006 from time import sleep +def C_to_F(C): + return C * (180.0 / 100.0) + 32.0 + # =========================================================================== # Example Code # =========================================================================== @@ -21,6 +24,6 @@ dietemp = tmp.readDieTempC() objtemp = tmp.readObjTempC() -print "Die Temperature: %.2f C" % dietemp -print "Object Temperature: %.2f C" % objtemp +print "Die Temperature: %.2f C / %.2f F" % (dietemp, C_to_F(dietemp)) +print "Object Temperature: %.2f C / %.2f F" % (objtemp, C_to_F(objtemp)) From 76de6af08d950b7b86dee70753c743791f3cf274 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Wed, 10 Jul 2013 00:40:49 -0500 Subject: [PATCH 14/20] loop and read the temp --- Adafruit_TMP006/Adafruit_TMP006_example.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Adafruit_TMP006/Adafruit_TMP006_example.py b/Adafruit_TMP006/Adafruit_TMP006_example.py index 95099569..1e45b71f 100755 --- a/Adafruit_TMP006/Adafruit_TMP006_example.py +++ b/Adafruit_TMP006/Adafruit_TMP006_example.py @@ -18,12 +18,13 @@ def C_to_F(C): tmp.begin() # Wait a short bit for sample averaging -print "Pausing 1.5 s..." -sleep(1.5) +while True: + print "Pausing 1.0 s..." + sleep(1.0) -dietemp = tmp.readDieTempC() -objtemp = tmp.readObjTempC() + dietemp = tmp.readDieTempC() + objtemp = tmp.readObjTempC() -print "Die Temperature: %.2f C / %.2f F" % (dietemp, C_to_F(dietemp)) -print "Object Temperature: %.2f C / %.2f F" % (objtemp, C_to_F(objtemp)) + print "Die Temperature: %.2f C / %.2f F" % (dietemp, C_to_F(dietemp)) + print "Object Temperature: %.2f C / %.2f F" % (objtemp, C_to_F(objtemp)) From c27a9fe35ff800a3faae5e3be59a7963cba8bfe3 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Sun, 21 Jul 2013 09:22:29 -0500 Subject: [PATCH 15/20] added unit conversion for US to BMP085 example --- Adafruit_BMP085/Adafruit_BMP085_example.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Adafruit_BMP085/Adafruit_BMP085_example.py b/Adafruit_BMP085/Adafruit_BMP085_example.py index 43524418..7537cd14 100755 --- a/Adafruit_BMP085/Adafruit_BMP085_example.py +++ b/Adafruit_BMP085/Adafruit_BMP085_example.py @@ -2,6 +2,18 @@ from Adafruit_BMP085 import BMP085 +def C_to_F(C): + return C * (180.0 / 100.0) + 32.0 + +def m_to_ft(m): + return 3.2808399 * m + +def hPa_to_inHg(hPa): + return hPa / 33.86389 + +def hPa_to_psi(hPa): + return hPa / 0.0145037 + # =========================================================================== # Example Code # =========================================================================== @@ -20,6 +32,6 @@ pressure = bmp.readPressure() altitude = bmp.readAltitude() -print "Temperature: %.2f C" % temp -print "Pressure: %.2f hPa" % (pressure / 100.0) -print "Altitude: %.2f m" % altitude +print "Temperature: %.2f C / %.2f F" % (temp, C_to_F(temp)) +print "Pressure: %.2f hPa / %.2f inHg" % ((pressure / 100.0), hPa_to_inHg(pressure)) +print "Altitude: %.2f m / %.1 ft" % (altitude, m_to_ft(altitude)) From 58a782198f176d63c6167776d285a06363988dd8 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Sun, 21 Jul 2013 14:44:22 +0000 Subject: [PATCH 16/20] fixed pressure calculation and format string for inHg --- Adafruit_BMP085/Adafruit_BMP085_example.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_BMP085/Adafruit_BMP085_example.py b/Adafruit_BMP085/Adafruit_BMP085_example.py index 7537cd14..a7f9b9ff 100755 --- a/Adafruit_BMP085/Adafruit_BMP085_example.py +++ b/Adafruit_BMP085/Adafruit_BMP085_example.py @@ -33,5 +33,5 @@ def hPa_to_psi(hPa): altitude = bmp.readAltitude() print "Temperature: %.2f C / %.2f F" % (temp, C_to_F(temp)) -print "Pressure: %.2f hPa / %.2f inHg" % ((pressure / 100.0), hPa_to_inHg(pressure)) -print "Altitude: %.2f m / %.1 ft" % (altitude, m_to_ft(altitude)) +print "Pressure: %.2f hPa / %.2f inHg" % ((pressure / 100.0), hPa_to_inHg(pressure / 100.0)) +print "Altitude: %.2f m / %.1f ft" % (altitude, m_to_ft(altitude)) From 159a4ad1a1e0b7284eee0327dda29f11044a3c40 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Mon, 22 Jul 2013 20:17:54 -0500 Subject: [PATCH 17/20] fixed 16bit word write for i2c? --- Adafruit_I2C/Adafruit_I2C.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 739339ca..76835dc0 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -61,11 +61,11 @@ def write8(self, reg, value): def write16(self, reg, value): "Writes a 16-bit value to the specified register/address pair" + value = ((val << 8) & 0xff00) | ((val >> 8) & 0xff) try: self.bus.write_word_data(self.address, reg, value) if self.debug: - print ("I2C: Wrote 0x%02X to register pair 0x%02X,0x%02X" % - (value, reg, reg+1)) + print ("I2C: Wrote 0x%04X to register 0x%02X" % (value, reg)) except IOError, err: return self.errMsg() From 805a3bf12c139e9a00590c3d8fe342dcf5b8da54 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 23 Jul 2013 01:22:42 +0000 Subject: [PATCH 18/20] loop in demo, fix unsigned short->int conversion in I2C readS16 --- Adafruit_BMP085/Adafruit_BMP085_example.py | 15 +++++++++------ Adafruit_I2C/Adafruit_I2C.py | 11 ++++++++--- Adafruit_TMP006/Adafruit_TMP006_example.py | 6 +++--- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Adafruit_BMP085/Adafruit_BMP085_example.py b/Adafruit_BMP085/Adafruit_BMP085_example.py index a7f9b9ff..62ccaf8b 100755 --- a/Adafruit_BMP085/Adafruit_BMP085_example.py +++ b/Adafruit_BMP085/Adafruit_BMP085_example.py @@ -1,5 +1,6 @@ #!/usr/bin/python +from time import sleep from Adafruit_BMP085 import BMP085 def C_to_F(C): @@ -28,10 +29,12 @@ def hPa_to_psi(hPa): # bmp = BMP085(0x77, 2) # HIRES Mode # bmp = BMP085(0x77, 3) # ULTRAHIRES Mode -temp = bmp.readTemperature() -pressure = bmp.readPressure() -altitude = bmp.readAltitude() +while True: + temp = bmp.readTemperature() + pressure = bmp.readPressure() + altitude = bmp.readAltitude() -print "Temperature: %.2f C / %.2f F" % (temp, C_to_F(temp)) -print "Pressure: %.2f hPa / %.2f inHg" % ((pressure / 100.0), hPa_to_inHg(pressure / 100.0)) -print "Altitude: %.2f m / %.1f ft" % (altitude, m_to_ft(altitude)) + print "Temperature: %.2f C / %.2f F" % (temp, C_to_F(temp)) + print "Pressure: %.2f hPa / %.2f inHg" % ((pressure / 100.0), hPa_to_inHg(pressure / 100.0)) + print "Altitude: %.2f m / %.1f ft" % (altitude, m_to_ft(altitude)) + sleep(2.0) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 739339ca..5184fb50 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -1,6 +1,7 @@ #!/usr/bin/python import smbus +from ctypes import c_short # =========================================================================== # Adafruit_I2C Class @@ -130,9 +131,13 @@ def readU16(self, reg): def readS16(self, reg): "Reads a signed 16-bit value from the I2C device" try: - hibyte = self.readS8(reg) - lobyte = self.readU8(reg+1) - result = (hibyte << 8) + lobyte + #hibyte = self.readS8(reg) + #lobyte = self.readU8(reg+1) + #result = (hibyte << 8) + lobyte + result = self.bus.read_word_data(self.address, reg) + hibyte = 0xff & result + lobyte = 0xff & (result >> 8) + result = c_short((hibyte << 8) + lobyte).value if (self.debug): print "I2C: Device 0x%02X returned 0x%04X from reg 0x%02X" % (self.address, result & 0xFFFF, reg) return result diff --git a/Adafruit_TMP006/Adafruit_TMP006_example.py b/Adafruit_TMP006/Adafruit_TMP006_example.py index 1e45b71f..f721975a 100755 --- a/Adafruit_TMP006/Adafruit_TMP006_example.py +++ b/Adafruit_TMP006/Adafruit_TMP006_example.py @@ -12,15 +12,15 @@ def C_to_F(C): # Initialise the TMP006 and use defaults # tmp = TMP006(0x40, debug=True) -tmp = TMP006(0x40) +tmp = TMP006(0x41, debug=True) # Start sampling tmp.begin() # Wait a short bit for sample averaging while True: - print "Pausing 1.0 s..." - sleep(1.0) + print "Pausing 2.0 s..." + sleep(2.0) dietemp = tmp.readDieTempC() objtemp = tmp.readObjTempC() From a7d5c06cabd8e944ac5626405e5b1a6548da7653 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Tue, 23 Jul 2013 01:29:07 +0000 Subject: [PATCH 19/20] fixed typo in I2C, val->value --- Adafruit_I2C/Adafruit_I2C.py | 2 +- Adafruit_TMP006/Adafruit_TMP006_example.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 2268eff6..525e6b7a 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -62,7 +62,7 @@ def write8(self, reg, value): def write16(self, reg, value): "Writes a 16-bit value to the specified register/address pair" - value = ((val << 8) & 0xff00) | ((val >> 8) & 0xff) + value = ((value << 8) & 0xff00) | ((value >> 8) & 0xff) try: self.bus.write_word_data(self.address, reg, value) if self.debug: diff --git a/Adafruit_TMP006/Adafruit_TMP006_example.py b/Adafruit_TMP006/Adafruit_TMP006_example.py index f721975a..8965a0b6 100755 --- a/Adafruit_TMP006/Adafruit_TMP006_example.py +++ b/Adafruit_TMP006/Adafruit_TMP006_example.py @@ -12,7 +12,7 @@ def C_to_F(C): # Initialise the TMP006 and use defaults # tmp = TMP006(0x40, debug=True) -tmp = TMP006(0x41, debug=True) +tmp = TMP006(0x41) # Start sampling tmp.begin() From 411698e3b46edc3cbfbbd19a4390a01b110aebc6 Mon Sep 17 00:00:00 2001 From: michael tesch Date: Mon, 22 Jul 2013 20:30:11 -0500 Subject: [PATCH 20/20] typo fix --- Adafruit_I2C/Adafruit_I2C.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_I2C/Adafruit_I2C.py b/Adafruit_I2C/Adafruit_I2C.py index 76835dc0..749b3f98 100755 --- a/Adafruit_I2C/Adafruit_I2C.py +++ b/Adafruit_I2C/Adafruit_I2C.py @@ -61,7 +61,7 @@ def write8(self, reg, value): def write16(self, reg, value): "Writes a 16-bit value to the specified register/address pair" - value = ((val << 8) & 0xff00) | ((val >> 8) & 0xff) + value = ((value << 8) & 0xff00) | ((value >> 8) & 0xff) try: self.bus.write_word_data(self.address, reg, value) if self.debug: