Skip to content

Commit

Permalink
Update/sensor api 4.4.8 (#6)
Browse files Browse the repository at this point in the history
* Sensor API update

Updated to the latest sensor api version 4.4.8.
SD card access library changed to SdFat.

* Update bme688_dev_kit.ino

Removed unused macros
  • Loading branch information
Deepak-Mvk authored Jun 5, 2024
1 parent 16984f4 commit bdd6052
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 71 deletions.
30 changes: 17 additions & 13 deletions examples/bme688_dev_kit/bme688_dev_kit.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
*/

#include "Arduino.h"
#include "FS.h"
#include "bme68xLibrary.h"
#include "commMux.h"
#include <SD.h>

#include <SdFat.h>
#include <Esp.h>

/* Macros used in BME68x_datalogger module */
#define N_KIT_SENS 8
#define SD_PIN_CS 33
#define SPI_COMM_SPEED 32000000
#define SD_MAX_FILES 5
#define PANIC_LED LED_BUILTIN
#define PANIC_DUR 1000
/* measurement duration */
Expand All @@ -39,6 +38,8 @@ bme68xData sensorData[N_KIT_SENS] = {0};
String logHeader;
uint32_t lastLogged = 0;

static SdFat sd;

/**
* @brief Initializes the sensor and hardware settings
* Initializes the SD card module
Expand All @@ -51,13 +52,14 @@ void setup(void) {
delay(100);

/* Setting SD Card */
if (!SD.begin(SD_PIN_CS, SPI, SPI_COMM_SPEED, "/sd", SD_MAX_FILES)) {
if (!sd.begin(SD_PIN_CS, SPI_EIGHTH_SPEED)) {
Serial.println("SD Card not found");
panicLeds();
} else {
SD.remove(LOG_FILE_NAME);
File file = SD.open(LOG_FILE_NAME, "w");
if (!file) {
sd.remove(LOG_FILE_NAME);
File file;

if (!file.open(LOG_FILE_NAME, (O_RDWR | O_CREAT))) {
Serial.println("Failed to open file for writing");
panicLeds();
}
Expand Down Expand Up @@ -97,7 +99,7 @@ void setup(void) {
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[i].getMeasDur(BME68X_PARALLEL_MODE);
MEAS_DUR - (bme[i].getMeasDur(BME68X_PARALLEL_MODE) / INT64_C(1000));

bme[i].setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10);

Expand Down Expand Up @@ -196,8 +198,9 @@ static void panicLeds(void) {
*/
static void writeFile(String sensorData) {

File file = SD.open(LOG_FILE_NAME, FILE_WRITE);
if (!file) {
File file;

if (!file.open(LOG_FILE_NAME, (O_RDWR | O_AT_END))) {
Serial.println("Failed to open file for writing");
panicLeds();
}
Expand All @@ -214,8 +217,9 @@ static void writeFile(String sensorData) {
* @param sensorData
*/
static void appendFile(String sensorData) {
File file = SD.open(LOG_FILE_NAME, FILE_APPEND);
if (!file) {
File file;

if (!file.open(LOG_FILE_NAME, (O_RDWR | O_AT_END))) {
Serial.println("Failed to open file for appending");
panicLeds();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/bme688_dev_kit/commMux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
POSSIBILITY OF SUCH DAMAGE.
@file commMux.cpp
@date 8 Feb 2022
@version 1.1.40407
@date 11 Jan 2023
@version 1.2.40408
*/

Expand Down
4 changes: 2 additions & 2 deletions examples/bme688_dev_kit/commMux.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
POSSIBILITY OF SUCH DAMAGE.
@file commMux.h
@date 8 Feb 2022
@version 1.1.40407
@date 11 Jan 2023
@version 1.2.40408
*/
#ifndef COMM_MUX_H
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=BME68x Sensor library
version=1.1.40407
version=1.2.40408
author=Bosch Sensortec
maintainer=Bosch Sensortec <contact@bosch-sensortec.com>
sentence=Bosch Sensortec BME680 and BME688 sensor library
Expand Down
2 changes: 1 addition & 1 deletion src/bme68x/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.

BSD-3-Clause

Expand Down
93 changes: 51 additions & 42 deletions src/bme68x/bme68x.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
Expand Down Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68x.c
* @date 2021-11-09
* @version v4.4.7
* @date 2023-02-07
* @version v4.4.8
*
*/

Expand Down Expand Up @@ -145,28 +145,27 @@ int8_t bme68x_init(struct bme68x_dev *dev)
{
int8_t rslt;

rslt = bme68x_soft_reset(dev);
(void) bme68x_soft_reset(dev);

rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev);

if (rslt == BME68X_OK)
{
rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev);
if (rslt == BME68X_OK)
if (dev->chip_id == BME68X_CHIP_ID)
{
if (dev->chip_id == BME68X_CHIP_ID)
{
/* Read Variant ID */
rslt = read_variant_id(dev);
/* Read Variant ID */
rslt = read_variant_id(dev);

if (rslt == BME68X_OK)
{
/* Get the Calibration data */
rslt = get_calib_data(dev);
}
}
else
if (rslt == BME68X_OK)
{
rslt = BME68X_E_DEV_NOT_FOUND;
/* Get the Calibration data */
rslt = get_calib_data(dev);
}
}
else
{
rslt = BME68X_E_DEV_NOT_FOUND;
}
}

return rslt;
Expand Down Expand Up @@ -289,10 +288,11 @@ int8_t bme68x_soft_reset(struct bme68x_dev *dev)
{
rslt = bme68x_set_regs(&reg_addr, &soft_rst_cmd, 1, dev);

/* Wait for 5ms */
dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr);
if (rslt == BME68X_OK)
{
/* Wait for 5ms */
dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr);

/* After reset get the memory page */
if (dev->intf == BME68X_SPI_INTF)
{
Expand Down Expand Up @@ -681,39 +681,41 @@ int8_t bme68x_set_heatr_conf(uint8_t op_mode, const struct bme68x_heatr_conf *co
return rslt;
}

/*
/*!
* @brief This API is used to get the gas configuration of the sensor.
*/
int8_t bme68x_get_heatr_conf(const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev)
{
int8_t rslt;
int8_t rslt = BME68X_OK;
uint8_t data_array[10] = { 0 };
uint8_t i;

/* FIXME: Add conversion to deg C and ms and add the other parameters */
rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev);
if (rslt == BME68X_OK)
if ((conf != NULL) && (conf->heatr_dur_prof != NULL) && (conf->heatr_temp_prof != NULL))
{
if (conf && conf->heatr_dur_prof && conf->heatr_temp_prof)
/* FIXME: Add conversion to deg C and ms and add the other parameters */
rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev);

if (rslt == BME68X_OK)
{
for (i = 0; i < 10; i++)
for (i = 0; i < conf->profile_len; i++)
{
conf->heatr_temp_prof[i] = data_array[i];
}

rslt = bme68x_get_regs(BME68X_REG_GAS_WAIT0, data_array, 10, dev);

if (rslt == BME68X_OK)
{
for (i = 0; i < 10; i++)
for (i = 0; i < conf->profile_len; i++)
{
conf->heatr_dur_prof[i] = data_array[i];
}
}
}
else
{
rslt = BME68X_E_NULL_PTR;
}
}
else
{
rslt = BME68X_E_NULL_PTR;
}

return rslt;
Expand All @@ -732,14 +734,21 @@ int8_t bme68x_selftest_check(const struct bme68x_dev *dev)
struct bme68x_conf conf;
struct bme68x_heatr_conf heatr_conf;

/* Copy required parameters from reference bme68x_dev struct */
t_dev.amb_temp = 25;
t_dev.read = dev->read;
t_dev.write = dev->write;
t_dev.intf = dev->intf;
t_dev.delay_us = dev->delay_us;
t_dev.intf_ptr = dev->intf_ptr;
rslt = bme68x_init(&t_dev);
rslt = null_ptr_check(dev);

if (rslt == BME68X_OK)
{
/* Copy required parameters from reference bme68x_dev struct */
t_dev.amb_temp = 25;
t_dev.read = dev->read;
t_dev.write = dev->write;
t_dev.intf = dev->intf;
t_dev.delay_us = dev->delay_us;
t_dev.intf_ptr = dev->intf_ptr;

rslt = bme68x_init(&t_dev);
}

if (rslt == BME68X_OK)
{
/* Set the temperature, pressure and humidity & filter settings */
Expand Down Expand Up @@ -974,7 +983,7 @@ static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range
return calc_gas_res;
}

/* This internal API is used to calculate the heater resistance value using float */
/* This internal API is used to calculate the heater resistance value using integer */
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
{
uint8_t heatr_res;
Expand Down Expand Up @@ -1132,7 +1141,7 @@ static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range)
return calc_gas_res;
}

/* This internal API is used to calculate the heater resistance value */
/* This internal API is used to calculate the heater resistance value using float */
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
{
float var1;
Expand Down
6 changes: 3 additions & 3 deletions src/bme68x/bme68x.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
Expand Down Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68x.h
* @date 2021-11-09
* @version v4.4.7
* @date 2023-02-07
* @version v4.4.8
*
*/

Expand Down
6 changes: 3 additions & 3 deletions src/bme68x/bme68x_defs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
Expand Down Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68x_defs.h
* @date 2021-11-09
* @version v4.4.7
* @date 2023-02-07
* @version v4.4.8
*
*/

Expand Down
6 changes: 4 additions & 2 deletions src/bme68xLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68xLibrary.cpp
* @date 8 Feb 2022
* @version 1.1.40407
* @date 11 Jan 2023
* @version 1.2.40408
*
*/

Expand All @@ -51,6 +51,8 @@

#ifdef ARDUINO_ARCH_MBED
/* Assuming all MBED implementations of Wire have 256 byte sized buffers */
/* The buffer size needs to be modifed by the user as per the hardware they are using */
/* Check I2C buffer length in Wire.h of used board in ardunio library folder under wire/src */
#define BME68X_I2C_BUFFER_SIZE 256

#define BME68X_BURST_SPI_TRANSFER
Expand Down
4 changes: 2 additions & 2 deletions src/bme68xLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68xLibrary.h
* @date 8 Feb 2022
* @version 1.1.40407
* @date 11 Jan 2023
* @version 1.2.40408
*
*/

Expand Down

0 comments on commit bdd6052

Please sign in to comment.