RocketLogger  1.1
bme280.h File Reference
#include <errno.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "../log.h"
#include "../types.h"
+ Include dependency graph for bme280.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BME280_calibration_t
 

Macros

#define BME280_I2C_ADDRESS_LEFT   0x76
 
#define BME280_I2C_ADDRESSES   { (BME280_I2C_ADDRESS_LEFT) }
 
#define BME280_CHANNEL_TEMPERATURE   0
 
#define BME280_CHANNEL_HUMIDITY   1
 
#define BME280_CHANNEL_PREASURE   2
 
#define BME280_ID   0x60
 
#define BME280_REG_CALIBRATION_BLOCK1   0x88
 
#define BME280_REG_ID   0xD0
 
#define BME280_REG_RESET   0xE0
 
#define BME280_REG_CALIBRATION_BLOCK2   0xE1
 
#define BME280_REG_CONTROL_HUMIDITY   0xF2
 
#define BME280_REG_STATUS   0xF3
 
#define BME280_REG_CONTROL_MEASURE   0xF4
 
#define BME280_REG_CONFIG   0xF5
 
#define BME280_REG_PREASURE_MSB   0xF7
 
#define BME280_REG_PREASURE_LSB   0xF8
 
#define BME280_REG_PREASURE_XLSB   0xF9
 
#define BME280_REG_TEMPERATURE_MSB   0xFA
 
#define BME280_REG_TEMPERATURE_LSB   0xFB
 
#define BME280_REG_TEMPERATURE_XLSB   0xFC
 
#define BME280_REG_HUMIDITY_MSB   0xFD
 
#define BME280_REG_HUMIDITY_LSB   0xFE
 
#define BME280_CALIBRATION_BLOCK1_SIZE   26
 
#define BME280_CALIBRATION_BLOCK2_SIZE   7
 
#define BME280_DATA_BLOCK_SIZE   8
 
#define BME280_RESET_VALUE   0xB6
 
#define BME280_OVERSAMPLE_HUMIDITY_OFF   0x00
 
#define BME280_OVERSAMPLE_HUMIDITY_1   0x01
 
#define BME280_OVERSAMPLE_HUMIDITY_2   0x02
 
#define BME280_OVERSAMPLE_HUMIDITY_4   0x03
 
#define BME280_OVERSAMPLE_HUMIDITY_8   0x04
 
#define BME280_OVERSAMPLE_HUMIDITY_16   0x0f
 
#define BME280_MEASURING   0x03
 
#define BME280_UPDATE   0x1
 
#define BME280_OVERSAMPLE_TEMPERATURE_OFF   0x00
 
#define BME280_OVERSAMPLE_TEMPERATURE_1   0x20
 
#define BME280_OVERSAMPLE_TEMPERATURE_2   0x40
 
#define BME280_OVERSAMPLE_TEMPERATURE_4   0x60
 
#define BME280_OVERSAMPLE_TEMPERATURE_8   0x80
 
#define BME280_OVERSAMPLE_TEMPERATURE_16   0xA0
 
#define BME280_OVERSAMPLE_PREASURE_OFF   0x00
 
#define BME280_OVERSAMPLE_PREASURE_1   0x04
 
#define BME280_OVERSAMPLE_PREASURE_2   0x08
 
#define BME280_OVERSAMPLE_PREASURE_4   0x0C
 
#define BME280_OVERSAMPLE_PREASURE_8   0x10
 
#define BME280_OVERSAMPLE_PREASURE_16   0x14
 
#define BME280_MODE_SLEEP   0x00
 
#define BME280_MODE_FORCE   0x01
 
#define BME280_MODE_NORMAL   0x03
 
#define BME280_STANDBY_DURATION_0_5   0x00
 
#define BME280_STANDBY_DURATION_62   0x20
 
#define BME280_STANDBY_DURATION_125   0x40
 
#define BME280_STANDBY_DURATION_250   0x60
 
#define BME280_STANDBY_DURATION_500   0x80
 
#define BME280_STANDBY_DURATION_1000   0xA0
 
#define BME280_STANDBY_DURATION_10   0xC0
 
#define BME280_STANDBY_DURATION_20   0xE0
 
#define BME280_FILTER_OFF   0x00
 
#define BME280_FILTER_2   0x04
 
#define BME280_FILTER_4   0x08
 
#define BME280_FILTER_8   0x0C
 
#define BME280_FILTER_16   0x10
 
#define BME280_SPI_EN   0x01
 

Functions

int BME280_init (int)
 
void BME280_close (int)
 
int BME280_read (int)
 
