This commit is contained in:
2025-10-07 00:18:25 -04:00
parent 970e081f64
commit 909dddeb77
1612 changed files with 0 additions and 159018 deletions

View File

@@ -1 +0,0 @@
873d97d0bd30004f45d1653f078a4bafe39c1767e57d4bae0f0a13bc3a4d5e3d

View File

@@ -1,13 +0,0 @@
# ChangeLog
## v0.1.1 - 2024-12-23
### Bug Fixes:
* Fix the issue in README.md where the usage example for bme280 lacks the default initialization.
## v0.1.0 - 2024-11-5
### Enhancements:
* Initial version

View File

@@ -1 +0,0 @@
{"version": "1.0", "algorithm": "sha256", "created_at": "2025-05-21T17:09:18.488972+00:00", "files": [{"path": "CMakeLists.txt", "size": 160, "hash": "b9af3a241cecba82dda3b44e32c70b1aac28890f41eb00768f518a000f163357"}, {"path": "CHANGELOG.md", "size": 211, "hash": "d61f738a9a542e7c0f7d69fcc0b14e20c15d96688f0e4e067c943e853e3657e8"}, {"path": "idf_component.yml", "size": 580, "hash": "71fa62fa58af333761e45146271e5ed3c90e7e845740391711bfe276266b9131"}, {"path": "README.md", "size": 1713, "hash": "51df9e655bb500962a5736b65e49e6920d713216556c8bbf5d63b3132e1d3862"}, {"path": "license.txt", "size": 11358, "hash": "cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30"}, {"path": "bme280.c", "size": 13819, "hash": "47aac27b35df43fdad8551d1f8759d774362d291859685a77a331aa6433eb163"}, {"path": "include/bme280.h", "size": 10161, "hash": "043eda239a4686220cff149054b678bd736bf7c5f2edd290c7c703c8a1c156f9"}, {"path": "test_apps/CMakeLists.txt", "size": 350, "hash": "02be4ce8d0c8034408017c3948d13d93d3be6fdc40ada18906a5f15fc4ef0dad"}, {"path": "test_apps/sdkconfig.defaults", "size": 213, "hash": "9a34a6cb08c49ec24007587e0c5d492f44b5a862d9c0f583cf9f6f643669b564"}, {"path": "test_apps/main/CMakeLists.txt", "size": 143, "hash": "802c3b217fc1bd9ed8c615353f70d9084caf0b4216288e05fc18af11e6bf7abf"}, {"path": "test_apps/main/bme280_test.c", "size": 2447, "hash": "ee63d7fbd09167de421eb0c416acb6a9f0da44789f7d453b603b3fd74989cf4c"}]}

View File

@@ -1,5 +0,0 @@
idf_component_register(SRCS "bme280.c"
INCLUDE_DIRS include)
include(package_manager)
cu_pkg_define_version(${CMAKE_CURRENT_LIST_DIR})

View File

@@ -1,51 +0,0 @@
# Component: BME280
The BME280 is as combined digital humidity, pressure and temperature sensor based on proven sensing principles. The sensor module is housed in an extremely compact metal-lid LGA package with a footprint of only 2.5 × 2.5 mm² with a height of 0.93 mm. Its small dimensions and its low power consumption allow the implementation in battery driven devices such as handsets, GPS modules or watches.
## Add component to your project
Please use the component manager command `add-dependency` to add the `bme280` to your project's dependency, during the `CMake` step the component will be downloaded automatically
```
idf.py add-dependency "espressif/bme280=*"
```
## Example of BME280 usage
Pin assignment:
* master:
* GPIO2 is assigned as the clock signal of i2c master port
* GPIO1 is assigned as the data signal of i2c master port
* Connection:
* connect sda of sensor with GPIO1
* connect scl of sensor with GPIO2
```c
static i2c_bus_handle_t i2c_bus = NULL;
static bme280_handle_t bme280 = NULL;
//Step1: Init I2C bus
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_MASTER_SCL_IO,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
i2c_bus = i2c_bus_create(I2C_MASTER_NUM, &conf);
//Step2: Init bme280
bme280 = bme280_create(i2c_bus, BME280_I2C_ADDRESS_DEFAULT);
bme280_default_init(bme280);
//Step3: Read temperature, humidity and pressure
float temperature = 0.0, humidity = 0.0, pressure = 0.0;
bme280_read_temperature(bme280, &temperature);
bme280_read_humidity(bme280, &humidity);
bme280_read_pressure(bme280, &pressure);
```

