Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. wmprintf("BME680\r\n");
  2. int8_t rslt = BME680_OK;
  3.  
  4. struct bme680_dev gas_sensor;
  5. gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
  6. gas_sensor.intf = BME680_I2C_INTF;
  7. gas_sensor.read = user_i2c_read;
  8. gas_sensor.write = user_i2c_write;
  9. gas_sensor.delay_ms = user_delay_ms;
  10. /* amb_temp can be set to 25 prior to configuring the gas sensor
  11. * or by performing a few temperature readings without operating the gas sensor.
  12. */
  13. gas_sensor.amb_temp = 25;
  14.  
  15. rslt = bme680_init(&gas_sensor);
  16. wmprintf("bme680_init done: %d\r\n", rslt);
  17. wmprintf("bme680.chip_id: 0x%02X\r\n", gas_sensor.chip_id);
  18.  
  19. uint16_t set_required_settings;
  20.  
  21. /* Set the temperature, pressure and humidity settings */
  22. gas_sensor.tph_sett.os_hum = BME680_OS_2X;
  23. gas_sensor.tph_sett.os_pres = BME680_OS_4X;
  24. gas_sensor.tph_sett.os_temp = BME680_OS_8X;
  25. gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
  26.  
  27. /* Set the remaining gas sensor settings and link the heating profile */
  28. gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
  29. /* Create a ramp heat waveform in 3 steps */
  30. gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
  31. gas_sensor.gas_sett.heatr_dur = 2000; /* milliseconds */
  32.  
  33. /* Select the power mode */
  34. /* Must be set before writing the sensor configuration */
  35. gas_sensor.power_mode = BME680_FORCED_MODE;
  36.  
  37. /* Set the required sensor settings needed */
  38. set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL | BME680_GAS_SENSOR_SEL;
  39.  
  40. /* Set the desired sensor configuration */
  41. rslt = bme680_set_sensor_settings(set_required_settings, &gas_sensor);
  42. wmprintf("bme680_set_sensor_settings done: %d\r\n", rslt);
  43. /* Set the power mode */
  44. rslt = bme680_set_sensor_mode(&gas_sensor);
  45. wmprintf("bme680_set_sensor_mode done: %d\r\n", rslt);
  46. /* Get the total measurement duration so as to sleep or wait till the
  47. * measurement is complete */
  48. uint16_t meas_period;
  49. bme680_get_profile_dur(&meas_period, &gas_sensor);
  50.  
  51. struct bme680_field_data data;
  52.  
  53. while (1) {
  54. user_delay_ms(meas_period); /* Delay till the measurement is ready */
  55.  
  56. rslt = bme680_get_sensor_data(&data, &gas_sensor);
  57. //wmprintf("data.status: %d\r\n", data.status);
  58. wmprintf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f, data.pressure / 100.0f, data.humidity / 1000.0f);
  59. /* Avoid using measurements from an unstable heating setup */
  60. if (data.status & BME680_GASM_VALID_MSK){
  61. wmprintf(", G: %d ohms", data.gas_resistance);
  62. }
  63. wmprintf("\r\n");
  64.  
  65. /* Trigger the next measurement if you would like to read data out continuously */
  66. if (gas_sensor.power_mode == BME680_FORCED_MODE) {
  67. rslt = bme680_set_sensor_mode(&gas_sensor);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement