This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:emb1b_1 [2024/04/21 08:16] – [STM_1B: Reading environmental data with a Bosch integrated sensor] ktokarz | en:iot-open:practical:hardware:sut:stm32:emb1b_1 [2024/04/21 09:41] (current) – [FAQ] ktokarz | ||
---|---|---|---|
Line 2: | Line 2: | ||
We will read environmental data using a BME 280 sensor in this scenario. It is one of the most popular sensors in weather stations. It integrates a single chip's digital thermometer, | We will read environmental data using a BME 280 sensor in this scenario. It is one of the most popular sensors in weather stations. It integrates a single chip's digital thermometer, | ||
The sensor communicates with the microcontroller using the I2C bus. In all our laboratory nodes, the I2C bus uses two GPIOs: a D14 (PB_9 in Nucleo numbering) pin for the SDA line, and a D15 (PB_8 in Nucleo numbering) pin for SCL. Every integrated circuit connected to the I2C bus has its own address. BME 280 is visible under the address 0x76. For the details please refer to Table 1: STM32WB55 Node Hardware Details in [[en: | The sensor communicates with the microcontroller using the I2C bus. In all our laboratory nodes, the I2C bus uses two GPIOs: a D14 (PB_9 in Nucleo numbering) pin for the SDA line, and a D15 (PB_8 in Nucleo numbering) pin for SCL. Every integrated circuit connected to the I2C bus has its own address. BME 280 is visible under the address 0x76. For the details please refer to Table 1: STM32WB55 Node Hardware Details in [[en: | ||
- | This scenario can be run stand-alone to read weather data in the laboratory nodes' room. Still, it is also complementary to the scenario | + | This scenario can be run stand-alone to read weather data in the laboratory nodes' room. Still, it is also complementary to the scenario [[en: |
===== Prerequisites ===== | ===== Prerequisites ===== | ||
Line 9: | Line 9: | ||
lib_deps = adafruit/ | lib_deps = adafruit/ | ||
</ | </ | ||
- | To observe air pressure changes over a short time, it is necessary to implement fan PWM control as described in the [[en: | + | To observe air pressure changes over a short time, it is necessary to implement fan PWM control as described in the [[en: |
Sensor readings can be sent over the network or presented on one of the node's displays (e.g. LCD), so understanding how to handle at least one of the displays is essential: | Sensor readings can be sent over the network or presented on one of the node's displays (e.g. LCD), so understanding how to handle at least one of the displays is essential: | ||
- | * [[en: | + | * [[en: |
- | * [[en: | + | * [[en: |
- | * [[en: | + | * [[en: |
To implement monitoring of the air pressure changes, understanding how to control a fan with PWM is necessary: | To implement monitoring of the air pressure changes, understanding how to control a fan with PWM is necessary: | ||
- | * [[en: | + | * [[en: |
Technical documentation for the BME 280 sensor is available here: | Technical documentation for the BME 280 sensor is available here: | ||
Line 24: | Line 24: | ||
===== Suggested Readings and Knowledge Resources ===== | ===== Suggested Readings and Knowledge Resources ===== | ||
* [[en: | * [[en: | ||
- | * [[en: | + | * [[en: |
- | * [[en: | + | * [[en: |
* [[en: | * [[en: | ||
===== Hands-on Lab Scenario ===== | ===== Hands-on Lab Scenario ===== | ||
Line 33: | Line 33: | ||
==== Start ==== | ==== Start ==== | ||
- | For statical measurements, | + | For statical measurements, |
==== Steps ==== | ==== Steps ==== | ||
- | The steps below present only interaction with the sensor. Those steps should be supplied to present the data (or send it over the network) using other scenarios accordingly, | + | The steps below present only interaction with the sensor. Those steps should be supplied to present the data (or send it over the network) using other scenarios accordingly, |
=== Step 1 === | === Step 1 === | ||
Line 76: | Line 76: | ||
The temperature is Celsius, air pressure is in Pascals (so we divide it by float 100 to obtain the hPa reading), and relative air humidity is in % (frequently referenced as %Rh). | The temperature is Celsius, air pressure is in Pascals (so we divide it by float 100 to obtain the hPa reading), and relative air humidity is in % (frequently referenced as %Rh). | ||
- | Note that the controller class has an exciting function of trading | + | Note that the controller class has an exciting function of trading |
<code c> | <code c> | ||
float altitude = bme280.readAltitude(1013.00F); | float altitude = bme280.readAltitude(1013.00F); | ||
</ | </ | ||
- | You need to know the sea level pressure (a parameter, here, 1013hPa). It uses '' | + | Note that due to the non-linear characteristics of the air pressure drop with increasing altitude, it does not work correctly at high altitudes. |
The library also has a mathematical calculation function that returns current sea level pressure if only altitude and local air pressure are known. It does not read the sensor itself, however: | The library also has a mathematical calculation function that returns current sea level pressure if only altitude and local air pressure are known. It does not read the sensor itself, however: | ||
Line 92: | Line 92: | ||
===== FAQ ===== | ===== FAQ ===== | ||
- | **I've got NaN (Not a Number) readings. What to do?**: Check if GPIO is OK (should be 47), check if you initialised controller class and most of all, give the sensor some recovery time (at least 250ms) between consecutive readings. | + | **I've got NaN (Not a Number) readings. What to do?**: Check if the I2C address corresponds to the BME280 sensor |
<WRAP noprint> | <WRAP noprint> |