75 lines
2.4 KiB
C
75 lines
2.4 KiB
C
#include <stdio.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/task.h>
|
|
#include <esp_system.h>
|
|
#include <bme680.h>
|
|
#include <string.h>
|
|
|
|
#define PORT 0
|
|
#if defined(CONFIG_EXAMPLE_I2C_ADDRESS_0)
|
|
#define ADDR BME680_I2C_ADDR_0
|
|
#endif
|
|
#if defined(CONFIG_EXAMPLE_I2C_ADDRESS_1)
|
|
#define ADDR BME680_I2C_ADDR_1
|
|
#endif
|
|
|
|
#ifndef APP_CPU_NUM
|
|
#define APP_CPU_NUM PRO_CPU_NUM
|
|
#endif
|
|
|
|
void bme680_test(void *pvParameters)
|
|
{
|
|
bme680_t sensor;
|
|
memset(&sensor, 0, sizeof(bme680_t));
|
|
|
|
ESP_ERROR_CHECK(bme680_init_desc(&sensor, ADDR, PORT, CONFIG_EXAMPLE_I2C_MASTER_SDA, CONFIG_EXAMPLE_I2C_MASTER_SCL));
|
|
|
|
// init the sensor
|
|
ESP_ERROR_CHECK(bme680_init_sensor(&sensor));
|
|
|
|
// Changes the oversampling rates to 4x oversampling for temperature
|
|
// and 2x oversampling for humidity. Pressure measurement is skipped.
|
|
bme680_set_oversampling_rates(&sensor, BME680_OSR_4X, BME680_OSR_NONE, BME680_OSR_2X);
|
|
|
|
// Change the IIR filter size for temperature and pressure to 7.
|
|
bme680_set_filter_size(&sensor, BME680_IIR_SIZE_7);
|
|
|
|
// Change the heater profile 0 to 200 degree Celsius for 100 ms.
|
|
bme680_set_heater_profile(&sensor, 0, 200, 100);
|
|
bme680_use_heater_profile(&sensor, 0);
|
|
|
|
// Set ambient temperature to 10 degree Celsius
|
|
bme680_set_ambient_temperature(&sensor, 10);
|
|
|
|
// as long as sensor configuration isn't changed, duration is constant
|
|
uint32_t duration;
|
|
bme680_get_measurement_duration(&sensor, &duration);
|
|
|
|
TickType_t last_wakeup = xTaskGetTickCount();
|
|
|
|
bme680_values_float_t values;
|
|
while (1)
|
|
{
|
|
// trigger the sensor to start one TPHG measurement cycle
|
|
if (bme680_force_measurement(&sensor) == ESP_OK)
|
|
{
|
|
// passive waiting until measurement results are available
|
|
vTaskDelay(duration);
|
|
|
|
// get the results and do something with them
|
|
if (bme680_get_results_float(&sensor, &values) == ESP_OK)
|
|
printf("BME680 Sensor: %.2f °C, %.2f %%, %.2f hPa, %.2f Ohm\n",
|
|
values.temperature, values.humidity, values.pressure, values.gas_resistance);
|
|
}
|
|
// passive waiting until 1 second is over
|
|
vTaskDelayUntil(&last_wakeup, pdMS_TO_TICKS(1000));
|
|
}
|
|
}
|
|
|
|
void app_main()
|
|
{
|
|
ESP_ERROR_CHECK(i2cdev_init());
|
|
xTaskCreatePinnedToCore(bme680_test, "bme680_test", configMINIMAL_STACK_SIZE * 8, NULL, 5, NULL, APP_CPU_NUM);
|
|
}
|
|
|