Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX31855 SDFileSystem mbed
Revision 0:42e8fa13c7a9, committed 2016-03-03
- Comitter:
- DanielBlomdahl
- Date:
- Thu Mar 03 16:24:22 2016 +0000
- Child:
- 1:8116bd9d3c46
- Commit message:
- Initial copy-and-paste from Dr. Larkin. Includes capability for more than one thermometer.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP102.cpp Thu Mar 03 16:24:22 2016 +0000
@@ -0,0 +1,30 @@
+#include "TMP102.h"
+
+#define TEMP_REG_ADDR 0x00
+
+TMP102::TMP102(I2C i2c, int addr) : m_i2c(i2c), m_addr(addr)
+{
+
+}
+
+TMP102::~TMP102()
+{
+
+}
+
+float TMP102::read()
+{
+
+ const char tempRegAddr = TEMP_REG_ADDR;
+
+ m_i2c.write(m_addr, &tempRegAddr, 1); //Pointer to the temperature register
+
+ char reg[2] = {0,0};
+ m_i2c.read(m_addr, reg, 2); //Rea
+
+ int16_t res = ((int8_t)reg[0] << 4) | ((uint8_t)reg[1] >> 4);
+
+ float temp = (float) ((float)res * 0.0625);
+
+ return temp;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP102.h Thu Mar 03 16:24:22 2016 +0000
@@ -0,0 +1,38 @@
+#ifndef TMP102_H
+#define TMP102_H
+
+#include "mbed.h"
+
+//!Library for the TI TMP102 temperature sensor.
+/*!
+The TMP102 is an I2C digital temperature sensor in a small SOT563 package, with a 0.0625C resolution and 0.5C accuracy.
+*/
+class TMP102
+{
+public:
+ //!Creates an instance of the class.
+ /*!
+ Connect module at I2C address addr using I2C port pins sda and scl.
+ TMP102
+ \param addr <table><tr><th>A0 pin connection</th><th>Address</th></tr><tr><td>GND</td><td>0x90</td></tr><tr><td>V+</td><td>0x92</td></tr><tr><td>SDA</td><td>0x94</td></tr><tr><td>SCL</td><td>0x96</td></tr></table>
+ */
+ TMP102(I2C i2c, int addr);
+
+ /*!
+ Destroys instance.
+ */
+ ~TMP102();
+
+ //!Reads the current temperature.
+ /*!
+ Reads the temperature register of the TMP102 and converts it to a useable value.
+ */
+ float read();
+
+private:
+ I2C m_i2c;
+ int m_addr;
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Mar 03 16:24:22 2016 +0000
@@ -0,0 +1,18 @@
+#include "mbed.h"
+#include "TMP102.h"
+
+I2C i2c(PTE25, PTE24);
+TMP102 temperature(i2c,0x90); // i2c, address
+/* The TMP102 board has an address of 0x90 if ADD0 is connected to ground */
+
+Serial pc(USBTX,USBRX);
+
+int main()
+{
+ float currentTemp;
+ while (true) {
+ currentTemp = temperature.read();
+ pc.printf("T = %.2fC\r\n", currentTemp);
+ wait(0.5);
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 03 16:24:22 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb \ No newline at end of file
