Reformatted the README and fixed bug in documentation for reading out sensor data
This commit is contained in:
		
							
								
								
									
										156
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										156
									
								
								README.md
									
									
									
									
									
								
							@@ -1,74 +1,85 @@
 | 
				
			|||||||
# BME680 sensor API
 | 
					# BME680 sensor API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Introduction
 | 
					## Introduction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This package contains the Bosch Sensortec's BME680 gas sensor API
 | 
					This package contains the Bosch Sensortec's BME680 gas sensor API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The sensor driver package includes bme680.h, bme680.c and bme680_defs.h files
 | 
					The sensor driver package includes bme680.h, bme680.c and bme680_defs.h files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Version
 | 
					## Version
 | 
				
			||||||
 | 
					
 | 
				
			||||||
File          | Version | Date
 | 
					File          | Version | Date
 | 
				
			||||||
--------------|---------|-------------
 | 
					--------------|---------|-------------
 | 
				
			||||||
bme680.c      |  3.5.8	| 22 Feb 2018
 | 
					bme680.c      |  3.5.8    | 22 Feb 2018
 | 
				
			||||||
bme680.h      |  3.5.8	| 22 Feb 2018
 | 
					bme680.h      |  3.5.8    | 22 Feb 2018
 | 
				
			||||||
bme680_defs.h |  3.5.8	| 22 Feb 2018  
 | 
					bme680_defs.h |  3.5.8    | 22 Feb 2018  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Integration details
 | 
					## Integration details
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Integrate bme680.h, bme680_defs.h and bme680.c file in to your project.
 | 
					* Integrate bme680.h, bme680_defs.h and bme680.c file in to your project.
 | 
				
			||||||
* Include the bme680.h file in your code like below.
 | 
					* Include the bme680.h file in your code like below.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``` c
 | 
					``` c
 | 
				
			||||||
#include "bme680.h"
 | 
					#include "bme680.h"
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## File information
 | 
					## File information
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* bme680_defs.h : This header file has the constants, macros and datatype declarations.
 | 
					* bme680_defs.h : This header file has the constants, macros and datatype declarations.
 | 
				
			||||||
* bme680.h : This header file contains the declarations of the sensor driver APIs.
 | 
					* bme680.h : This header file contains the declarations of the sensor driver APIs.
 | 
				
			||||||
* bme680.c : This source file contains the definitions of the sensor driver APIs.
 | 
					* bme680.c : This source file contains the definitions of the sensor driver APIs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Supported sensor interfaces
 | 
					## Supported sensor interfaces
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* SPI 4-wire
 | 
					* SPI 4-wire
 | 
				
			||||||
* I2C
 | 
					* I2C
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Usage guide
 | 
					## Usage guide
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Initializing the sensor
 | 
					### Initializing the sensor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
To initialize the sensor, you will first need to create a device structure. You 
 | 
					To initialize the sensor, you will first need to create a device structure. You 
 | 
				
			||||||
can do this by creating an instance of the structure bme680_dev. Then go on to 
 | 
					can do this by creating an instance of the structure bme680_dev. Then go on to 
 | 
				
			||||||
fill in the various parameters as shown below
 | 
					fill in the various parameters as shown below
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Example for SPI 4-Wire
 | 
					#### Example for SPI 4-Wire
 | 
				
			||||||
