BMP280 (bmp280 v0.2.3) View Source
Read temperature and pressure from a Bosch BM*280 sensors
Here's an example use:
iex> {:ok, bmp} = BMP280.start_link(bus_name: "i2c-1", bus_address: 0x77)
{:ok, #PID<0.29929.0>}
iex> BMP280.read(bmp)
{:ok,
%BMP280.Measurement{
altitude_m: 13.842046523689644,
dew_point_c: 18.438691684856007,
humidity_rh: 51.59938493850065,
pressure_pa: 99836.02154563366,
temperature_c: 29.444089211523533
}}
Depending on your hardware configuration, you may need to modify the call to
BMP280.start_link/1
. See BMP280.options/0
for parameters.
All measurements are reported in SI units.
The altitude measurement is computed from the measured barometric pressure. To be accurate, it requires either the current sea level pressure or the current altitude. Here's an example:
iex> BMP280.force_altitude(bmp, 100)
:ok
Subsequent altitude reports should be more accurate until the weather changes.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Detect the type of sensor that is located at the I2C address
Force the altitude to a known value
Read the current temperature, pressure, altitude
Return the type of sensor
Start a new GenServer for interacting with a BMP280
Update the sea level pressure estimate
Link to this section Types
Specs
options() :: [ name: GenServer.name(), bus_name: String.t(), bus_address: Circuits.I2C.address(), sea_level_pa: number() ]
BMP280 GenServer start_link options
:name
- a name for the GenServer:bus_name
- which I2C bus to use (e.g.,"i2c-1"
):bus_address
- the address of the BMP280 (defaults to 0x77):sea_level_pa
- a starting estimate for the sea level pressure in Pascals
Specs
sensor_type() :: :bmp280 | :bme280 | 0..255
The type of sensor in use.
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Specs
detect(String.t(), Circuits.I2C.address()) :: {:ok, sensor_type()} | {:error, any()}
Detect the type of sensor that is located at the I2C address
If the sensor is a known BMP280 or BME280 the response will either contain
:bmp280
or :bme280
. If the sensor does not report back that it is one of
those two types of sensors the return value will contain the id value that
was reported back form the sensor.
The bus address is likely going to be 0x77 (the default) or 0x76.
Specs
force_altitude(GenServer.server(), number()) :: :ok | {:error, any()}
Force the altitude to a known value
Altitude calculations depend on the accuracy of the sea level pressure estimate. Since the sea level pressure changes based on the weather, it needs to be kept up to date or altitude measurements can be pretty far off. Another way to set the sea level pressure is to report a known altitude. Call this function with the current altitude in meters.
This function returns an error if the attempt to sample the current barometric pressure fails.
Specs
read(GenServer.server()) :: {:ok, BMP280.Measurement.t()} | {:error, any()}
Read the current temperature, pressure, altitude
An error is return if the I2C transactions fail.
Specs
sensor_type(GenServer.server()) :: sensor_type()
Return the type of sensor
This function returns the cached result of reading the ID register. if the part is recognized. If not, it returns the integer read.
Specs
start_link(options()) :: GenServer.on_start()
Start a new GenServer for interacting with a BMP280
Normally, you'll want to pass the :bus_name
option to specify the I2C
bus going to the BMP280.
Specs
update_sea_level_pressure(GenServer.server(), number()) :: :ok
Update the sea level pressure estimate
The sea level pressure should be specified in Pascals. The estimate is used for altitude calculations.