ADT7410 Temperature Sensor sample.

Dependencies:   mbed

About ADT7410

ADT7410 is a temperature sensor and can be controlled by using the I2C.

About sample program

This program outputs temperature data.
In order to run I2C communication with connecting GR-PEACH and the sensor, you will need to pull up.
Short jumper of GR-PEACH, leakage solder in two places of "PU" of the sensor base, or, add with the external resistor (10KΩ).

About wiring

SensorGR-PEACH
VDD3.3V
GNDGND
SCLD15
SDAD14
Committer:
1050186
Date:
Thu May 12 10:16:22 2016 +0000
Revision:
0:6e109b79e249
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
1050186 0:6e109b79e249 1 #include "mbed.h"
1050186 0:6e109b79e249 2 #include "ADT7410.h"
1050186 0:6e109b79e249 3
1050186 0:6e109b79e249 4 ADT7410::ADT7410(PinName sda, PinName scl) : i2c(sda, scl) {
1050186 0:6e109b79e249 5 // set config (16bit resolution)
1050186 0:6e109b79e249 6 send(ADT7410_CFG_ADDR, 0x80);
1050186 0:6e109b79e249 7 }
1050186 0:6e109b79e249 8
1050186 0:6e109b79e249 9 void ADT7410::send(char data_0, char data_1) {
1050186 0:6e109b79e249 10 buf[0] = data_0;
1050186 0:6e109b79e249 11 buf[1] = data_1;
1050186 0:6e109b79e249 12
1050186 0:6e109b79e249 13 i2c.write(ADT7410_I2C_ADDR, buf, 2);
1050186 0:6e109b79e249 14 }
1050186 0:6e109b79e249 15
1050186 0:6e109b79e249 16 void ADT7410::recv(char data) {
1050186 0:6e109b79e249 17 buf[0] = data;
1050186 0:6e109b79e249 18
1050186 0:6e109b79e249 19 // no stop condition (restared)
1050186 0:6e109b79e249 20 i2c.write(ADT7410_I2C_ADDR, buf, 1, true);
1050186 0:6e109b79e249 21 i2c.read(ADT7410_I2C_ADDR, buf, 2);
1050186 0:6e109b79e249 22 }
1050186 0:6e109b79e249 23
1050186 0:6e109b79e249 24 float ADT7410::temp_value() {
1050186 0:6e109b79e249 25 int temp;
1050186 0:6e109b79e249 26 float temp_fix;
1050186 0:6e109b79e249 27
1050186 0:6e109b79e249 28 // set config (16bit resolution with one shot mode)
1050186 0:6e109b79e249 29 send(ADT7410_CFG_ADDR, 0xA0);
1050186 0:6e109b79e249 30 wait_ms(250);
1050186 0:6e109b79e249 31 // recieve temperatue value(high and low)
1050186 0:6e109b79e249 32 recv(ADT7410_TMPH_ADDR);
1050186 0:6e109b79e249 33 temp = buf[0] << 0x08;
1050186 0:6e109b79e249 34 temp += buf[1];
1050186 0:6e109b79e249 35
1050186 0:6e109b79e249 36 if (temp & 0x8000) {
1050186 0:6e109b79e249 37 temp_fix = (float)(temp - 65536) / 128;
1050186 0:6e109b79e249 38 } else {
1050186 0:6e109b79e249 39 temp_fix = (float)temp / 128;
1050186 0:6e109b79e249 40 }
1050186 0:6e109b79e249 41
1050186 0:6e109b79e249 42 return temp_fix;
1050186 0:6e109b79e249 43 }