``` c
 | 
					 | 
				
			||||||
	struct bme680_dev gas_sensor;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* You may assign a chip select identifier to be handled later */
 | 
					``` c
 | 
				
			||||||
	gas_sensor.dev_id = 0;
 | 
					    struct bme680_dev gas_sensor;
 | 
				
			||||||
	gas_sensor.intf = BME680_SPI_INTF;
 | 
					
 | 
				
			||||||
	gas_sensor.read = user_spi_read;
 | 
					    /* You may assign a chip select identifier to be handled later */
 | 
				
			||||||
	gas_sensor.write = user_spi_write;
 | 
					    gas_sensor.dev_id = 0;
 | 
				
			||||||
	gas_sensor.delay_ms = user_delay_ms;
 | 
					    gas_sensor.intf = BME680_SPI_INTF;
 | 
				
			||||||
 | 
					    gas_sensor.read = user_spi_read;
 | 
				
			||||||
 | 
					    gas_sensor.write = user_spi_write;
 | 
				
			||||||
 | 
					    gas_sensor.delay_ms = user_delay_ms;
 | 
				
			||||||
    /* amb_temp can be set to 25 prior to configuring the gas sensor 
 | 
					    /* amb_temp can be set to 25 prior to configuring the gas sensor 
 | 
				
			||||||
     * or by performing a few temperature readings without operating the gas sensor.
 | 
					     * or by performing a few temperature readings without operating the gas sensor.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
	gas_sensor.amb_temp = 25;
 | 
					    gas_sensor.amb_temp = 25;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int8_t rslt = BME680_OK;
 | 
					    int8_t rslt = BME680_OK;
 | 
				
			||||||
	rslt = bme680_init(&gas_sensor);
 | 
					    rslt = bme680_init(&gas_sensor);
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Example for I2C
 | 
					#### Example for I2C
 | 
				
			||||||
``` c
 | 
					 | 
				
			||||||
	struct bme680_dev gas_sensor;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
 | 
					``` c
 | 
				
			||||||
	gas_sensor.intf = BME680_I2C_INTF;
 | 
					    struct bme680_dev gas_sensor;
 | 
				
			||||||
	gas_sensor.read = user_i2c_read;
 | 
					
 | 
				
			||||||
	gas_sensor.write = user_i2c_write;
 | 
					    gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
 | 
				
			||||||
	gas_sensor.delay_ms = user_delay_ms;
 | 
					    gas_sensor.intf = BME680_I2C_INTF;
 | 
				
			||||||
 | 
					    gas_sensor.read = user_i2c_read;
 | 
				
			||||||
 | 
					    gas_sensor.write = user_i2c_write;
 | 
				
			||||||
 | 
					    gas_sensor.delay_ms = user_delay_ms;
 | 
				
			||||||
    /* amb_temp can be set to 25 prior to configuring the gas sensor 
 | 
					    /* amb_temp can be set to 25 prior to configuring the gas sensor 
 | 
				
			||||||
     * or by performing a few temperature readings without operating the gas sensor.
 | 
					     * or by performing a few temperature readings without operating the gas sensor.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
	gas_sensor.amb_temp = 25;
 | 
					    gas_sensor.amb_temp = 25;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	int8_t rslt = BME680_OK;
 | 
					    int8_t rslt = BME680_OK;
 | 
				
			||||||
	rslt = bme680_init(&gas_sensor);
 | 
					    rslt = bme680_init(&gas_sensor);
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Regarding compensation functions for temperature, pressure, humidity and gas we have two implementations.
 | 
					Regarding compensation functions for temperature, pressure, humidity and gas we have two implementations.
 | 
				
			||||||
@@ -82,63 +93,76 @@ If the user needs the floating point version, the user has to un-comment BME680_
 | 
				
			|||||||
in bme680_defs.h file or to add it in the compiler flags.
 | 
					in bme680_defs.h file or to add it in the compiler flags.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Configuring the sensor
 | 
					### Configuring the sensor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Example for configuring the sensor in forced mode
 | 
					#### Example for configuring the sensor in forced mode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``` c
 | 
					``` c
 | 
				
			||||||
	uint8_t set_required_settings;
 | 
					    uint8_t set_required_settings;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set the temperature, pressure and humidity settings */
 | 
					    /* Set the temperature, pressure and humidity settings */
 | 
				
			||||||
	gas_sensor.tph_sett.os_hum = BME680_OS_2X;
 | 
					    gas_sensor.tph_sett.os_hum = BME680_OS_2X;
 | 
				
			||||||
	gas_sensor.tph_sett.os_pres = BME680_OS_4X;
 | 
					    gas_sensor.tph_sett.os_pres = BME680_OS_4X;
 | 
				
			||||||
	gas_sensor.tph_sett.os_temp = BME680_OS_8X;
 | 
					    gas_sensor.tph_sett.os_temp = BME680_OS_8X;
 | 
				
			||||||
	gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
 | 
					    gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set the remaining gas sensor settings and link the heating profile */
 | 
					    /* Set the remaining gas sensor settings and link the heating profile */
 | 
				
			||||||
	gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
 | 
					    gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
 | 
				
			||||||
	/* Create a ramp heat waveform in 3 steps */
 | 
					    /* Create a ramp heat waveform in 3 steps */
 | 
				
			||||||
	gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
 | 
					    gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
 | 
				
			||||||
	gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */
 | 
					    gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Select the power mode */
 | 
					    /* Select the power mode */
 | 
				
			||||||
	/* Must be set before writing the sensor configuration */
 | 
					    /* Must be set before writing the sensor configuration */
 | 
				
			||||||
	gas_sensor.power_mode = BME680_FORCED_MODE; 
 | 
					    gas_sensor.power_mode = BME680_FORCED_MODE; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set the required sensor settings needed */
 | 
					    /* Set the required sensor settings needed */
 | 
				
			||||||
	set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL 
 | 
					    set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL 
 | 
				
			||||||
		| BME680_GAS_SENSOR_SEL;
 | 
					        | BME680_GAS_SENSOR_SEL;
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	/* Set the desired sensor configuration */
 | 
					 | 
				
			||||||
	rslt = bme680_set_sensor_settings(set_required_settings,&gas_sensor);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Set the power mode */
 | 
					    /* Set the desired sensor configuration */
 | 
				
			||||||
	rslt = bme680_set_sensor_mode(&gas_sensor);
 | 
					    rslt = bme680_set_sensor_settings(set_required_settings,&gas_sensor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Get the total measurement duration so as to sleep or wait till the
 | 
					    /* Set the power mode */
 | 
				
			||||||
	 * measurement is complete */
 | 
					    rslt = bme680_set_sensor_mode(&gas_sensor);
 | 
				
			||||||
	uint16_t meas_period;
 | 
					
 | 
				
			||||||
	bme680_get_profile_dur(&meas_period, &gas_sensor);
 | 
					    
 | 
				
			||||||
	user_delay_ms(meas_period); /* Delay till the measurement is ready */
 | 
					 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Reading sensor data
 | 
					### Reading sensor data
 | 
				
			||||||
#### Example for reading all sensor data
 | 
					 | 
				
			||||||
``` c
 | 
					 | 
				
			||||||
	struct bme680_field_data data;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	while(1) 
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		rslt = bme680_get_sensor_data(&data, &gas_sensor);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		printf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f,
 | 
					#### Example for reading all sensor data
 | 
				
			||||||
			data.pressure / 100.0f, data.humidity / 1000.0f );
 | 
					
 | 
				
			||||||
		/* Avoid using measurements from an unstable heating setup */
 | 
					``` c
 | 
				
			||||||
		if(data.status & BME680_GASM_VALID_MSK)
 | 
					    /* Get the total measurement duration so as to sleep or wait till the
 | 
				
			||||||
			printf(", G: %d ohms", data.gas_resistance);
 | 
					     * measurement is complete */
 | 
				
			||||||
		
 | 
					    uint16_t meas_period;
 | 
				
			||||||
		printf("\r\n");
 | 
					    bme680_get_profile_dur(&meas_period, &gas_sensor);
 | 
				
			||||||
	}
 | 
					
 | 
				
			||||||
 | 
					    struct bme680_field_data data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while(1)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        user_delay_ms(meas_period); /* Delay till the measurement is ready */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        rslt = bme680_get_sensor_data(&data, &gas_sensor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        printf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f,
 | 
				
			||||||
 | 
					            data.pressure / 100.0f, data.humidity / 1000.0f );
 | 
				
			||||||
 | 
					        /* Avoid using measurements from an unstable heating setup */
 | 
				
			||||||
 | 
					        if(data.status & BME680_GASM_VALID_MSK)
 | 
				
			||||||
 | 
					            printf(", G: %d ohms", data.gas_resistance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        printf("\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* Trigger the next measurement if you would like to read data out continuously */
 | 
				
			||||||
 | 
					        if (gas_sensor.power_mode == BME680_FORCED_MODE) {
 | 
				
			||||||
 | 
					            rslt = bme680_set_sensor_mode(&gas_sensor);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Templates for function pointers
 | 
					### Templates for function pointers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``` c
 | 
					``` c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void user_delay_ms(uint32_t period)
 | 
					void user_delay_ms(uint32_t period)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user