An Elixir library to interface with the BME680 and BME280 environmental sensors. The BME680 provides measurements of temperature, pressure, humidity, and gas resistance (which is a proxy of indoor air quality). The BME280 is a lower cost device that only provides measurements of temperature, pressure, humidity.
The package can be installed
by adding elixir_bme680
to your list of dependencies in mix.exs
:
def deps do
[
{:elixir_bme680, "~> 0.2.2"}
]
end
The Linux I2C driver needs to be installed for this library to work (e.g.
libi2c-dev
on Debian). If using Nerves, the
driver should already be installed by default.
Depending on your hardware configuration, you may need to specify options to Bme680.start_link/2
or Bme280.start_link/2
.
For example, the i2c address of the sensor can be 0x76
or 0x77
.
{:ok, pid} = Bme680.start_link(i2c_address: 0x76)
measurement = Bme680.measure(pid)
# Measurement is like:
#
# %Bme680.Measurement{
# temperature: 21.74,
# pressure: 1090.52,
# humidity: 45.32,
# gas_resistance: 10235
# }
#
# Where temperature is in degrees Celsius, pressure in hPa, humidity in %
# relative humidity, and gas_resistance in Ohm
For more information, read the API documentation.
The default setting has been tested on the Pimoroni
BME680. The Adafruit
BME680 requires using a different i2c
address. For the Adafruit, pass in the i2c_address
option with value 0x77
as
follows:
Bme680.start_link(i2c_address: 0x77)
Note that, due to the nature of the BME680 gas resistance sensor, the gas resistance measurement needs a warm-up in order to give stable measurements. One possible strategy is to perform continuous meaurements in a loop until the value stabilizes. That might take from a few seconds to several minutes (or more when the sensor is brand new).
{:ok, pid} = Bme280.start_link(i2c_address: 0x76)
measurement = Bme280.measure(pid)
# Measurement is like:
#
# %Bme280.Measurement{
# temperature: 21.74,
# pressure: 30.52,
# humidity: 45.32
# }
#
# Where temperature is in degrees Celsius, pressure in inHg, humidity in %
# relative humidity
For more information, read the API documentation.
The default setting has been tested on the HiLetgo BME280.
This project contains low-level code from the BME680 driver by Bosch and the BME280 driver by Bosch.