AND / Mbed 2 deprecated Sensor_si7051

Dependencies:   mbed

main.cpp

Committer:
christodoulos
Date:
2020-05-01
Revision:
5:97429a69bdcd
Parent:
3:3d51f8870e91
Child:
6:b5f2a1f5b91a

File content as of revision 5:97429a69bdcd:

#include "mbed.h"
#include "eco2.h"
//I2C bus for both ZMOD and temperature sensor
 
Serial pc(PC_12, PD_2); 
I2C i2c(PB_9, PB_8);
DigitalOut wake(PB_2);

uint16_t eco2, tvoc;

 
int main()
{
    int addr=0x80; //si7050 8bit address
    
    char wTemp[1];
    wTemp[0]=0xE3; //Hold master mode
    char rTemp[2]; //Temperature returns MSB and LSB
                    //assume MBS in rTemp[0] and LSB in rTemp[1]
    
    char wInit[2];
    wInit[0]=0xE6; //User register 1
    wInit[1]=0x00; //Set 14 bit resolution, other read-ony registers shouldn't be affected
    
    i2c.write(addr,wInit,2);
    
    while(1){
        i2c.write(addr,wTemp,1);
        i2c.read(addr,rTemp,2); //Returns 2 bytes
        float temp_code=(rTemp[0]<<8)+rTemp[1];
        float temp=((175.72*temp_code)/65536)-46.85;
        pc.printf("Temp: %f\n",temp);
        
    }
    
}