upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for bmp280.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 Intel Corporation.
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "upm_utilities.h"
#include "bmp280.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
// Instantiate a BMP280 instance using default i2c bus and address
bmp280_context sensor = bmp280_init(BMP280_DEFAULT_I2C_BUS,
BMP280_DEFAULT_ADDR, -1);
if (!sensor)
{
printf("bmp280_init() failed\n");
return 1;
}
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
// bmp280_init(BMP280_DEFAULT_SPI_BUS,
// -1, 10)
while (shouldRun)
{
// update our values from the sensor
if (bmp280_update(sensor))
{
printf("bmp280_update() failed\n");
bmp280_close(sensor);
return 1;
}
printf("Compensation Temperature: %f C\n",
printf("Pressure: %f Pa\n", bmp280_get_pressure(sensor));
printf("Computed Altitude: %f m\n\n", bmp280_get_altitude(sensor));
upm_delay(1);
}
printf("Exiting...\n");
bmp280_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _bmp280_context
 

Functions

bmp280_context bmp280_init (int bus, int addr, int cs)
 
void bmp280_close (bmp280_context dev)
 
upm_result_t bmp280_update (const bmp280_context dev)
 
uint8_t bmp280_get_chip_id (const bmp280_context dev)
 
void bmp280_reset (const bmp280_context dev)
 
float bmp280_get_temperature (const bmp280_context dev)
 
float bmp280_get_humidity (const bmp280_context dev)
 
float bmp280_get_pressure (const bmp280_context dev)
 
void bmp280_set_sea_level_pressure (const bmp280_context dev, float seaLevelhPA)
 
float bmp280_get_altitude (const bmp280_context dev)
 
void bmp280_set_usage_mode (const bmp280_context dev, BMP280_USAGE_MODE_T mode)
 
void bmp280_set_oversample_rate_temperature (const bmp280_context dev, BMP280_OSRS_T_T rate)
 
void bmp280_set_oversample_rate_pressure (const bmp280_context dev, BMP280_OSRS_P_T rate)
 
void bmp280_set_oversample_rate_humidity (const bmp280_context dev, BME280_OSRS_H_T rate)
 
void bmp280_set_timer_standby (const bmp280_context dev, BMP280_T_SB_T tsb)
 
void bmp280_set_filter (const bmp280_context dev, BMP280_FILTER_T filter)
 
void bmp280_set_measure_mode (const bmp280_context dev, BMP280_MODES_T mode)
 
uint8_t bmp280_get_status (const bmp280_context dev)
 
uint8_t bmp280_read_reg (const bmp280_context dev, uint8_t reg)
 
int bmp280_read_regs (const bmp280_context dev, uint8_t reg, uint8_t *buffer, int len)
 
upm_result_t bmp280_write_reg (const bmp280_context dev, uint8_t reg, uint8_t val)
 

Typedefs

typedef struct _bmp280_contextbmp280_context
 

Function Documentation

bmp280_context bmp280_init ( int  bus,
int  addr,
int  cs 
)

BMP280 initialization.

This driver supports both the BMP280 and the BME280. The BME280 adds a humidity sensor. The device type is detected automatically by querying the chip id register.

Both I2C and SPI accesses are supported. For SPI, set the addr to -1, and specify a positive integer representing the Chip Select (CS) pin for the cs argument. If you are using a hardware CS pin you cannot control (Intel Edison), then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs. The default operating mode is I2C.

Parameters
busI2C or SPI bus to use.
addressThe I2C address for this device. Use -1 for SPI.
csThe gpio pin to use for the SPI Chip Select. Use -1 for I2C, or for SPI with a hardware controlled pin.
Returns
Device context, or NULL on error.

Here is the call graph for this function:

void bmp280_close ( bmp280_context  dev)

BMP280 close function.

Parameters
devDevice context.

Here is the caller graph for this function:

upm_result_t bmp280_update ( const bmp280_context  dev)

Update the internal stored values from sensor data.

Parameters
devDevice context.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t bmp280_get_chip_id ( const bmp280_context  dev)

Return the chip ID.

Parameters
devDevice context.
Returns
The chip ID (BMP280_CHIPID).

Here is the call graph for this function:

Here is the caller graph for this function:

void bmp280_reset ( const bmp280_context  dev)

Reset the sensor, as if by a power-on-reset.

Parameters
devDevice context.

Here is the call graph for this function:

Here is the caller graph for this function:

float bmp280_get_temperature ( const bmp280_context  dev)

Return the current measured temperature. Note, this is not ambient temperature - this is the temperature used to fine tune the pressure measurement. bmp280_update() must have been called prior to calling this method.

Parameters
devDevice context.
Returns
The temperature in degrees Celsius.

Here is the caller graph for this function:

float bmp280_get_humidity ( const bmp280_context  dev)

Return the current measured relative humidity (bme280 only). bmp280_update() must have been called prior to calling this method. For a bmp280, the returned value will always be 0.

Parameters
devDevice context.
Returns
The relative humidity in percent.

Here is the caller graph for this function:

float bmp280_get_pressure ( const bmp280_context  dev)

Return the current measured pressure in Pascals (Pa). bmp280_update() must have been called prior to calling this method.

Parameters
devDevice context.
Returns
The pressure in Pascals (Pa).

Here is the caller graph for this function:

void bmp280_set_sea_level_pressure ( const bmp280_context  dev,
float  seaLevelhPA 
)

Set the default Sea Level Pressure in hectoPascals (hPA). A default of 1013.25 (101325 Pa) is set during bmp280_init(). This value is used for altitude computation.

Parameters
devDevice context.
seaLevelhPAThe pressure at sea level in hectoPascals (hPa).

Here is the caller graph for this function:

float bmp280_get_altitude ( const bmp280_context  dev)

Return the current computed altitude in meters. bmp280_update() must have been called prior to calling this method.

Computing this value requires knowing the pressure at sea level. bmp280_init() sets this by default to 1013.25 hPA. Use bmp280_set_sea_level_pressure() to change this value.

Parameters
devDevice context.
Returns
The computed altitude in meters.

Here is the caller graph for this function:

void bmp280_set_usage_mode ( const bmp280_context  dev,
BMP280_USAGE_MODE_T  mode 
)

Set a general usage mode. This function can be used to configure the filters and oversampling for a particular use case. These setting are documented in the BMP280 datasheet. The default mode set in the bmp280_init() function is BMP280_USAGE_MODE_INDOOR_NAV, the highest resolution mode.

Parameters
devDevice context.
modeOne of the BMP280_USAGE_MODE_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmp280_set_oversample_rate_temperature ( const bmp280_context  dev,
BMP280_OSRS_T_T  rate 
)

Set the temperature sensor oversampling parameter. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for bmp280_set_usage_mode().

Parameters
devDevice context.
rateOne of the BMP280_OSRS_T_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmp280_set_oversample_rate_pressure ( const bmp280_context  dev,
BMP280_OSRS_P_T  rate 
)

Set the pressure sensor oversampling parameter. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for bmp280_set_usage_mode().

Parameters
devDevice context.
rateOne of the BMP280_OSRS_P_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmp280_set_oversample_rate_humidity ( const bmp280_context  dev,
BME280_OSRS_H_T  rate 
)

Set the humidity sensor oversampling parameter (BME280 only). See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for bmp280_set_usage_mode().

Parameters
devDevice context.
rateOne of the BME280_OSRS_H_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmp280_set_timer_standby ( const bmp280_context  dev,
BMP280_T_SB_T  tsb 
)

Set the timer standby value. When in NORMAL operating mode, this timer governs how long the chip will wait before performing a measurement. See the data sheet for details.

Parameters
devDevice context.
tsbOne of the BMP280_T_SB_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmp280_set_filter ( const bmp280_context  dev,
BMP280_FILTER_T  filter 
)

Set the IIR filtering parameter. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for bmp280_set_usage_mode().

Parameters
devDevice context.
filterOne of the BMP280_FILTER_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmp280_set_measure_mode ( const bmp280_context  dev,
BMP280_MODES_T  mode 
)

Set the default measuring mode. Basic values are forced, sleep, and normal. See the data sheet for details. This value can be automatically set to a suitable value by using one of the predefined modes for bmp280_set_usage_mode().

Parameters
devDevice context.
modeOne of the BMP280_MODES_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t bmp280_get_status ( const bmp280_context  dev)

Return the value of the BMP280_REG_STATUS register.

Parameters
devDevice context.
Returns
Contents of the status register.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t bmp280_read_reg ( const bmp280_context  dev,
uint8_t  reg 
)

Read a register.

Parameters
devDevice context.
regThe register to read
Returns
The value of the register

Here is the caller graph for this function:

int bmp280_read_regs ( const bmp280_context  dev,
uint8_t  reg,
uint8_t *  buffer,
int  len 
)

Read contiguous registers into a buffer. This is a low level function, and should not be used unless you know what you are doing.

Parameters
devDevice context.
bufferThe buffer to store the results
lenThe number of registers to read
Returns
The number of bytes read, or -1 on error

Here is the caller graph for this function:

upm_result_t bmp280_write_reg ( const bmp280_context  dev,
uint8_t  reg,
uint8_t  val 
)

Write to a register. This is a low level function, and should not be used unless you know what you are doing.

Parameters
devDevice context.
regThe register to write to
valThe value to write
Returns
UPM result.

Here is the caller graph for this function:

Typedef Documentation

typedef struct _bmp280_context * bmp280_context

Device context