int32_t BME280_getValue (int, int)
 
int BME280_getID (void)
 
int BME280_readCalibration (int)
 
int BME280_setParameters (int)
 
int BME280_getIndex (int)
 
int32_t BME280_compensate_temperature_fine (int, int32_t)
 
int32_t BME280_compensate_temperature (int, int32_t)
 
uint32_t BME280_compensate_preasure (int, int32_t, int32_t)
 
uint32_t BME280_compensate_humidity (int, int32_t, int32_t)
 

Macro Definition Documentation

#define BME280_CALIBRATION_BLOCK1_SIZE   26

Definition at line 78 of file bme280.h.

Referenced by BME280_readCalibration().

#define BME280_CALIBRATION_BLOCK2_SIZE   7

Definition at line 79 of file bme280.h.

Referenced by BME280_readCalibration().

#define BME280_CHANNEL_HUMIDITY   1

Definition at line 55 of file bme280.h.

Referenced by BME280_getValue().

#define BME280_CHANNEL_PREASURE   2

Definition at line 56 of file bme280.h.

Referenced by BME280_getValue().

#define BME280_CHANNEL_TEMPERATURE   0

Definition at line 54 of file bme280.h.

Referenced by BME280_getValue().

#define BME280_DATA_BLOCK_SIZE   8

Definition at line 81 of file bme280.h.

Referenced by BME280_read().

#define BME280_FILTER_16   0x10

Definition at line 123 of file bme280.h.

#define BME280_FILTER_2   0x04

Definition at line 120 of file bme280.h.

#define BME280_FILTER_4   0x08

Definition at line 121 of file bme280.h.

#define BME280_FILTER_8   0x0C

Definition at line 122 of file bme280.h.

#define BME280_FILTER_OFF   0x00

Definition at line 119 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_I2C_ADDRESS_LEFT   0x76

Copyright (c) 2016-2017, Swiss Federal Institute of Technology (ETH Zurich) All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 49 of file bme280.h.

#define BME280_I2C_ADDRESSES   { (BME280_I2C_ADDRESS_LEFT) }

Definition at line 51 of file bme280.h.

#define BME280_ID   0x60

Definition at line 59 of file bme280.h.

Referenced by BME280_init().

#define BME280_MEASURING   0x03

Definition at line 92 of file bme280.h.

#define BME280_MODE_FORCE   0x01

Definition at line 108 of file bme280.h.

#define BME280_MODE_NORMAL   0x03

Definition at line 109 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_MODE_SLEEP   0x00

Definition at line 107 of file bme280.h.

#define BME280_OVERSAMPLE_HUMIDITY_1   0x01

Definition at line 86 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_OVERSAMPLE_HUMIDITY_16   0x0f

Definition at line 90 of file bme280.h.

#define BME280_OVERSAMPLE_HUMIDITY_2   0x02

Definition at line 87 of file bme280.h.

#define BME280_OVERSAMPLE_HUMIDITY_4   0x03

Definition at line 88 of file bme280.h.

#define BME280_OVERSAMPLE_HUMIDITY_8   0x04

Definition at line 89 of file bme280.h.

#define BME280_OVERSAMPLE_HUMIDITY_OFF   0x00

Definition at line 85 of file bme280.h.

#define BME280_OVERSAMPLE_PREASURE_1   0x04

Definition at line 102 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_OVERSAMPLE_PREASURE_16   0x14

Definition at line 106 of file bme280.h.

#define BME280_OVERSAMPLE_PREASURE_2   0x08

Definition at line 103 of file bme280.h.

#define BME280_OVERSAMPLE_PREASURE_4   0x0C

Definition at line 104 of file bme280.h.

#define BME280_OVERSAMPLE_PREASURE_8   0x10

Definition at line 105 of file bme280.h.

#define BME280_OVERSAMPLE_PREASURE_OFF   0x00

Definition at line 101 of file bme280.h.

#define BME280_OVERSAMPLE_TEMPERATURE_1   0x20

Definition at line 96 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_OVERSAMPLE_TEMPERATURE_16   0xA0

Definition at line 100 of file bme280.h.

#define BME280_OVERSAMPLE_TEMPERATURE_2   0x40

Definition at line 97 of file bme280.h.

#define BME280_OVERSAMPLE_TEMPERATURE_4   0x60

Definition at line 98 of file bme280.h.

#define BME280_OVERSAMPLE_TEMPERATURE_8   0x80

Definition at line 99 of file bme280.h.

#define BME280_OVERSAMPLE_TEMPERATURE_OFF   0x00

