i2c

Dependencies:   mbed

main.cpp

Committer:
qaz
Date:
2020-07-18
Revision:
0:519691976fbc

File content as of revision 0:519691976fbc:

#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);
    }
}