View File

@@ -1,372 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "i2c_bus.h"
#include "bme280.h"
#include "math.h"
#include "esp_log.h"
bme280_handle_t bme280_create(i2c_bus_handle_t bus, uint8_t dev_addr)
{
bme280_dev_t *sens = (bme280_dev_t *) calloc(1, sizeof(bme280_dev_t));
sens->i2c_dev = i2c_bus_device_create(bus, dev_addr, i2c_bus_get_current_clk_speed(bus));
if (sens->i2c_dev == NULL) {
free(sens);
return NULL;
}
sens->dev_addr = dev_addr;
return (bme280_handle_t)sens;
}
esp_err_t bme280_delete(bme280_handle_t *sensor)
{
if (*sensor == NULL) {
return ESP_OK;
}
bme280_dev_t *sens = (bme280_dev_t *)(*sensor);
i2c_bus_device_delete(&sens->i2c_dev);
free(sens);
*sensor = NULL;
return ESP_OK;
}
static esp_err_t bme280_read_uint16(bme280_handle_t sensor, uint8_t addr, uint16_t *data)
{
esp_err_t ret = ESP_FAIL;
bme280_dev_t *sens = (bme280_dev_t *) sensor;
uint8_t data0, data1;
if (i2c_bus_read_byte(sens->i2c_dev, addr, &data0) != ESP_OK) {
return ret;
}
if (i2c_bus_read_byte(sens->i2c_dev, addr + 1, &data1) != ESP_OK) {
return ret;
}
*data = (data0 << 8) | data1;
return ESP_OK;
}
static esp_err_t bme280_read_uint16_le(bme280_handle_t sensor, uint8_t addr, uint16_t *data)
{
esp_err_t ret = ESP_FAIL;
bme280_dev_t *sens = (bme280_dev_t *) sensor;
uint8_t data0, data1;
if (i2c_bus_read_byte(sens->i2c_dev, addr, &data0) != ESP_OK) {
return ret;
}
if (i2c_bus_read_byte(sens->i2c_dev, addr + 1, &data1) != ESP_OK) {
return ret;
}
*data = (data1 << 8) | data0;
return ESP_OK;
}
unsigned int bme280_getconfig(bme280_handle_t sensor)
{
bme280_dev_t *sens = (bme280_dev_t *) sensor;
return (sens->config_t.t_sb << 5) | (sens->config_t.filter << 3) | sens->config_t.spi3w_en;
}
unsigned int bme280_getctrl_meas(bme280_handle_t sensor)
{
bme280_dev_t *sens = (bme280_dev_t *) sensor;
return (sens->ctrl_meas_t.osrs_t << 5) | (sens->ctrl_meas_t.osrs_p << 3) | sens->ctrl_meas_t.mode;
}
unsigned int bme280_getctrl_hum(bme280_handle_t sensor)
{
bme280_dev_t *sens = (bme280_dev_t *) sensor;
return (sens->ctrl_hum_t.osrs_h);
}
bool bme280_is_reading_calibration(bme280_handle_t sensor)
{
uint8_t rstatus = 0;
bme280_dev_t *sens = (bme280_dev_t *) sensor;
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_STATUS, &rstatus) != ESP_OK) {
return false;
}
return (rstatus & (1 << 0)) != 0;
}
esp_err_t bme280_read_coefficients(bme280_handle_t sensor)
{
uint8_t data = 0;
uint8_t data1 = 0;
uint16_t data16 = 0;
bme280_dev_t *sens = (bme280_dev_t *) sensor;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_T1, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_t1 = data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_T2, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_t2 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_T3, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_t3 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P1, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p1 = data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P2, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p2 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P3, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p3 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P4, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p4 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P5, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p5 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P6, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p6 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P7, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p7 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P8, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p8 = (int16_t) data16;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_P9, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_p9 = (int16_t) data16;
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_DIG_H1, &data) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_h1 = data;
if (bme280_read_uint16_le(sensor, BME280_REGISTER_DIG_H2, &data16) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_h2 = (int16_t) data16;
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_DIG_H3, &data) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_h3 = data;
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_DIG_H4, &data) != ESP_OK) {
return ESP_FAIL;
}
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_DIG_H4 + 1, &data1) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_h4 = (data << 4) | (data1 & 0xF);
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_DIG_H5 + 1, &data) != ESP_OK) {
return ESP_FAIL;
}
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_DIG_H5, &data1) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_h5 = (data << 4) | (data1 >> 4);
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_DIG_H6, &data) != ESP_OK) {
return ESP_FAIL;
}
sens->data_t.dig_h6 = (int8_t) data;
return ESP_OK;
}
esp_err_t bme280_set_sampling(bme280_handle_t sensor, bme280_sensor_mode mode, bme280_sensor_sampling tempSampling, bme280_sensor_sampling pressSampling, bme280_sensor_sampling humSampling, bme280_sensor_filter filter, bme280_standby_duration duration)
{
bme280_dev_t *sens = (bme280_dev_t *) sensor;
sens->ctrl_meas_t.mode = mode;
sens->ctrl_meas_t.osrs_t = tempSampling;
sens->ctrl_meas_t.osrs_p = pressSampling;
sens->ctrl_hum_t.osrs_h = humSampling;
sens->config_t.filter = filter;
sens->config_t.t_sb = duration;
// you must make sure to also set REGISTER_CONTROL after setting the
// CONTROLHUMID register, otherwise the values won't be applied (see DS 5.4.3)
if (i2c_bus_write_byte(sens->i2c_dev, BME280_REGISTER_CONTROLHUMID, bme280_getctrl_hum(sensor)) != ESP_OK) {
return ESP_FAIL;
}
if (i2c_bus_write_byte(sens->i2c_dev, BME280_REGISTER_CONFIG, bme280_getconfig(sensor)) != ESP_OK) {
return ESP_FAIL;
}
if (i2c_bus_write_byte(sens->i2c_dev, BME280_REGISTER_CONTROL, bme280_getctrl_meas(sensor)) != ESP_OK) {
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t bme280_default_init(bme280_handle_t sensor)
{
// check if sensor, i.e. the chip ID is correct
uint8_t chipid = 0;
bme280_dev_t *sens = (bme280_dev_t *) sensor;
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_CHIPID, &chipid) != ESP_OK) {
ESP_LOGI("BME280:", "bme280_default_init->bme280_read_byte ->BME280_REGISTER_CHIPID failed!!!!:%x", chipid);
return ESP_FAIL;
}
if (chipid != BME280_DEFAULT_CHIPID) {
ESP_LOGI("BME280:", "bme280_default_init->BME280_DEFAULT_CHIPID:%x", chipid);
return ESP_FAIL;
}
// reset the sens using soft-reset, this makes sure the IIR is off, etc.
if (i2c_bus_write_byte(sens->i2c_dev, BME280_REGISTER_SOFTRESET, 0xB6) != ESP_OK) {
return ESP_FAIL;
}
// wait for chip to wake up.
vTaskDelay(300 / portTICK_RATE_MS);
// if chip is still reading calibration, delay
while (bme280_is_reading_calibration(sensor)) {
vTaskDelay(100 / portTICK_RATE_MS);
}
if (bme280_read_coefficients(sensor) != ESP_OK) { // read trimming parameters, see DS 4.2.2
return ESP_FAIL;
}
if (bme280_set_sampling(sensor, BME280_MODE_NORMAL, BME280_SAMPLING_X16, BME280_SAMPLING_X16, BME280_SAMPLING_X16, BME280_FILTER_OFF, BME280_STANDBY_MS_0_5) != ESP_OK) { // use defaults
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t bme280_take_forced_measurement(bme280_handle_t sensor)
{
uint8_t data = 0;
bme280_dev_t *sens = (bme280_dev_t *) sensor;
if (sens->ctrl_meas_t.mode == BME280_MODE_FORCED) {
// set to forced mode, i.e. "take next measurement"
if (i2c_bus_write_byte(sens->i2c_dev, BME280_REGISTER_CONTROL, bme280_getctrl_meas(sensor)) != ESP_OK) {
return ESP_FAIL;
}
// wait until measurement has been completed, otherwise we would read, the values from the last measurement
if (i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_STATUS, &data) != ESP_OK) {
return ESP_FAIL;
}
while (data & 0x08) {
i2c_bus_read_byte(sens->i2c_dev, BME280_REGISTER_STATUS, &data);
vTaskDelay(10 / portTICK_RATE_MS);
}
}
return ESP_OK;
}
esp_err_t bme280_read_temperature(bme280_handle_t sensor, float *temperature)
{
int32_t var1, var2;
uint8_t data[3] = { 0 };
bme280_dev_t *sens = (bme280_dev_t *) sensor;
if (i2c_bus_read_bytes(sens->i2c_dev, BME280_REGISTER_TEMPDATA, 3, data) != ESP_OK) {
return ESP_FAIL;
}
int32_t adc_T = (data[0] << 16) | (data[1] << 8) | data[2];
if (adc_T == 0x800000) { // value in case temp measurement was disabled
return ESP_FAIL;
}
adc_T >>= 4;
var1 = ((((adc_T >> 3) - ((int32_t) sens->data_t.dig_t1 << 1)))
* ((int32_t) sens->data_t.dig_t2)) >> 11;
var2 = (((((adc_T >> 4) - ((int32_t) sens->data_t.dig_t1))
* ((adc_T >> 4) - ((int32_t) sens->data_t.dig_t1))) >> 12)
* ((int32_t) sens->data_t.dig_t3)) >> 14;
sens->t_fine = var1 + var2;
*temperature = ((sens->t_fine * 5 + 128) >> 8) / 100.0;
return ESP_OK;
}
esp_err_t bme280_read_pressure(bme280_handle_t sensor, float *pressure)
{
int64_t var1, var2, p;
uint8_t data[3] = { 0 };
bme280_dev_t *sens = (bme280_dev_t *) sensor;
float temp = 0.0;
if (bme280_read_temperature(sensor, &temp) != ESP_OK) {
// must be done first to get t_fine
return ESP_FAIL;
}
if (i2c_bus_read_bytes(sens->i2c_dev, BME280_REGISTER_PRESSUREDATA, 3, data) != ESP_OK) {
return ESP_FAIL;
}
int32_t adc_P = (data[0] << 16) | (data[1] << 8) | data[2];
if (adc_P == 0x800000) { // value in case pressure measurement was disabled
return ESP_FAIL;
}
adc_P >>= 4;
var1 = ((int64_t) sens->t_fine) - 128000;
var2 = var1 * var1 * (int64_t) sens->data_t.dig_p6;
var2 = var2 + ((var1 * (int64_t) sens->data_t.dig_p5) << 17);
var2 = var2 + (((int64_t) sens->data_t.dig_p4) << 35);
var1 = ((var1 * var1 * (int64_t) sens->data_t.dig_p3) >> 8) + ((var1 * (int64_t) sens->data_t.dig_p2) << 12);
var1 = (((((int64_t) 1) << 47) + var1)) * ((int64_t) sens->data_t.dig_p1) >> 33;
if (var1 == 0) {
return ESP_FAIL; // avoid exception caused by division by zero
}
p = 1048576 - adc_P;
p = (((p << 31) - var2) * 3125) / var1;
var1 = (((int64_t) sens->data_t.dig_p9) * (p >> 13) * (p >> 13)) >> 25;
var2 = (((int64_t) sens->data_t.dig_p8) * p) >> 19;
p = ((p + var1 + var2) >> 8) + (((int64_t) sens->data_t.dig_p7) << 4);
p = p >> 8; // /256
*pressure = (float) p / 100;
return ESP_OK;
}
esp_err_t bme280_read_humidity(bme280_handle_t sensor, float *humidity)
{
uint16_t data16;
bme280_dev_t *sens = (bme280_dev_t *) sensor;
float temp = 0.0;
if (bme280_read_temperature(sensor, &temp) != ESP_OK) {
// must be done first to get t_fine
return ESP_FAIL;
}
if (bme280_read_uint16(sensor, BME280_REGISTER_HUMIDDATA, &data16) != ESP_OK) {
return ESP_FAIL;
}
int32_t adc_H = data16;
if (adc_H == 0x8000) { // value in case humidity measurement was disabled
return ESP_FAIL;
}
int32_t v_x1_u32r;
v_x1_u32r = (sens->t_fine - ((int32_t) 76800));
v_x1_u32r = (((((adc_H << 14) - (((int32_t) sens->data_t.dig_h4) << 20)
- (((int32_t) sens->data_t.dig_h5) * v_x1_u32r))
+ ((int32_t) 16384)) >> 15)
* (((((((v_x1_u32r * ((int32_t) sens->data_t.dig_h6)) >> 10)
* (((v_x1_u32r * ((int32_t) sens->data_t.dig_h3)) >> 11) + ((int32_t) 32768))) >> 10) + ((int32_t) 2097152))
* ((int32_t) sens->data_t.dig_h2) + 8192) >> 14));
v_x1_u32r = (v_x1_u32r
- (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7)
* ((int32_t) sens->data_t.dig_h1)) >> 4));
v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r;
v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r;
*humidity = (v_x1_u32r >> 12) / 1024.0;
return ESP_OK;
}
esp_err_t bme280_read_altitude(bme280_handle_t sensor, float seaLevel, float *altitude)
{
float pressure = 0.0;
float temp = 0.0;
if (bme280_read_pressure(sensor, &temp) != ESP_OK) {
return ESP_FAIL;
}
float atmospheric = pressure / 100.0F;
*altitude = 44330.0 * (1.0 - pow(atmospheric / seaLevel, 0.1903));
return ESP_OK;
}
esp_err_t bme280_calculates_pressure(bme280_handle_t sensor, float altitude,
float atmospheric, float *pressure)
{
*pressure = atmospheric / pow(1.0 - (altitude / 44330.0), 5.255);
return ESP_OK;
}