Definition at line 95 of file bme280.h.

#define BME280_REG_CALIBRATION_BLOCK1   0x88

Definition at line 61 of file bme280.h.

Referenced by BME280_readCalibration().

#define BME280_REG_CALIBRATION_BLOCK2   0xE1

Definition at line 64 of file bme280.h.

Referenced by BME280_readCalibration().

#define BME280_REG_CONFIG   0xF5

Definition at line 68 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_REG_CONTROL_HUMIDITY   0xF2

Definition at line 65 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_REG_CONTROL_MEASURE   0xF4

Definition at line 67 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_REG_HUMIDITY_LSB   0xFE

Definition at line 76 of file bme280.h.

#define BME280_REG_HUMIDITY_MSB   0xFD

Definition at line 75 of file bme280.h.

#define BME280_REG_ID   0xD0

Definition at line 62 of file bme280.h.

Referenced by BME280_getID().

#define BME280_REG_PREASURE_LSB   0xF8

Definition at line 70 of file bme280.h.

#define BME280_REG_PREASURE_MSB   0xF7

Definition at line 69 of file bme280.h.

Referenced by BME280_read().

#define BME280_REG_PREASURE_XLSB   0xF9

Definition at line 71 of file bme280.h.

#define BME280_REG_RESET   0xE0

Definition at line 63 of file bme280.h.

#define BME280_REG_STATUS   0xF3

Definition at line 66 of file bme280.h.

#define BME280_REG_TEMPERATURE_LSB   0xFB

Definition at line 73 of file bme280.h.

#define BME280_REG_TEMPERATURE_MSB   0xFA

Definition at line 72 of file bme280.h.

#define BME280_REG_TEMPERATURE_XLSB   0xFC

Definition at line 74 of file bme280.h.

#define BME280_RESET_VALUE   0xB6

Definition at line 83 of file bme280.h.

#define BME280_SPI_EN   0x01

Definition at line 124 of file bme280.h.

#define BME280_STANDBY_DURATION_0_5   0x00

Definition at line 111 of file bme280.h.

#define BME280_STANDBY_DURATION_10   0xC0

Definition at line 117 of file bme280.h.

#define BME280_STANDBY_DURATION_1000   0xA0

Definition at line 116 of file bme280.h.

#define BME280_STANDBY_DURATION_125   0x40

Definition at line 113 of file bme280.h.

#define BME280_STANDBY_DURATION_20   0xE0

Definition at line 118 of file bme280.h.

#define BME280_STANDBY_DURATION_250   0x60

Definition at line 114 of file bme280.h.

Referenced by BME280_setParameters().

#define BME280_STANDBY_DURATION_500   0x80

Definition at line 115 of file bme280.h.

#define BME280_STANDBY_DURATION_62   0x20

Definition at line 112 of file bme280.h.

#define BME280_UPDATE   0x1

Definition at line 93 of file bme280.h.

Function Documentation

void BME280_close ( int  sensor_identifier)

Close TSL sensor.

Parameters
sensor_identifierThe I2C address of the sensor

Definition at line 89 of file bme280.c.

uint32_t BME280_compensate_humidity ( int  sensor_identifier,
int32_t  humidity_raw,
int32_t  temperature_raw 
)

Get the compensated relative humidity in micros (0.0001 percents).

Parameters
sensor_identifierThe I2C address of the sensor
humidity_rawThe raw humidity reading
temperature_rawThe raw temperature reading
Returns
The compensated humidity in micros (0.0001 percents)

Definition at line 397 of file bme280.c.

References BME280_calibration, BME280_compensate_temperature_fine(), BME280_getIndex(), BME280_calibration_t::H1, BME280_calibration_t::H2, BME280_calibration_t::H3, BME280_calibration_t::H4, BME280_calibration_t::H5, and BME280_calibration_t::H6.

Referenced by BME280_read().

+ Here is the call graph for this function:

uint32_t BME280_compensate_preasure ( int  sensor_identifier,
int32_t  preasure_raw,
int32_t  temperature_raw 
)

Get the compensated preasure in milli Pascal.

Parameters
sensor_identifierThe I2C address of the sensor
preasure_rawThe raw preasure reading
temperature_rawThe raw temperature reading
Returns
The compensated preasure in 0.001 Pascal

Definition at line 352 of file bme280.c.

References BME280_calibration, BME280_compensate_temperature_fine(), BME280_getIndex(), BME280_calibration_t::P1, BME280_calibration_t::P2, BME280_calibration_t::P3, BME280_calibration_t::P4, BME280_calibration_t::P5, BME280_calibration_t::P6, BME280_calibration_t::P7, BME280_calibration_t::P8, and BME280_calibration_t::P9.

