]> git.itanic.dy.fi Git - BME280_driver/blob - README.md
Updated to v3.2.0
[BME280_driver] / README.md
1 # BME280 sensor API
2 ## Introduction
3 This package contains the Bosch Sensortec's BME280 pressure sensor driver (sensor API)
4
5 The sensor driver package includes bme280.c, bme280.h and bme280_defs.h files.
6
7 ## Version
8 File | Version | Date
9 -----|---------|-----
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
13
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.
17 ``` c
18 #include "bme280.h"
19 ```
20
21 ## File information
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.
25
26 ## Supported sensor interfaces
27 * SPI 4-wire
28 * I2C
29
30 SPI 3-wire is currently not supported in the API.
31 ## Usage guide
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.
36
37 #### Example for SPI 4-Wire
38 ``` c
39 struct bme280_dev dev;
40 int8_t rslt = BME280_OK;
41
42 /* Sensor_0 interface over SPI with native chip select line */
43 dev.id = 0;
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;
48
49 rslt = bme280_init(&dev);
50 ```
51 #### Example for I2C
52 ``` c
53 struct bme280_dev dev;
54 int8_t rslt = BME280_OK;
55
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;
61
62 rslt = bme280_init(&dev);
63 ```
64 Regarding compensation functions for temperature,pressure and humidity we have two implementations.
65 1) Double precision floating point version
66 2) Integer version
67
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.
70
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.
74
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.
77
78 ### Get sensor data
79 #### Get sensor data in forced mode
80
81 ``` c
82 int8_t get_sensor_data_forced_mode(struct bme280_dev *dev)
83 {
84         int8_t rslt;
85         uint8_t settings_sel;
86         struct bme280_data comp_data;
87
88         /* Continuously get the sensor data */
89         while (1) {
90                 dev->settings.osr_h = BME280_OVERSAMPLING_4X;
91                 dev->settings.osr_p = BME280_OVERSAMPLING_4X;
92                 dev->settings.osr_t = BME280_OVERSAMPLING_4X;
93
94                 settings_sel = BME280_OSR_PRESS_SEL|BME280_OSR_TEMP_SEL|BME280_OSR_HUM_SEL;
95
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 */
99                 dev->delay_ms(5);
100                 rslt = bme280_get_sensor_data(BME280_PRESS | BME280_HUM | BME280_TEMP, &comp_data, dev);
101                 print_sensor_data(&comp_data);
102         }
103         return rslt;
104 }
105
106 void print_sensor_data(struct bme280_data *comp_data)
107 {
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);
110 #else
111                 printf("%ld\t\t%ld\t\t%ld\t\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
112 #endif
113 }
114
115 ```
116 ##### Get sensor data in normal mode
117 ``` c
118 int8_t get_sensor_data_normal_mode(struct bme280_dev *dev)
119 {
120         int8_t rslt;
121         uint8_t settings_sel;
122         struct bme280_data comp_data;
123
124         dev->settings.osr_h = BME280_OVERSAMPLING_4X;
125         dev->settings.osr_p = BME280_OVERSAMPLING_4X;
126         dev->settings.osr_t = BME280_OVERSAMPLING_4X;
127
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 */
132         dev->delay_ms(5);
133         
134         while (1) {
135                 rslt = bme280_get_sensor_data(BME280_PRESS | BME280_HUM | BME280_TEMP, &comp_data, dev);
136                 print_sensor_data(&comp_data);
137         }
138
139         return rslt;
140 }
141
142 void print_sensor_data(struct bme280_data *comp_data)
143 {
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);
146 #else
147                 printf("%ld\t\t%ld\t\t%ld\t\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
148 #endif
149 }
150 ```
151
152 ## Copyright (C) 2016 - 2017 Bosch Sensortec GmbH