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.
Add bme280
as a dependency to your crate with Alire:
alr with bme280
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);
...
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
Launch GNAT Studio with Alire:
cd examples; alr exec gnatstudio -- -P bme280_put/bme280_put.gpr
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.
- Simple example for STM32 F4VE board - complete example for the generic instantiation.
- Advanced example for STM32 F4VE board and LCD & touch panel - complete example of the tagged type usage.