Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added I2C variants of the code #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions examples_I2C/forced_mode/forced_mode.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (C) 2021 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/

#include "Arduino.h"
#include "bme68xLibrary.h"

#define BME688_ADD 0x77

Bme68x bme;

/**
* @brief Initializes the sensor and hardware settings
*/
void setup(void)
{
Wire.begin();
Serial.begin(115200);

while (!Serial)
delay(10);

/* initializes the sensor based on SPI library */
bme.begin(BME688_ADD, Wire);

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);

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);
}
}
87 changes: 87 additions & 0 deletions examples_I2C/parallel_mode/parallel_mode.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright (C) 2021 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/

#include "Arduino.h"
#include "bme68xLibrary.h"

#define NEW_GAS_MEAS (BME68X_GASM_VALID_MSK | BME68X_HEAT_STAB_MSK | BME68X_NEW_DATA_MSK)
#define MEAS_DUR 140

#define BME688_ADD 0x77

Bme68x bme;

/**
* @brief Initializes the sensor and hardware settings
*/
void setup(void)
{
Wire.begin();
Serial.begin(115200);

while (!Serial)
delay(10);

/* initializes the sensor based on SPI library */
bme.begin(BME688_ADD, Wire);

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();

/* Heater temperature in degree Celsius */
uint16_t tempProf[10] = { 320, 100, 100, 100, 200, 200, 200, 320, 320,
320 };
/* Multiplier to the shared heater duration */
uint16_t mulProf[10] = { 5, 2, 10, 30, 5, 5, 5, 5, 5, 5 };
/* Shared heating duration in milliseconds */
uint16_t sharedHeatrDur = MEAS_DUR - (bme.getMeasDur(BME68X_PARALLEL_MODE) / 1000);

bme.setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10);
bme.setOpMode(BME68X_PARALLEL_MODE);

Serial.println("TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status, Gas index");
}

void loop(void)
{
bme68xData data;
uint8_t nFieldsLeft = 0;

/* data being fetched for every 140ms */
delay(MEAS_DUR);

if (bme.fetchData())
{
do
{
nFieldsLeft = bme.getData(data);
if (data.status == NEW_GAS_MEAS)
{
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.print(String(data.status, HEX) + ", ");
Serial.println(data.gas_index);
}
} while (nFieldsLeft);
}
}
85 changes: 85 additions & 0 deletions examples_I2C/sequential_mode/sequential_mode.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (C) 2021 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/

#include "Arduino.h"
#include "bme68xLibrary.h"

#define NEW_GAS_MEAS (BME68X_GASM_VALID_MSK | BME68X_HEAT_STAB_MSK | BME68X_NEW_DATA_MSK)

#define BME688_ADD 0x77

Bme68x bme;

/**
* @brief Initializes the sensor and hardware settings
*/
void setup(void)
{
Wire.begin();
Serial.begin(115200);

while (!Serial)
delay(10);

/* Initializes the sensor based on SPI library */
bme.begin(BME688_ADD, Wire);

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();

/* Heater temperature in degree Celsius */
uint16_t tempProf[10] = { 100, 200, 320 };
/* Heating duration in milliseconds */
uint16_t durProf[10] = { 150, 150, 150 };

bme.setSeqSleep(BME68X_ODR_250_MS);
bme.setHeaterProf(tempProf, durProf, 3);
bme.setOpMode(BME68X_SEQUENTIAL_MODE);

Serial.println("TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status, Gas index");
}

void loop(void)
{
bme68xData data;
uint8_t nFieldsLeft = 0;

delay(150);

if (bme.fetchData())
{
do
{
nFieldsLeft = bme.getData(data);
//if (data.status == NEW_GAS_MEAS)
{
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.print(String(data.status, HEX) + ", ");
Serial.println(data.gas_index);
if(data.gas_index == 2) /* Sequential mode sleeps after this measurement */
delay(250);
}
} while (nFieldsLeft);
}
}