Read the Bosch BME680 sensor on Nuvoton NuMaker board

Committer:
morgandu
Date:
Tue Jun 09 02:35:34 2020 +0000
Revision:
0:a0e92a018ff2
Child:
1:6dd878905b5c
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
morgandu 0:a0e92a018ff2 1 #include "mbed.h"
morgandu 0:a0e92a018ff2 2 #include "mbed_bme680.h"
morgandu 0:a0e92a018ff2 3
morgandu 0:a0e92a018ff2 4 #if TARGET_NUMAKER_IOT_M263A
morgandu 0:a0e92a018ff2 5 I2C sensor_i2c(PD_4, PD_5);
morgandu 0:a0e92a018ff2 6 #else
morgandu 0:a0e92a018ff2 7 I2C sensor_i2c(I2C_SDA, I2C_SCL); // Used inside the BME680 Mbed Lib.
morgandu 0:a0e92a018ff2 8 #endif
morgandu 0:a0e92a018ff2 9
morgandu 0:a0e92a018ff2 10 BME680 bme680(0x76 << 1);
morgandu 0:a0e92a018ff2 11
morgandu 0:a0e92a018ff2 12 int main()
morgandu 0:a0e92a018ff2 13 {
morgandu 0:a0e92a018ff2 14 int count = 10;
morgandu 0:a0e92a018ff2 15
morgandu 0:a0e92a018ff2 16 if (!bme680.begin()) {
morgandu 0:a0e92a018ff2 17 printf("BME680 Begin failed \r\n");
morgandu 0:a0e92a018ff2 18 return 1;
morgandu 0:a0e92a018ff2 19 }
morgandu 0:a0e92a018ff2 20
morgandu 0:a0e92a018ff2 21 while (true) {
morgandu 0:a0e92a018ff2 22 if (++count >= 10)
morgandu 0:a0e92a018ff2 23 {
morgandu 0:a0e92a018ff2 24 count = 0;
morgandu 0:a0e92a018ff2 25 printf("\r\nTemperature Humidity Pressure VOC\r\n"
morgandu 0:a0e92a018ff2 26 " degC %% hPa KOhms\r\n"
morgandu 0:a0e92a018ff2 27 "------------------------------------------\r\n");
morgandu 0:a0e92a018ff2 28 }
morgandu 0:a0e92a018ff2 29
morgandu 0:a0e92a018ff2 30 if (bme680.performReading())
morgandu 0:a0e92a018ff2 31 {
morgandu 0:a0e92a018ff2 32 printf(" %.2f ", bme680.getTemperature());
morgandu 0:a0e92a018ff2 33 printf("%.2f ", bme680.getHumidity());
morgandu 0:a0e92a018ff2 34 printf("%.2f ", bme680.getPressure() / 100.0);
morgandu 0:a0e92a018ff2 35 printf("%0.2f\r\n", bme680.getGasResistance() / 1000.0);
morgandu 0:a0e92a018ff2 36 }
morgandu 0:a0e92a018ff2 37
morgandu 0:a0e92a018ff2 38 thread_sleep_for(1000);
morgandu 0:a0e92a018ff2 39 }
morgandu 0:a0e92a018ff2 40 }