Library for ADT7410 I2C temperature sensor. Use this instead of TMP102 when you need to measure temperatures lower than -40 degrees C. The device is guaranteed to work at -55 C but will actually read lower temps. See http://mbed.org/users/tkreyche/notebook/adt7140-i2c-temperature-sensor/ for more info.

Dependents:   BLE_ADT7410_TMP102_Sample BLE_HTM_HRM1017 BLENano_SimpleTemplate_temp_170802 BLENano_SimpleTemplate_temp_170813 ... more

Files at this revision

API Documentation at this revision

Comitter:
tkreyche
Date:
Tue Feb 01 18:57:41 2011 +0000
Child:
1:257d9e026cc4
Commit message:

Changed in this revision

ADT7410.cpp Show annotated file Show diff for this revision Revisions of this file
ADT7410.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADT7410.cpp	Tue Feb 01 18:57:41 2011 +0000
@@ -0,0 +1,73 @@
+#include "ADT7410.h"
+
+
+ // constructor taks paramters and initializes I2C bus
+ADT7410::ADT7410(PinName sda, PinName scl, char addr, int hz)
+        : i2c(sda, scl)
+        , busAddr(addr)
+{
+    i2c.frequency(hz);
+}
+
+// destructor
+ADT7410::~ADT7410() {
+}
+
+// read 13 bit temperature
+float ADT7410::getTemp() {
+
+    char wReg[1] = {TEMP_REG_ADDR};
+    char rReg[2] = {0,0};
+    float tFin = 0;
+    int tRaw = 0;
+
+    // set address pointer to temperature register
+    i2c.write(busAddr, wReg, 1);
+
+    // read temperature register, two bytes
+    i2c.read(busAddr, rReg, 2);
+
+    // temperature returned is only 13 bits
+    // discard alarm flags in lower bits
+    tRaw = (rReg[0] << 8) | (rReg[1]);
+    tRaw >>= 3;
+
+    // handle positive and negative temperatures
+    // results in two's complement
+    if ( tRaw & 0x1000) {
+        tFin = (float) (tRaw - 8192) / 16;
+    } else {
+        tFin = (float) tRaw  / 16;
+    }
+     
+    return tFin;
+}
+
+void ADT7410::setConfig(char regVal) {
+
+    char wReg[2] = {CONFIG_REG_ADDR, regVal};
+    i2c.write(busAddr, wReg, 2);
+    return;
+}
+
+char ADT7410::getConfig() {
+
+    char rReg[1] = {0};
+    char wReg[1] = {CONFIG_REG_ADDR};
+    // need to add repeat to supress stop
+   i2c.write(busAddr, wReg, 1, 1); 
+   i2c.read(busAddr, rReg, 1);
+    return rReg[0];
+}
+
+
+// reset the sensor
+void ADT7410::reset() {
+
+    char wReg[1] = {RESET};
+    i2c.write(busAddr, wReg, 1);
+    // wait for sensor to reload and convert
+    wait_ms(250);
+    return;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADT7410.h	Tue Feb 01 18:57:41 2011 +0000
@@ -0,0 +1,105 @@
+/*
+Copyright (c) 2011 Tom Kreyche tkreyche@well.com
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+  
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+  
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+/** Servo control class, based on a PwmOut
+*
+* Example:
+* @code
+
+#include "mbed.h"
+#include "ADT7410.h"
+
+ADT7410 tempSens1(p28, p27, 0x90, 100000);
+
+int main() {
+
+    // reset sensor to default values
+   tempSens1.reset();
+    
+    // read the config register, should be default
+   printf("Config: 0x%x\n", tempSens1.getConfig());
+    
+    // reduce sample rate to save power
+   tempSens1.setConfig(ONE_SPS_MODE);
+    
+    // check config register was set correctly
+   printf("Config: 0x%x\n", tempSens1.getConfig());
+    
+    // get temperature every two seconds
+    while (1) {
+    
+        printf("Deg C %f\n", tempSens1.getTemp());
+        wait(2);
+    }
+}
+
+* @endcode
+*/
+
+#ifndef ADT7410_H
+#define ADT7410_H
+
+#include "mbed.h"
+
+// sensor register addresses
+// only a partial list, don't use them all
+#define TEMP_REG_ADDR 0x00
+#define CONFIG_REG_ADDR 0x03
+#define RESET 0x2F
+
+// configuration register values
+// only a partial list, don't use them all
+#define ONE_SPS_MODE 0x40
+
+//Library for the ADT7410 temperature sensor
+
+class ADT7410
+{
+
+public:
+
+  // Creates an instance of the class.
+  // Connect module at I2C address addr using I2C port pins sda and scl
+  ADT7410(PinName sda, PinName scl, char addr, int hz);
+  
+  //Destroys instance.
+  ~ADT7410();
+  
+  //Reads the current temperature.
+  float getTemp();
+  
+  //Set config register
+  void setConfig(char regVal);
+  
+   //Get config register
+  char getConfig(); 
+  
+  //Send reset
+  void reset();
+  
+private:
+  I2C i2c;
+  char busAddr;
+
+};
+
+#endif