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:esp32:emb1b_1 [2024/03/22 10:01] – [Project information] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb1b_1 [2025/04/28 20:32] (current) – [Steps] pczekalski | ||
---|---|---|---|
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 I2C. In all our laboratory nodes, it uses the I2C bus on GPIOs 5 (SDA) and 4 (SCL) and is visible under the I2C address 0x76.\\ | The sensor communicates with the microcontroller using I2C. In all our laboratory nodes, it uses the I2C bus on GPIOs 5 (SDA) and 4 (SCL) and is visible under the I2C address 0x76.\\ | ||
- | This scenario can be run stand-alone to read weather data in the laboratory nodes' room. Still, it is also complementary to the scenario EMB1A [[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 EMB1A [[en: |
===== Prerequisites ===== | ===== Prerequisites ===== | ||
Line 33: | Line 33: | ||
==== Start ==== | ==== Start ==== | ||
- | For statical | + | For static |
Line 49: | Line 49: | ||
Declare BME's address, sensor controller class and variables to store readings: | Declare BME's address, sensor controller class and variables to store readings: | ||
<code c> | <code c> | ||
+ | #define SCL 4 | ||
+ | #define SDA 5 | ||
+ | |||
static const int BME280_addr = 0x76; //I2C address | static const int BME280_addr = 0x76; //I2C address | ||
Line 61: | Line 64: | ||
=== Step 3 === | === Step 3 === | ||
- | Initialise controller class: | + | Initialise |
<code c> | <code c> | ||
+ | Wire.begin(SDA, | ||
+ | delay(100); | ||
+ | ... | ||
isBMEOk = bme280.begin(BME280_addr); | isBMEOk = bme280.begin(BME280_addr); | ||
</ | </ | ||
If '' | If '' | ||
+ | <note important> | ||
=== Step 4 === | === Step 4 === | ||
Read environmental data (one at a time): | Read environmental data (one at a time): | ||
Line 83: | Line 90: | ||
You need to know the sea level pressure (a parameter, here, 1013hPa). It uses '' | You need to know the sea level pressure (a parameter, here, 1013hPa). It uses '' | ||
- | 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 |
<code c> | <code c> | ||
float seaLevelPressure = bme280.seaLevelForAltitude(230, | float seaLevelPressure = bme280.seaLevelForAltitude(230, | ||
</ | </ | ||
- | In the example above first parameter | + | In the example above, the first parameter is the altitude (230m). |
==== Result validation ==== | ==== Result validation ==== | ||
The observable temperature is usually within the range of 19-24C, with humidity about 40-70%, strongly depending on the weather. On rainy days, it can even go higher. Air pressure depends on the current weather (assuming the fan is off) and is usually low to 890hPa (when low-pressure area) and even up to 1040hPa (when high-pressure area comes, usually during the summer). Spinning the fan may easily change air pressure by at least 1-2Pa up relative to the static pressure, depending on the fan's rotation speed. | The observable temperature is usually within the range of 19-24C, with humidity about 40-70%, strongly depending on the weather. On rainy days, it can even go higher. Air pressure depends on the current weather (assuming the fan is off) and is usually low to 890hPa (when low-pressure area) and even up to 1040hPa (when high-pressure area comes, usually during the summer). Spinning the fan may easily change air pressure by at least 1-2Pa up relative to the static pressure, depending on the fan's rotation speed. | ||
===== 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 GPIO is OK (should be 47), check if you initialised |
<WRAP noprint> | <WRAP noprint> |