71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
#include "Arduino.h"
|
|
#include "bme68xLibrary.h"
|
|
//#include "bsec2.h"
|
|
|
|
|
|
Bme68x bme;
|
|
//Bsec2 bsec;
|
|
|
|
|
|
void setup(void)
|
|
{
|
|
Serial.println("Startin setup.");
|
|
Wire.begin(14, 8); // SDA, SCL
|
|
Wire.setClock(100000); // Set I2C clock speed to 100kHz
|
|
Serial.begin(115200);
|
|
|
|
while (!Serial)
|
|
delay(10);
|
|
|
|
/* initializes the sensor based on Wire library */
|
|
bme.begin(BME68X_I2C_ADDR_HIGH, Wire); // BME68X_I2C_ADDR_HIGH=0x76, BME68X_I2C_ADDR_LOW=0x77
|
|
|
|
if(bme.checkStatus())
|
|
{
|
|
if (bme.checkStatus() == BME68X_ERROR)
|
|
{
|
|
Serial.println("Sensor error:" + bme.statusString());
|
|
return;
|
|
}
|
|
else if (bme.checkStatus() == BME68X_WARNING)
|
|
{
|
|
Serial.println("Sensor Warning:" + bme.statusString());
|
|
}
|
|
}
|
|
|
|
/* Set the default configuration for temperature, pressure and humidity */
|
|
bme.setTPH();
|
|
|
|
/* Set the heater configuration to 300 deg C for 100ms for Forced mode */
|
|
bme.setHeaterProf(300, 100);
|
|
|
|
// Set the temperature profile
|
|
//const uint8_t numSteps = 5;
|
|
//const uint16_t temperatures[] = {200, 250, 300, 350, 400}; // temperatures in degrees Celsius
|
|
//const uint16_t durations[] = {100, 200, 300, 400, 500}; // durations in milliseconds
|
|
//bme.setHeaterProfile(numSteps, temperatures, durations);
|
|
|
|
|
|
Serial.println("TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status");
|
|
}
|
|
|
|
void loop(void)
|
|
{
|
|
bme68xData data;
|
|
|
|
bme.setOpMode(BME68X_FORCED_MODE);
|
|
delayMicroseconds(bme.getMeasDur());
|
|
|
|
if (bme.fetchData())
|
|
{
|
|
bme.getData(data);
|
|
Serial.print(String(millis()) + ", ");
|
|
Serial.print(String(data.temperature) + ", ");
|
|
Serial.print(String(data.pressure) + ", ");
|
|
Serial.print(String(data.humidity) + ", ");
|
|
Serial.print(String(data.gas_resistance) + ", ");
|
|
Serial.println(data.status, HEX);
|
|
delay(1000);
|
|
}
|
|
}
|