Abdul Haseeb Khalid
/
example-sensirion-ublox-c030
example program to demonstrate usage of sensirion ess with ublox-c030
main.cpp@0:4fd0369caf7e, 2018-12-21 (annotated)
- Committer:
- Haseeb Khalid
- Date:
- Fri Dec 21 17:41:16 2018 +0500
- Revision:
- 0:4fd0369caf7e
Example program to demonstrate the usage of sensirion-ess with ublox-c030
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Haseeb Khalid |
0:4fd0369caf7e | 1 | /* mbed Microcontroller Library |
Haseeb Khalid |
0:4fd0369caf7e | 2 | * Copyright (c) 2018 u-blox AG |
Haseeb Khalid |
0:4fd0369caf7e | 3 | * |
Haseeb Khalid |
0:4fd0369caf7e | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Haseeb Khalid |
0:4fd0369caf7e | 5 | * you may not use this file except in compliance with the License. |
Haseeb Khalid |
0:4fd0369caf7e | 6 | * You may obtain a copy of the License at |
Haseeb Khalid |
0:4fd0369caf7e | 7 | * |
Haseeb Khalid |
0:4fd0369caf7e | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Haseeb Khalid |
0:4fd0369caf7e | 9 | * |
Haseeb Khalid |
0:4fd0369caf7e | 10 | * Unless required by applicable law or agreed to in writing, software |
Haseeb Khalid |
0:4fd0369caf7e | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Haseeb Khalid |
0:4fd0369caf7e | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Haseeb Khalid |
0:4fd0369caf7e | 13 | * See the License for the specific language governing permissions and |
Haseeb Khalid |
0:4fd0369caf7e | 14 | * limitations under the License. |
Haseeb Khalid |
0:4fd0369caf7e | 15 | */ |
Haseeb Khalid |
0:4fd0369caf7e | 16 | |
Haseeb Khalid |
0:4fd0369caf7e | 17 | #include "mbed.h" |
Haseeb Khalid |
0:4fd0369caf7e | 18 | #include "sensirion_ess.h" |
Haseeb Khalid |
0:4fd0369caf7e | 19 | I2C i2c(D14,D15); |
Haseeb Khalid |
0:4fd0369caf7e | 20 | SensirionESS sensirionESS(&i2c); |
Haseeb Khalid |
0:4fd0369caf7e | 21 | int main() |
Haseeb Khalid |
0:4fd0369caf7e | 22 | { |
Haseeb Khalid |
0:4fd0369caf7e | 23 | printf("u-blox C030 Demo with Sensirion Environmental Sensor Shield\r\n"); |
Haseeb Khalid |
0:4fd0369caf7e | 24 | |
Haseeb Khalid |
0:4fd0369caf7e | 25 | if (sensirionESS.initSensors() != 0) { |
Haseeb Khalid |
0:4fd0369caf7e | 26 | printf("Error while initializing sensors: %s\n",sensirionESS.getError()); |
Haseeb Khalid |
0:4fd0369caf7e | 27 | return -1; |
Haseeb Khalid |
0:4fd0369caf7e | 28 | } |
Haseeb Khalid |
0:4fd0369caf7e | 29 | sensirionESS.setLedRYG(1,1,1); |
Haseeb Khalid |
0:4fd0369caf7e | 30 | printf("Sensirion ESS initialized successfully..\r\n"); |
Haseeb Khalid |
0:4fd0369caf7e | 31 | printf("Detected sensor %s on kit\r\n", sensirionESS.getProductType() ? "SGPC3" : "SGP30"); |
Haseeb Khalid |
0:4fd0369caf7e | 32 | wait(3); |
Haseeb Khalid |
0:4fd0369caf7e | 33 | |
Haseeb Khalid |
0:4fd0369caf7e | 34 | while (1){ |
Haseeb Khalid |
0:4fd0369caf7e | 35 | if (sensirionESS.measureIAQ() !=0){ |
Haseeb Khalid |
0:4fd0369caf7e | 36 | printf("Error reading IAQ: %s\r\n",sensirionESS.getError()); |
Haseeb Khalid |
0:4fd0369caf7e | 37 | return -1; |
Haseeb Khalid |
0:4fd0369caf7e | 38 | } |
Haseeb Khalid |
0:4fd0369caf7e | 39 | if (sensirionESS.measureRHT()!=0) { |
Haseeb Khalid |
0:4fd0369caf7e | 40 | printf("Error reading RHT: %s\n",sensirionESS.getError()); |
Haseeb Khalid |
0:4fd0369caf7e | 41 | return -1; |
Haseeb Khalid |
0:4fd0369caf7e | 42 | } |
Haseeb Khalid |
0:4fd0369caf7e | 43 | printf("Temperature: %.2f Humidity: %.2f\n" |
Haseeb Khalid |
0:4fd0369caf7e | 44 | "tVOC Concentration: %.2fppb CO2eq Concentration: %.2fppm\r\n",sensirionESS.getTemperature(),sensirionESS.getHumidity(),\ |
Haseeb Khalid |
0:4fd0369caf7e | 45 | sensirionESS.getTVOC(),sensirionESS.getECO2()); |
Haseeb Khalid |
0:4fd0369caf7e | 46 | wait(1); |
Haseeb Khalid |
0:4fd0369caf7e | 47 | } |
Haseeb Khalid |
0:4fd0369caf7e | 48 | } |