temperature reading

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
212600191
Date:
Fri Aug 11 16:20:22 2017 +0000
Commit message:
temperature;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1f9fae46bbe1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 11 16:20:22 2017 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+ 
+// Read temperature from LM75BD
+
+I2C i2c(PB_9 , PB_8 ); 
+
+Serial pc (SERIAL_TX, SERIAL_RX);
+
+const int addr7bit = 0x48;      // 7 bit I2C address
+const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
+
+int main() {
+    pc.baud(250000);
+    char cmd[2];
+    while (1) {
+        cmd[0] = 0x01;
+        cmd[1] = 0x00;
+        i2c.write(addr8bit, cmd, 2);
+ 
+        wait(0.5);
+ 
+        cmd[0] = 0x00;
+        i2c.write(addr8bit, cmd, 1);
+        i2c.read( addr8bit, cmd, 2);
+ 
+        float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
+        printf("Temp = %.2f\r\n", tmp);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 1f9fae46bbe1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 11 16:20:22 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/fd96258d940d
\ No newline at end of file