-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0f798c
commit 4790bce
Showing
7 changed files
with
1,061 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
idf_component_register( | ||
SRCS bmx280.c | ||
INCLUDE_DIRS "include" | ||
REQUIRES driver | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
menu "BMX280 Options" | ||
choice BMX280_EXPECT_DEVICE | ||
prompt "Installed Sensor Model" | ||
help | ||
Set to the model of the sensor you are using (if you know it). | ||
default BMX280_EXPECT_DETECT | ||
config BMX280_EXPECT_DETECT | ||
bool "Auto" | ||
config BMX280_EXPECT_BME280 | ||
bool "BME280" | ||
config BMX280_EXPECT_BMP280 | ||
bool "BMP280" | ||
endchoice | ||
|
||
choice BMX280_ADDRESS | ||
prompt "I2C Slave Address" | ||
help | ||
Set the slave address of the sensor if you know it. The driver can | ||
automatically detect it if you don't know. | ||
default BMX280_ADDRESS_DETECT | ||
config BMX280_ADDRESS_DETECT | ||
bool "Auto" | ||
config BMX280_ADDERSS_LO | ||
bool "0x76 (SDO LOW)" | ||
config BMX280_ADDERSS_HI | ||
bool "0x77 (SDO HIGH)" | ||
endchoice | ||
|
||
config BMX280_TIMEOUT | ||
int "Read/Write Timeout" | ||
default 5 | ||
help | ||
Number of ticks to wait for I2C read/write operations. | ||
|
||
menu "Default Configuration" | ||
choice BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING | ||
prompt "Temperature Oversampling" | ||
default BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING_X2 | ||
help | ||
Refer to BMP280/BME280 Datasheet for more information. | ||
config BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING_NONE | ||
bool "None" | ||
config BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING_X1 | ||
bool "x1" | ||
config BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING_X2 | ||
bool "x2" | ||
config BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING_X4 | ||
bool "x4" | ||
config BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING_X8 | ||
bool "x8" | ||
config BMX280_DEFAULT_TEMPERATURE_OVERSAMPLING_X16 | ||
bool "x16" | ||
endchoice | ||
|
||
choice BMX280_DEFAULT_PRESSURE_OVERSAMPLING | ||
prompt "Pressure Oversampling" | ||
default BMX280_DEFAULT_PRESSURE_OVERSAMPLING_X16 | ||
help | ||
Refer to BMP280/BME280 Datasheet for more information. | ||
config BMX280_DEFAULT_PRESSURE_OVERSAMPLING_NONE | ||
bool "None" | ||
config BMX280_DEFAULT_PRESSURE_OVERSAMPLING_X1 | ||
bool "x1" | ||
config BMX280_DEFAULT_PRESSURE_OVERSAMPLING_X2 | ||
bool "x2" | ||
config BMX280_DEFAULT_PRESSURE_OVERSAMPLING_X4 | ||
bool "x4" | ||
config BMX280_DEFAULT_PRESSURE_OVERSAMPLING_X8 | ||
bool "x8" | ||
config BMX280_DEFAULT_PRESSURE_OVERSAMPLING_X16 | ||
bool "x16" | ||
endchoice | ||
|
||
choice BMX280_DEFAULT_STANDBY | ||
prompt "Cyclic Measurement Standby Time" | ||
default BMX280_DEFAULT_STANDBY_0M5 | ||
help | ||
Refer to BMP280/BME280 Datasheet for more information. | ||
config BMX280_DEFAULT_STANDBY_0M5 | ||
bool "0.5ms" | ||
config BMX280_DEFAULT_STANDBY_62M5 | ||
bool "62.5ms" | ||
config BMX280_DEFAULT_STANDBY_125M | ||
bool "125ms" | ||
config BMX280_DEFAULT_STANDBY_250M | ||
bool "250ms" | ||
config BMX280_DEFAULT_STANDBY_500M | ||
bool "500ms" | ||
config BMX280_DEFAULT_STANDBY_1000M | ||
bool "1000ms" | ||
config BMX280_DEFAULT_STANDBY_10M | ||
bool "BMP280: 2000ms // BME280: 10ms" | ||
config BMX280_DEFAULT_STANDBY_20M | ||
bool "BMP280: 4000ms // BME280: 20ms" | ||
endchoice | ||
|
||
choice BMX280_DEFAULT_IIR | ||
prompt "IIR Filter Sensitivity" | ||
default BMX280_DEFAULT_IIR_X16 | ||
help | ||
Refer to BMP280/BME280 Datasheet for more information. | ||
config BMX280_DEFAULT_IIR_NONE | ||
bool "Filter Off" | ||
config BMX280_DEFAULT_IIR_X2 | ||
bool "x2" | ||
config BMX280_DEFAULT_IIR_X4 | ||
bool "x4" | ||
config BMX280_DEFAULT_IIR_X8 | ||
bool "x8" | ||
config BMX280_DEFAULT_IIR_X16 | ||
bool "x16" | ||
endchoice | ||
|
||
menu "BME280 Specific Options" | ||
depends on !(BMX280_EXPECT_BMP280) | ||
|
||
choice BMX280_DEFAULT_HUMIDITY_OVERSAMPLING | ||
prompt "Humidity Oversampling" | ||
default BMX280_DEFAULT_HUMIDITY_OVERSAMPLING_X1 | ||
help | ||
Refer to BME280 Datasheet for more information. | ||
config BMX280_DEFAULT_HUMIDITY_OVERSAMPLING_NONE | ||
bool "None" | ||
config BMX280_DEFAULT_HUMIDITY_OVERSAMPLING_X1 | ||
bool "x1" | ||
config BMX280_DEFAULT_HUMIDITY_OVERSAMPLING_X2 | ||
bool "x2" | ||
config BMX280_DEFAULT_HUMIDITY_OVERSAMPLING_X4 | ||
bool "x4" | ||
config BMX280_DEFAULT_HUMIDITY_OVERSAMPLING_X8 | ||
bool "x8" | ||
config BMX280_DEFAULT_HUMIDITY_OVERSAMPLING_X16 | ||
bool "x16" | ||
endchoice | ||
endmenu | ||
endmenu | ||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Halit Utku Maden | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
BMX280 for ESP-IDF | ||
================== | ||
BMX280 is a basic I2C based driver for ESP32 devices licensed mostly under MIT. | ||
(See caption "License" for details.) | ||
|
||
Usage | ||
----- | ||
Clone this repository or add it as a submodule into your components directory. | ||
Add the module as a requirement to your main module, or other modules. | ||
|
||
Example Code | ||
------------ | ||
```c | ||
#include "esp_log.h" | ||
#include "bmx280.h" | ||
|
||
void app_main(void) | ||
{ | ||
// Entry Point | ||
//ESP_ERROR_CHECK(nvs_flash_init()); | ||
i2c_config_t i2c_cfg = { | ||
.mode = I2C_MODE_MASTER, | ||
.sda_io_num = GPIO_NUM_17, | ||
.scl_io_num = GPIO_NUM_16, | ||
.sda_pullup_en = false, | ||
.scl_pullup_en = false, | ||
|
||
.master = { | ||
.clk_speed = 100000 | ||
} | ||
}; | ||
|
||
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &i2c_cfg)); | ||
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)); | ||
|
||
bmx280_t* bmx280 = bmx280_create(I2C_NUM_0); | ||
|
||
if (!bmx280) { | ||
ESP_LOGE("test", "Could not create bmx280 driver."); | ||
return; | ||
} | ||
|
||
ESP_ERROR_CHECK(bmx280_init(bmx280)); | ||
|
||
bmx280_config_t bmx_cfg = BMX280_DEFAULT_CONFIG; | ||
ESP_ERROR_CHECK(bmx280_configure(bmx280, &bmx_cfg)); | ||
|
||
while (1) | ||
{ | ||
ESP_ERROR_CHECK(bmx280_setMode(bmx280, BMX280_MODE_FORCE)); | ||
do { | ||
vTaskDelay(pdMS_TO_TICKS(1)); | ||
} while(bmx280_isSampling(bmx280)); | ||
|
||
float temp = 0, pres = 0, hum = 0; | ||
ESP_ERROR_CHECK(bmx280_readoutFloat(bmx280, &temp, &pres, &hum)); | ||
|
||
ESP_LOGI("test", "Read Values: temp = %f, pres = %f, hum = %f", temp, pres, hum); | ||
} | ||
} | ||
``` | ||
License | ||
------- | ||
This repository contains a lot of code I have written which is licensed under | ||
MIT, however there are sections modified from the BME280 datasheet which is | ||
unclearly licensed. | ||
The unclearly licensed section is clearly marked with two comments. Any code | ||
between `// HERE BE DRAGONS` and `// END OF DRAGONS` contains modified versions | ||
of the Bosch Sensortec code. | ||
Please take note of this in production. |
Oops, something went wrong.