BME68X Add Time/Temp config to Gas, document

pull/143/head
Phil Howard 2021-08-02 09:21:22 +01:00
rodzic 618fd559f9
commit 746e21c542
7 zmienionych plików z 40 dodań i 16 usunięć

Wyświetl plik

@ -48,14 +48,14 @@ namespace pimoroni {
return true;
}
bool BME68X::read_forced(bme68x_data *data) {
bool BME68X::read_forced(bme68x_data *data, uint16_t heater_temp, uint16_t heater_duration) {
int8_t result = 0;
uint8_t n_fields;
uint32_t delay_period;
heatr_conf.enable = BME68X_ENABLE;
heatr_conf.heatr_temp = 300;
heatr_conf.heatr_dur = 100;
heatr_conf.heatr_temp = heater_temp;
heatr_conf.heatr_dur = heater_duration;
result = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatr_conf, &device);
bme68x_check_rslt("bme68x_set_heatr_conf", result);
if(result != BME68X_OK) return false;

Wyświetl plik

@ -22,7 +22,7 @@ namespace pimoroni {
bool init();
bool configure(uint8_t filter, uint8_t odr, uint8_t os_humidity, uint8_t os_pressure, uint8_t os_temp);
bool read_forced(bme68x_data *data);
bool read_forced(bme68x_data *data, uint16_t heater_temp=300, uint16_t heater_duration=100);
bool read_parallel(bme68x_data *results, uint16_t *profile_temps, uint16_t *profile_durations, size_t profile_length);
BME68X() : BME68X(new I2C()) {}

Wyświetl plik

@ -37,6 +37,14 @@ The `read` method will return a tuple containing Temperature (degrees C), Pressu
temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read()
```
In all cases `gas_index` and `meas_index` will be zero, since these refer to the measurement profile used to gather the current readings. The MicroPython bindings currently only support a single measurement profile with a default of 300c for 100ms.
You can pass a custom temperature and duration into `read`:
```python
temperature, pressure, humidity, gas_resistance, status, gas_index, meas_index = bme.read(heater_temp=250, heater_duration=50)
```
## Configuring The Sensor
The `configure` method allows you to set up the oversampling, filtering and operation mode.

Wyświetl plik

@ -3,16 +3,18 @@
This demo will work for both the BME680 and BME688.
"""
import time
from breakout_bme68x import BreakoutBME68X
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE
from pimoroni_i2c import PimoroniI2C
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
i2c = PimoroniI2C(**PINS_PICO_EXPLORER)
bmp = BreakoutBME68X(i2c, address=0x77)
bmp = BreakoutBME68X(i2c)
while True:
reading = bmp.read()
print(reading)
temperature, pressure, humidity, gas, status, _, _ = bmp.read()
heater = "Stable" if status & STATUS_HEATER_STABLE else "Unstable"
print("{:0.2f}c, {:0.2f}Pa, {:0.2f}%, {:0.2f} Ohms, Heater: {}".format(
temperature, pressure, humidity, gas, heater))
time.sleep(1.0)

Wyświetl plik

@ -5,7 +5,7 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
/***** Methods *****/
MP_DEFINE_CONST_FUN_OBJ_1(BreakoutBME68X_read_obj, BreakoutBME68X_read);
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutBME68X_read_obj, 1, BreakoutBME68X_read);
MP_DEFINE_CONST_FUN_OBJ_KW(BreakoutBME68X_configure_obj, 1, BreakoutBME68X_configure);
/***** Binding of Methods *****/
@ -66,6 +66,9 @@ STATIC const mp_map_elem_t breakout_bme68x_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_STANDBY_TIME_10_MS), MP_ROM_INT(BME68X_ODR_10_MS) },
{ MP_ROM_QSTR(MP_QSTR_STANDBY_TIME_20_MS), MP_ROM_INT(BME68X_ODR_20_MS) },
{ MP_ROM_QSTR(MP_QSTR_STATUS_GAS_VALID), MP_ROM_INT(BME68X_GASM_VALID_MSK) },
{ MP_ROM_QSTR(MP_QSTR_STATUS_HEATER_STABLE), MP_ROM_INT(BME68X_HEAT_STAB_MSK) },
{ MP_ROM_QSTR(MP_QSTR_I2C_ADDRESS_DEFAULT), MP_ROM_INT(BME68X_I2C_ADDR_LOW) },
{ MP_ROM_QSTR(MP_QSTR_I2C_ADDRESS_ALT), MP_ROM_INT(BME68X_I2C_ADDR_HIGH) },
};

Wyświetl plik

@ -82,18 +82,29 @@ mp_obj_t BreakoutBME68X_make_new(const mp_obj_type_t *type, size_t n_args, size_
return MP_OBJ_FROM_PTR(self);
}
mp_obj_t BreakoutBME68X_read(mp_obj_t self_in) {
breakout_bme68x_BreakoutBME68X_obj_t *self = MP_OBJ_TO_PTR2(self_in, breakout_bme68x_BreakoutBME68X_obj_t);
mp_obj_t BreakoutBME68X_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_self, ARG_temp, ARG_duration };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_heater_temp, MP_ARG_INT, { .u_int=300 } },
{ MP_QSTR_heater_duration, MP_ARG_INT, { .u_int=100 } },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
breakout_bme68x_BreakoutBME68X_obj_t *self = MP_OBJ_TO_PTR2(args[ARG_self].u_obj, breakout_bme68x_BreakoutBME68X_obj_t);
bme68x_data result;
if(self->breakout->read_forced(&result)){
if(self->breakout->read_forced(&result, args[ARG_temp].u_int, args[ARG_duration].u_int)){
mp_obj_t tuple[7];
tuple[0] = mp_obj_new_float(result.temperature);
tuple[1] = mp_obj_new_float(result.pressure);
tuple[2] = mp_obj_new_float(result.humidity);
tuple[3] = mp_obj_new_float(result.gas_resistance);
tuple[4] = mp_obj_new_float(result.status);
tuple[5] = mp_obj_new_float(result.gas_index);
tuple[6] = mp_obj_new_float(result.meas_index);
tuple[4] = mp_obj_new_int(result.status);
tuple[5] = mp_obj_new_int(result.gas_index);
tuple[6] = mp_obj_new_int(result.meas_index);
return mp_obj_new_tuple(7, tuple);
}
else {

Wyświetl plik

@ -10,5 +10,5 @@ extern const mp_obj_type_t breakout_bme68x_BreakoutBME68X_type;
/***** Extern of Class Methods *****/
extern void BreakoutBME68X_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind);
extern mp_obj_t BreakoutBME68X_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args);
extern mp_obj_t BreakoutBME68X_read(mp_obj_t self_in);
extern mp_obj_t BreakoutBME68X_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);
extern mp_obj_t BreakoutBME68X_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args);