i2c

Dependencies:   mbed

Revision:
0:519691976fbc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jul 18 08:23:26 2020 +0000
@@ -0,0 +1,24 @@
+#include "mbed.h"
+ 
+// Read temperatures from Grid-EYE
+// note i2c stuff does not need a special ,h file
+ 
+I2C i2c(PTE0, PTE1);
+ 
+const int addr = 0x90;
+ 
+int main() {
+    char cmd[2];
+    while (1) {
+        cmd[0] = 0x01;
+        cmd[1] = 0x00;
+        i2c.write(addr, cmd, 2);
+        wait(0.5);
+      cmd[0] = 0x00;
+      i2c.write(addr, cmd, 1);
+      i2c.read(addr, cmd, 2);
+
+      float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
+      printf("Temp = %.2f\n", tmp);
+    }
+}
\ No newline at end of file