AND / Mbed 2 deprecated Sensor_si7051

Dependencies:   mbed

Committer:
christodoulos
Date:
Sun Jun 14 13:14:13 2020 +0000
Revision:
6:b5f2a1f5b91a
Parent:
5:97429a69bdcd
Si7051 (used in POCBreath_V2_smd_commercial)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
christodoulos 0:d034cdad5b6d 1 #include "mbed.h"
christodoulos 5:97429a69bdcd 2 //I2C bus for both ZMOD and temperature sensor
christodoulos 5:97429a69bdcd 3
christodoulos 6:b5f2a1f5b91a 4 Serial ttl(PC_12, PD_2);
christodoulos 6:b5f2a1f5b91a 5 I2C ZMODtemp(PB_9, PB_8);
christodoulos 6:b5f2a1f5b91a 6 DigitalOut red(PC_4);
christodoulos 6:b5f2a1f5b91a 7 DigitalOut amber(PC_5);
christodoulos 6:b5f2a1f5b91a 8 DigitalOut green(PB_0);
mehrnaz 2:ef98576cd67b 9 int main()
christodoulos 0:d034cdad5b6d 10 {
christodoulos 6:b5f2a1f5b91a 11 ttl.baud(115200); //baudrate for the serial connection, 9600 for hc05 115200 for rn
christodoulos 6:b5f2a1f5b91a 12
christodoulos 6:b5f2a1f5b91a 13 ttl.printf("$");//enter command mode only for rn
christodoulos 6:b5f2a1f5b91a 14 wait(0.5);
christodoulos 6:b5f2a1f5b91a 15 ttl.printf("$$");//enter command mode
christodoulos 6:b5f2a1f5b91a 16 wait(0.5);
christodoulos 6:b5f2a1f5b91a 17 ttl.printf("SN,Si7051\r");//set new name
christodoulos 6:b5f2a1f5b91a 18 wait(0.5);
christodoulos 6:b5f2a1f5b91a 19 ttl.printf("SS,C0\r");//set transparent uart
christodoulos 6:b5f2a1f5b91a 20 wait(0.5);
christodoulos 6:b5f2a1f5b91a 21 ttl.printf("&,4782CC640611\r");//Assign mac
christodoulos 6:b5f2a1f5b91a 22 wait(0.5);
christodoulos 6:b5f2a1f5b91a 23 ttl.printf("---\r");//enter data mode
christodoulos 6:b5f2a1f5b91a 24 wait(0.5);
christodoulos 6:b5f2a1f5b91a 25
christodoulos 6:b5f2a1f5b91a 26 int ZMODTEMPaddr=0x80; //si7050 8bit address
mehrnaz 3:3d51f8870e91 27
christodoulos 5:97429a69bdcd 28 char wTemp[1];
christodoulos 5:97429a69bdcd 29 wTemp[0]=0xE3; //Hold master mode
christodoulos 5:97429a69bdcd 30 char rTemp[2]; //Temperature returns MSB and LSB
christodoulos 5:97429a69bdcd 31 //assume MBS in rTemp[0] and LSB in rTemp[1]
mehrnaz 3:3d51f8870e91 32
christodoulos 5:97429a69bdcd 33 char wInit[2];
christodoulos 5:97429a69bdcd 34 wInit[0]=0xE6; //User register 1
christodoulos 5:97429a69bdcd 35 wInit[1]=0x00; //Set 14 bit resolution, other read-ony registers shouldn't be affected
mehrnaz 3:3d51f8870e91 36
christodoulos 6:b5f2a1f5b91a 37 ZMODtemp.write(ZMODTEMPaddr,wInit,2);
mehrnaz 2:ef98576cd67b 38
christodoulos 5:97429a69bdcd 39 while(1){
christodoulos 6:b5f2a1f5b91a 40 ZMODtemp.write(ZMODTEMPaddr,wInit,2); //maybe
christodoulos 6:b5f2a1f5b91a 41 ZMODtemp.write(ZMODTEMPaddr,wTemp,1);
christodoulos 6:b5f2a1f5b91a 42 ZMODtemp.read(ZMODTEMPaddr,rTemp,2); //Returns 2 bytes
christodoulos 5:97429a69bdcd 43 float temp_code=(rTemp[0]<<8)+rTemp[1];
christodoulos 5:97429a69bdcd 44 float temp=((175.72*temp_code)/65536)-46.85;
christodoulos 6:b5f2a1f5b91a 45 ttl.printf("Temp: %f\n",temp_code);
christodoulos 6:b5f2a1f5b91a 46 wait(1);
christodoulos 6:b5f2a1f5b91a 47 red=1;
christodoulos 6:b5f2a1f5b91a 48 amber=1;
christodoulos 6:b5f2a1f5b91a 49 green=1;
christodoulos 6:b5f2a1f5b91a 50 wait(2);
christodoulos 6:b5f2a1f5b91a 51 red=0;
christodoulos 6:b5f2a1f5b91a 52 amber=0;
christodoulos 6:b5f2a1f5b91a 53 green=0;
christodoulos 6:b5f2a1f5b91a 54 wait(2);
mehrnaz 2:ef98576cd67b 55 }
christodoulos 5:97429a69bdcd 56
mehrnaz 2:ef98576cd67b 57 }