Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@5:3ba375562c74, 2020-05-01 (annotated)
- Committer:
- christodoulos
- Date:
- Fri May 01 14:30:55 2020 +0000
- Revision:
- 5:3ba375562c74
- Parent:
- 3:3d51f8870e91
CCS811 (NOT USED in POCBreath_V2_smd_commercial)
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| christodoulos | 0:d034cdad5b6d | 1 | #include "mbed.h" |
| christodoulos | 5:3ba375562c74 | 2 | |
| christodoulos | 5:3ba375562c74 | 3 | Serial pc(PC_12, PD_2); |
| christodoulos | 5:3ba375562c74 | 4 | I2C i2c(PC_1,PC_0); |
| christodoulos | 5:3ba375562c74 | 5 | DigitalOut wake(PB_2); |
| christodoulos | 0:d034cdad5b6d | 6 | |
| christodoulos | 5:3ba375562c74 | 7 | uint16_t eco2, tvoc; |
| christodoulos | 0:d034cdad5b6d | 8 | |
| christodoulos | 5:3ba375562c74 | 9 | |
| mehrnaz | 2:ef98576cd67b | 10 | int main() |
| christodoulos | 0:d034cdad5b6d | 11 | { |
| christodoulos | 5:3ba375562c74 | 12 | int addr=0xB4; |
| christodoulos | 5:3ba375562c74 | 13 | wake=0; |
| christodoulos | 5:3ba375562c74 | 14 | // FIRST NEED TO INIT TO APP_START |
| christodoulos | 5:3ba375562c74 | 15 | //CHECK SYSTEM 1, PUT IN APP MODE, CECK SYSTEM 2, SET MODE |
| mehrnaz | 3:3d51f8870e91 | 16 | |
| christodoulos | 5:3ba375562c74 | 17 | char wID[1]; |
| christodoulos | 5:3ba375562c74 | 18 | wID[0]=0x20; |
| christodoulos | 5:3ba375562c74 | 19 | char rID[1]; |
| mehrnaz | 3:3d51f8870e91 | 20 | |
| christodoulos | 5:3ba375562c74 | 21 | i2c.write(addr,wID,1); |
| christodoulos | 5:3ba375562c74 | 22 | i2c.read(addr,rID,1); |
| christodoulos | 5:3ba375562c74 | 23 | pc.printf("ID: %x\n",rID[0]); |
| christodoulos | 5:3ba375562c74 | 24 | wait(1); |
| christodoulos | 5:3ba375562c74 | 25 | |
| christodoulos | 5:3ba375562c74 | 26 | char wS[1]; |
| christodoulos | 5:3ba375562c74 | 27 | wS[0]=0x00; |
| christodoulos | 5:3ba375562c74 | 28 | char rS[1]; |
| mehrnaz | 3:3d51f8870e91 | 29 | |
| christodoulos | 5:3ba375562c74 | 30 | i2c.write(addr,wS,1); |
| christodoulos | 5:3ba375562c74 | 31 | i2c.read(addr,rS,1); |
| christodoulos | 5:3ba375562c74 | 32 | pc.printf("Status before init: %x\n",rS[0]); |
| christodoulos | 5:3ba375562c74 | 33 | wait(1); |
| mehrnaz | 3:3d51f8870e91 | 34 | |
| christodoulos | 5:3ba375562c74 | 35 | char wInit[2]; |
| christodoulos | 5:3ba375562c74 | 36 | wInit[0]=0xF4; |
| christodoulos | 5:3ba375562c74 | 37 | // wInit[1]=0x00; |
| christodoulos | 5:3ba375562c74 | 38 | // char rInit[1]; |
| christodoulos | 5:3ba375562c74 | 39 | |
| christodoulos | 5:3ba375562c74 | 40 | i2c.write(addr,wInit,1); |
| christodoulos | 5:3ba375562c74 | 41 | wait(1); |
| christodoulos | 5:3ba375562c74 | 42 | |
| christodoulos | 5:3ba375562c74 | 43 | i2c.write(addr,wS,1); |
| christodoulos | 5:3ba375562c74 | 44 | i2c.read(addr,rS,1); |
| christodoulos | 5:3ba375562c74 | 45 | pc.printf("Status after init: %x\n",rS[0]); |
| christodoulos | 5:3ba375562c74 | 46 | wait(2); |
| christodoulos | 5:3ba375562c74 | 47 | |
| christodoulos | 5:3ba375562c74 | 48 | char wMode[2]; |
| christodoulos | 5:3ba375562c74 | 49 | wMode[0]=0x01; |
| christodoulos | 5:3ba375562c74 | 50 | wMode[1]=0x40; |
| christodoulos | 5:3ba375562c74 | 51 | char rMode[1]; |
| christodoulos | 5:3ba375562c74 | 52 | |
| christodoulos | 5:3ba375562c74 | 53 | i2c.write(addr,wMode,2); |
| christodoulos | 5:3ba375562c74 | 54 | i2c.read(addr,rMode,1); |
| christodoulos | 5:3ba375562c74 | 55 | pc.printf("Mode: %x\n",rMode[0]); |
| christodoulos | 5:3ba375562c74 | 56 | wait(1); |
| christodoulos | 5:3ba375562c74 | 57 | |
| christodoulos | 5:3ba375562c74 | 58 | char wE[1]; |
| christodoulos | 5:3ba375562c74 | 59 | wE[0]=0xE0; |
| christodoulos | 5:3ba375562c74 | 60 | char rE[1]; |
| christodoulos | 5:3ba375562c74 | 61 | |
| christodoulos | 5:3ba375562c74 | 62 | char wData[1]; |
| christodoulos | 5:3ba375562c74 | 63 | wData[0]=0x02; |
| christodoulos | 5:3ba375562c74 | 64 | char rData[6]; |
| christodoulos | 5:3ba375562c74 | 65 | |
| christodoulos | 5:3ba375562c74 | 66 | |
| christodoulos | 5:3ba375562c74 | 67 | while(1){ |
| christodoulos | 5:3ba375562c74 | 68 | i2c.write(addr,wData,1); //co2 and tvoc |
| christodoulos | 5:3ba375562c74 | 69 | i2c.read(addr,rData,6); |
| christodoulos | 5:3ba375562c74 | 70 | |
| christodoulos | 5:3ba375562c74 | 71 | int CO2=(rData[0]<<8)+rData[1]; |
| christodoulos | 5:3ba375562c74 | 72 | int TVOC=(rData[2]<<8)+rData[3]; |
| christodoulos | 5:3ba375562c74 | 73 | |
| christodoulos | 5:3ba375562c74 | 74 | |
| christodoulos | 5:3ba375562c74 | 75 | pc.printf("CO2: %i ppm, TVOC: %i ppb,Status: %x, Error: %x\n",CO2,TVOC,rData[4],rData[5]); |
| christodoulos | 5:3ba375562c74 | 76 | wait(0.1); |
| mehrnaz | 2:ef98576cd67b | 77 | } |
| christodoulos | 5:3ba375562c74 | 78 | |
| mehrnaz | 2:ef98576cd67b | 79 | } |