Referenced by BME280_read().

+ Here is the call graph for this function:

int32_t BME280_compensate_temperature ( int  sensor_identifier,
int32_t  temperature_raw 
)

Get the compensated temperature in milli degree centigrade.

Parameters
sensor_identifierThe I2C address of the sensor
temperature_rawThe raw temperature reading
Returns
The compensated temperature in 0.001 degree centigrade

Definition at line 337 of file bme280.c.

References BME280_compensate_temperature_fine().

Referenced by BME280_read().

+ Here is the call graph for this function:

int32_t BME280_compensate_temperature_fine ( int  sensor_identifier,
int32_t  temperature_raw 
)

Get fine grained temperature compensation value for further processing.

Parameters
sensor_identifierThe I2C address of the sensor
temperature_rawThe raw temperature reading
Returns
Fine grained, compensated temperature (arbritrary unit)

Definition at line 310 of file bme280.c.

References BME280_calibration, BME280_getIndex(), BME280_calibration_t::T1, BME280_calibration_t::T2, and BME280_calibration_t::T3.

Referenced by BME280_compensate_humidity(), BME280_compensate_preasure(), and BME280_compensate_temperature().

+ Here is the call graph for this function:

int BME280_getID ( void  )

Get the device ID

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Devie ID or negative status code

Definition at line 169 of file bme280.c.

References BME280_REG_ID, ERROR, rl_log(), sensor_bus, and Sensors_getSharedBus().

Referenced by BME280_init().

+ Here is the call graph for this function:

int BME280_getIndex ( int  sensor_identifier)

Get the index of the sensor with specified address.

Parameters
sensor_identifierThe sensor address used to look up the index
Returns
The index of the sensor, or if not found -1

Definition at line 293 of file bme280.c.

References BME280_sensors.

Referenced by BME280_compensate_humidity(), BME280_compensate_preasure(), BME280_compensate_temperature_fine(), BME280_getValue(), BME280_read(), and BME280_readCalibration().

int32_t BME280_getValue ( int  sensor_identifier,
int  channel 
)

Get the values read from the sensor

Parameters
sensor_identifierThe I2C address of the sensor
channelThe channel of the sensor to get
Returns
Channel value

Definition at line 146 of file bme280.c.

References BME280_CHANNEL_HUMIDITY, BME280_CHANNEL_PREASURE, BME280_CHANNEL_TEMPERATURE, BME280_getIndex(), BME280_humidity, BME280_preasure, and BME280_temperature.

+ Here is the call graph for this function:

int BME280_init ( int  sensor_identifier)

Initialize the light sensor

Parameters
sensor_identifierThe I2C address of the sensor
Returns
return code

Definition at line 48 of file bme280.c.

References BME280_getID(), BME280_ID, BME280_readCalibration(), BME280_setParameters(), ERROR, FAILURE, rl_log(), sensor_bus, Sensors_getSharedBus(), Sensors_initSharedComm(), and SUCCESS.

+ Here is the call graph for this function:

int BME280_read ( int  sensor_identifier)

Read the sensor values.

Parameters
sensor_identifierThe I2C address of the sensor
Returns
Value in lux

Definition at line 98 of file bme280.c.

References BME280_compensate_humidity(), BME280_compensate_preasure(), BME280_compensate_temperature(), BME280_DATA_BLOCK_SIZE, BME280_getIndex(), BME280_humidity, BME280_preasure, BME280_REG_PREASURE_MSB, BME280_temperature, ERROR, FAILURE, rl_log(), sensor_bus, Sensors_getSharedBus(), Sensors_initSharedComm(), and SUCCESS.

+ Here is the call graph for this function:

int BME280_setParameters ( int  sensor_identifier)

Set the sensor parameter to default for continuous sensing.

Returns
Status code

Definition at line 252 of file bme280.c.

References BME280_FILTER_OFF, BME280_MODE_NORMAL, BME280_OVERSAMPLE_HUMIDITY_1, BME280_OVERSAMPLE_PREASURE_1, BME280_OVERSAMPLE_TEMPERATURE_1, BME280_REG_CONFIG, BME280_REG_CONTROL_HUMIDITY, BME280_REG_CONTROL_MEASURE, BME280_STANDBY_DURATION_250, ERROR, FAILURE, rl_log(), sensor_bus, Sensors_getSharedBus(), and SUCCESS.

Referenced by BME280_init().

+ Here is the call graph for this function: