3 This package contains the Bosch Sensortec's BME280 pressure sensor driver (sensor API)
5 The sensor driver package includes bme280.c, bme280.h and bme280_defs.h files.
10 bme280.c | 3.2.0 | 21 Mar 2017
11 bme280.h | 3.2.0 | 21 Mar 2017
12 bme280_defs.h | 3.2.0 | 21 Mar 2017
14 ## Integration details
15 * Integrate bme280.h, bme280_defs.h and bme280.c file in to the project.
16 * Include the bme280.h file in your code like below.
22 * bme280_defs.h : This header file has the constants, macros and datatype declarations.
23 * bme280.h : This header file contains the declarations of the sensor driver APIs.
24 * bme280.c : This source file contains the definitions of the sensor driver APIs.
26 ## Supported sensor interfaces
30 SPI 3-wire is currently not supported in the API.
32 ### Initializing the sensor
33 To initialize the sensor, user need to create a device structure. User can do this by
34 creating an instance of the structure bme280_dev. After creating the device strcuture, user
35 need to fill in the various parameters as shown below.
37 #### Example for SPI 4-Wire
39 struct bme280_dev dev;
40 int8_t rslt = BME280_OK;
42 /* Sensor_0 interface over SPI with native chip select line */
44 dev.interface = BME280_SPI_INTF;
45 dev.read = user_spi_read;
46 dev.write = user_spi_write;
47 dev.delay_ms = user_delay_ms;
49 rslt = bme280_init(&dev);
53 struct bme280_dev dev;
54 int8_t rslt = BME280_OK;
56 dev.id = BME280_I2C_ADDR_PRIM;
57 dev.interface = BME280_I2C_INTF;
58 dev.read = user_i2c_read;
59 dev.write = user_i2c_write;
60 dev.delay_ms = user_delay_ms;
62 rslt = bme280_init(&dev);
64 Regarding compensation functions for temperature,pressure and humidity we have two implementations.
65 1) Double precision floating point version
68 By default, integer version is used in the API. If user needs double version, user has to
69 enable FLOATING_POINT_REPRESENTATION macro in bme280_defs.h file.
71 In integer compensation functions, we also have below two implementations for pressure.
72 1) For 32 bit machine.
73 2) For 64 bit machine.
75 By default, 64 bit variant is used in the API. If user wants 32 bit variant, user can disable the
76 macro MACHINE_64_BIT in bme280_defs.h file.
79 #### Get sensor data in forced mode
82 int8_t get_sensor_data_forced_mode(struct bme280_dev *dev)
86 struct bme280_data comp_data;
88 /* Continuously get the sensor data */
90 dev->settings.osr_h = BME280_OVERSAMPLING_4X;
91 dev->settings.osr_p = BME280_OVERSAMPLING_4X;
92 dev->settings.osr_t = BME280_OVERSAMPLING_4X;
94 settings_sel = BME280_OSR_PRESS_SEL|BME280_OSR_TEMP_SEL|BME280_OSR_HUM_SEL;
96 rslt = bme280_set_sensor_settings(settings_sel, dev);
97 rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev);
98 /* Give some delay for the sensor to go into force mode */
100 rslt = bme280_get_sensor_data(BME280_PRESS | BME280_HUM | BME280_TEMP, &comp_data, dev);
101 print_sensor_data(&comp_data);
106 void print_sensor_data(struct bme280_data *comp_data)
108 #ifdef FLOATING_POINT_REPRESENTATION
109 printf("%0.2f\t\t%0.2f\t\t%0.2f\t\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
111 printf("%ld\t\t%ld\t\t%ld\t\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
116 ##### Get sensor data in normal mode
118 int8_t get_sensor_data_normal_mode(struct bme280_dev *dev)
121 uint8_t settings_sel;
122 struct bme280_data comp_data;
124 dev->settings.osr_h = BME280_OVERSAMPLING_4X;
125 dev->settings.osr_p = BME280_OVERSAMPLING_4X;
126 dev->settings.osr_t = BME280_OVERSAMPLING_4X;
128 settings_sel = BME280_OSR_PRESS_SEL|BME280_OSR_TEMP_SEL|BME280_OSR_HUM_SEL;
129 rslt = bme280_set_sensor_settings(settings_sel, dev);
130 rslt = bme280_set_sensor_mode(BME280_NORMAL_MODE, dev);
131 /* Give some delay for the sensor to go into normal mode */
135 rslt = bme280_get_sensor_data(BME280_PRESS | BME280_HUM | BME280_TEMP, &comp_data, dev);
136 print_sensor_data(&comp_data);
142 void print_sensor_data(struct bme280_data *comp_data)
144 #ifdef FLOATING_POINT_REPRESENTATION
145 printf("%0.2f\t\t%0.2f\t\t%0.2f\t\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
147 printf("%ld\t\t%ld\t\t%ld\t\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
152 ## Copyright (C) 2016 - 2017 Bosch Sensortec GmbH