View File

@@ -1,14 +0,0 @@
dependencies:
cmake_utilities: 0.*
i2c_bus:
public: true
idf: '>=4.4'
description: I2C driver for BME280 preesure sensor
documentation: https://docs.espressif.com/projects/esp-iot-solution/en/latest/sensors/pressure.html
issues: https://github.com/espressif/esp-iot-solution/issues
repository: git://github.com/espressif/esp-iot-solution.git
repository_info:
commit_sha: 1f4206cfe0ff480fedd4fa7860dc41ece6768812
path: components/sensors/pressure/bme280
url: https://github.com/espressif/esp-iot-solution/tree/master/components/sensors/pressure/bme280
version: 0.1.1

View File

@@ -1,377 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BME280_H_
#define _BME280_H_
#include "i2c_bus.h"
#define BME280_I2C_ADDRESS_DEFAULT (0x76) /*The device's I2C address is either 0x76 or 0x77.*/
#define BME280_DEFAULT_CHIPID (0x60)
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
#define ACK_VAL 0x0 /*!< I2C ack value */
#define NACK_VAL 0x1 /*!< I2C nack value */
#define BME280_REGISTER_DIG_T1 0x88
#define BME280_REGISTER_DIG_T2 0x8A
#define BME280_REGISTER_DIG_T3 0x8C
#define BME280_REGISTER_DIG_P1 0x8E
#define BME280_REGISTER_DIG_P2 0x90
#define BME280_REGISTER_DIG_P3 0x92
#define BME280_REGISTER_DIG_P4 0x94
#define BME280_REGISTER_DIG_P5 0x96
#define BME280_REGISTER_DIG_P6 0x98
#define BME280_REGISTER_DIG_P7 0x9A
#define BME280_REGISTER_DIG_P8 0x9C
#define BME280_REGISTER_DIG_P9 0x9E
#define BME280_REGISTER_DIG_H1 0xA1
#define BME280_REGISTER_DIG_H2 0xE1
#define BME280_REGISTER_DIG_H3 0xE3
#define BME280_REGISTER_DIG_H4 0xE4
#define BME280_REGISTER_DIG_H5 0xE5
#define BME280_REGISTER_DIG_H6 0xE7
#define BME280_REGISTER_CHIPID 0xD0
#define BME280_REGISTER_VERSION 0xD1
#define BME280_REGISTER_SOFTRESET 0xE0
#define BME280_REGISTER_CAL26 0xE1 // R calibration stored in 0xE1-0xF0
#define BME280_REGISTER_CONTROLHUMID 0xF2
#define BME280_REGISTER_STATUS 0XF3
#define BME280_REGISTER_CONTROL 0xF4
#define BME280_REGISTER_CONFIG 0xF5
#define BME280_REGISTER_PRESSUREDATA 0xF7
#define BME280_REGISTER_TEMPDATA 0xFA
#define BME280_REGISTER_HUMIDDATA 0xFD
typedef struct {
uint16_t dig_t1;
int16_t dig_t2;
int16_t dig_t3;
uint16_t dig_p1;
int16_t dig_p2;
int16_t dig_p3;
int16_t dig_p4;
int16_t dig_p5;
int16_t dig_p6;
int16_t dig_p7;
int16_t dig_p8;
int16_t dig_p9;
uint8_t dig_h1;
int16_t dig_h2;
uint8_t dig_h3;
int16_t dig_h4;
int16_t dig_h5;
int8_t dig_h6;
} bme280_data_t;
typedef enum {
BME280_SAMPLING_NONE = 0b000,
BME280_SAMPLING_X1 = 0b001,
BME280_SAMPLING_X2 = 0b010,
BME280_SAMPLING_X4 = 0b011,
BME280_SAMPLING_X8 = 0b100,
BME280_SAMPLING_X16 = 0b101
} bme280_sensor_sampling;
typedef enum {
BME280_MODE_SLEEP = 0b00,
BME280_MODE_FORCED = 0b01,
BME280_MODE_NORMAL = 0b11
} bme280_sensor_mode;
typedef enum {
BME280_FILTER_OFF = 0b000,
BME280_FILTER_X2 = 0b001,
BME280_FILTER_X4 = 0b010,
BME280_FILTER_X8 = 0b011,
BME280_FILTER_X16 = 0b100
} bme280_sensor_filter;
// standby durations in ms
typedef enum {
BME280_STANDBY_MS_0_5 = 0b000,
BME280_STANDBY_MS_10 = 0b110,
BME280_STANDBY_MS_20 = 0b111,
BME280_STANDBY_MS_62_5 = 0b001,
BME280_STANDBY_MS_125 = 0b010,
BME280_STANDBY_MS_250 = 0b011,
BME280_STANDBY_MS_500 = 0b100,
BME280_STANDBY_MS_1000 = 0b101
} bme280_standby_duration;
// The config register
typedef struct config {
// inactive duration (standby time) in normal mode
// 000 = 0.5 ms
// 001 = 62.5 ms
// 010 = 125 ms
// 011 = 250 ms
// 100 = 500 ms
// 101 = 1000 ms
// 110 = 10 ms
// 111 = 20 ms
unsigned int t_sb : 3;
// filter settings
// 000 = filter off
// 001 = 2x filter
// 010 = 4x filter
// 011 = 8x filter
// 100 and above = 16x filter
unsigned int filter : 3;
// unused - don't set
unsigned int none : 1;
unsigned int spi3w_en : 1;
} bme280_config_t;
// The ctrl_meas register
typedef struct ctrl_meas {
// temperature oversampling
// 000 = skipped
// 001 = x1
// 010 = x2
// 011 = x4
// 100 = x8
// 101 and above = x16
unsigned int osrs_t : 3;
// pressure oversampling
// 000 = skipped
// 001 = x1
// 010 = x2
// 011 = x4
// 100 = x8
// 101 and above = x16
unsigned int osrs_p : 3;
// device mode
// 00 = sleep
// 01 or 10 = forced
// 11 = normal
unsigned int mode : 2;
} bme280_ctrl_meas_t;
// The ctrl_hum register
typedef struct ctrl_hum {
// unused - don't set
unsigned int none : 5;
// pressure oversampling
// 000 = skipped
// 001 = x1
// 010 = x2
// 011 = x4
// 100 = x8
// 101 and above = x16
unsigned int osrs_h : 3;
} bme280_ctrl_hum_t;
typedef struct {
i2c_bus_device_handle_t i2c_dev;
uint8_t dev_addr;
bme280_data_t data_t;
bme280_config_t config_t;
bme280_ctrl_meas_t ctrl_meas_t;
bme280_ctrl_hum_t ctrl_hum_t;
int32_t t_fine;
} bme280_dev_t;
typedef void *bme280_handle_t; /*handle of bme280*/
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief Create bme280 handle_t
*
* @param object handle of I2C
* @param device address
*
* @return
* - bme280_handle_t
*/
bme280_handle_t bme280_create(i2c_bus_handle_t bus, uint8_t dev_addr);
/**
* @brief delete bme280 handle_t
*
* @param point to object handle of bme280
* @param whether delete i2c bus
*
* @return
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t bme280_delete(bme280_handle_t *sensor);
/**
* @brief Get the value of BME280_REGISTER_CONFIG register
*
* @param sensor object handle of bme280
*
* @return
* - unsigned int: the value of BME280_REGISTER_CONFIG register
*/
unsigned int bme280_getconfig(bme280_handle_t sensor);
/**
* @brief Get the value of BME280_REGISTER_CONTROL measure register
*
* @param sensor object handle of bme280
*
* @return
* - unsigned int the value of BME280_REGISTER_CONTROL register
*/
unsigned int bme280_getctrl_meas(bme280_handle_t sensor);
/**
* @brief Get the value of BME280_REGISTER_CONTROLHUMID measure register
*
* @param sensor object handle of bme280
*
* @return
* - unsigned int the value of BME280_REGISTER_CONTROLHUMID register
*/
unsigned int bme280_getctrl_hum(bme280_handle_t sensor);
/**
* @brief return true if chip is busy reading cal data
*
* @param sensor object handle of bme280
*
* @return
* - true chip is busy
* - false chip is idle or wrong
*/
bool bme280_is_reading_calibration(bme280_handle_t sensor);
/**
* @brief Reads the factory-set coefficients
*
* @param sensor object handle of bme280
*
* @return
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t bme280_read_coefficients(bme280_handle_t sensor);
/**
* @brief setup sensor with gien parameters / settings
*
* @param sensor object handle of bme280
* @param Sensor working mode
* @param the sample of temperature measure
* @param the sample of pressure measure
* @param the sample of humidity measure
* @param Sensor filter multiples
* @param standby duration of sensor
*
* @return
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t bme280_set_sampling(bme280_handle_t sensor, bme280_sensor_mode mode,
bme280_sensor_sampling tempsampling,
bme280_sensor_sampling presssampling,
bme280_sensor_sampling humsampling, bme280_sensor_filter filter,
bme280_standby_duration duration);
/**
* @brief init bme280 device
*
* @param sensor object handle of bme280
*
* @return
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t bme280_default_init(bme280_handle_t sensor);
/**
* @brief Take a new measurement (only possible in forced mode)
* If we are in forced mode, the BME sensor goes back to sleep after each
* measurement and we need to set it to forced mode once at this point, so
* it will take the next measurement and then return to sleep again.
* In normal mode simply does new measurements periodically.
*
* @param sensor object handle of bme280
*
* @return
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t bme280_take_forced_measurement(bme280_handle_t sensor);
/**
* @brief Returns the temperature from the sensor
*
* @param sensor object handle of bme280
* @param temperature pointer to temperature
* @return esp_err_t
*/
esp_err_t bme280_read_temperature(bme280_handle_t sensor, float *temperature);
/**
* @brief Returns the temperature from the sensor
*
* @param sensor object handle of bme280
* @param pressure pointer to pressure value
* @return esp_err_t
*/
esp_err_t bme280_read_pressure(bme280_handle_t sensor, float *pressure);
/**
* @brief Returns the humidity from the sensor
*
* @param sensor object handle of bme280
* @param humidity pointer to humidity value
* @return esp_err_t
*/
esp_err_t bme280_read_humidity(bme280_handle_t sensor, float *humidity);
/**
* @brief Calculates the altitude (in meters) from the specified atmospheric
* pressure (in hPa), and sea-level pressure (in hPa).
*
* @param sensor object handle of bme280
* @param seaLevel: Sea-level pressure in hPa
* @param altitude pointer to altitude value
* @return esp_err_t
*/
esp_err_t bme280_read_altitude(bme280_handle_t sensor, float seaLevel, float *altitude);
/**
* Calculates the pressure at sea level (in hPa) from the specified altitude
* (in meters), and atmospheric pressure (in hPa).
*
* @param sensor object handle of bme280
* @param altitude Altitude in meters
* @param atmospheric Atmospheric pressure in hPa
* @param pressure pointer to pressure value
* @return esp_err_t
*/
esp_err_t bme280_calculates_pressure(bme280_handle_t sensor, float altitude,
float atmospheric, float *pressure);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1,9 +0,0 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components"
"../../bme280")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(bme280_test)

View File

@@ -1,3 +0,0 @@
idf_component_register(SRC_DIRS "."
PRIV_INCLUDE_DIRS "."
PRIV_REQUIRES unity test_utils bme280)

View File

@@ -1,77 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "unity.h"
#include "esp_log.h"
#include "bme280.h"
#include "i2c_bus.h"
#define I2C_MASTER_SCL_IO GPIO_NUM_2 /*!< gpio number for I2C master clock IO2*/
#define I2C_MASTER_SDA_IO GPIO_NUM_1 /*!< gpio number for I2C master data IO1*/
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master bme280 */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */
static i2c_bus_handle_t i2c_bus = NULL;
static bme280_handle_t bme280 = NULL;
void bme280_test_init()
{
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_MASTER_SCL_IO,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
i2c_bus = i2c_bus_create(I2C_MASTER_NUM, &conf);
bme280 = bme280_create(i2c_bus, BME280_I2C_ADDRESS_DEFAULT);
ESP_LOGI("BME280:", "bme280_default_init:%d", bme280_default_init(bme280));
}
void bme280_test_deinit()
{
bme280_delete(&bme280);
i2c_bus_delete(&i2c_bus);
}
void bme280_test_getdata()
{
int cnt = 10;
while (cnt--) {
float temperature = 0.0, humidity = 0.0, pressure = 0.0;
if (ESP_OK == bme280_read_temperature(bme280, &temperature)) {
ESP_LOGI("BME280", "temperature:%f ", temperature);
}
vTaskDelay(300 / portTICK_RATE_MS);
if (ESP_OK == bme280_read_humidity(bme280, &humidity)) {
ESP_LOGI("BME280", "humidity:%f ", humidity);
}
vTaskDelay(300 / portTICK_RATE_MS);
if (ESP_OK == bme280_read_pressure(bme280, &pressure)) {
ESP_LOGI("BME280", "pressure:%f\n", pressure);
}
vTaskDelay(300 / portTICK_RATE_MS);
}
}
TEST_CASE("Device bme280 test", "[bme280][iot][device]")
{
bme280_test_init();
bme280_test_getdata();
bme280_test_deinit();
}
void app_main(void)
{
printf("BME280 TEST \n");
unity_run_menu();
}

View File

@@ -1,9 +0,0 @@
# For IDF 5.0
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_TASK_WDT_EN=n
# For IDF4.4
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP_TASK_WDT=n