Skip to content

Latest commit

 

History

History
100 lines (73 loc) · 3.21 KB

README.md

File metadata and controls

100 lines (73 loc) · 3.21 KB

BME280

Build status Alire REUSE status

Humidity sensor measuring relative humidity, barometric pressure and ambient temperature

The sensor is available as a module for DIY projects from various manufacturers, such as Adafruit and SparkFun. It boasts high accuracy, a compact size, and the flexibility to connect via both I2C and SPI interfaces.

The BME280 driver enables the following functionalities:

  • Detect the presence of the sensor.
  • Perform a reset operation.
  • Configure the parameters of the IRR filter and oversampling for each channel.
  • Read calibration coefficients.
  • Conduct measurements and calibrate the obtained values.
  • Calculate the time required for measurements.

Install

Add bme280 as a dependency to your crate with Alire:

alr with bme280

Usage

The driver implements two usage models: the generic package, which is more convenient when dealing with a single sensor, and the tagged type, which allows easy creation of objects for any number of sensors and uniform handling.

Generic instantiation looks like this:

declare
   package BME280_I2C is new BME280.I2C
     (I2C_Port    => STM32.Device.I2C_1'Access,
      I2C_Address => 16#76#);

begin
   if BME280_I2C.Check_Chip_Id then
      BME280_I2C.Reset (Ravenscar_Time.Delays, Ok);
      ...

While declaring object of the tagged type looks like this:

declare
   Sensor : BME280.I2C_Sensors.BME280_I2C_Sensor :=
     (I2C_Port    => STM32.Device.I2C_1'Access,
      I2C_Address => 16#76#,
      Calibration => <>);
begin
   if Sensor.Check_Chip_Id then
      Sensor.Reset (Ravenscar_Time.Delays, Ok);
      ...

Examples

You need Ada_Drivers_Library in adl directory. Clone it then run Alire to build:

git clone https://github.com/AdaCore/Ada_Drivers_Library.git adl
cd examples
alr build

GNAT Studio

Launch GNAT Studio with Alire:

cd examples; alr exec gnatstudio -- -P bme280_put/bme280_put.gpr

VS Code

Make sure alr in the PATH. Open the examples folder in VS Code. Use pre-configured tasks to build projects and flash (openocd or st-util). Install Cortex Debug extension to launch pre-configured debugger targets.

Example of calibration data:

(t1 => 28502, t2 => 26652, t3 => 50,
 p1 => 37088, p2 => -10615, p3 => 3024, p4 => 8809, p5 => -130,
 p6 => -7, p7 => 9900, p8 => -10230, p9 => 4285,
 h1 => 75, h2 => 375, h3 => 0, h4 => 289, h5 => 50, h6 => 30)