Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:esp32:emb1b_1 [2024/03/06 15:06] – [Prerequisites] pczekalskien:iot-open:practical:hardware:sut:esp32:emb1b_1 [2025/04/28 20:32] (current) – [Steps] pczekalski
Line 1: Line 1:
 ====== EMB1B: Reading environmental data with a Bosch integrated sensor ===== ====== EMB1B: Reading environmental data with a Bosch integrated sensor =====
-In this scenario, we will read environmental data using a BME 280 sensor. It is one of the most popular sensors in weather stations. It integrates a digital thermometer, hygrometer (air humidity), and air pressure meter on a single chip+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'digital thermometer, hygrometer (air humidity), and air pressure meter. This sensor is located inside the yellow pressure chamber, under the fan in our laboratory nodes.\\ 
-The sensor communicates with the microcontroller using I2C. In 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, but it is also complementary to the scenario EMB1A [[en:iot-open:practical:hardware:sut:esp32:emb1a_1|]] and may enable you to monitor the results of the fan operation that should induct changes in the air pressure.+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:iot-open:practical:hardware:sut:esp32:emb1a_1|]] and may enable you to monitor the results of the fan operation that should induce changes in the air pressure.
  
 ===== Prerequisites ===== ===== Prerequisites =====
Line 33: Line 33:
  
 ==== Start ==== ==== Start ====
-//Write starting conditionsi.ewhat to do in the beginningwhat to pay attention to before beginning, how the mechanical part should look, etc.// Include needed compiler configuration, etc.+For static measurementsensure the fan is stoppedNote that the fan tends to spin up on itself (explained in EMB1A) when the GPIO controlling the fan is not configuredso it is better to ensure it is set to output and low (0) to keep the fan stoppedRefer to the [[en:iot-open:practical:hardware:sut:esp32:emb1a_1|]] for details on controlling the fan. 
 + 
  
 ==== Steps ==== ==== Steps ====
-// Write some extra information if, i.e. some steps are optional; otherwise, cancel this paragraph (but do not remove the header).//+The steps below present only interaction with the sensorThose steps should be supplied to present the data (or send it over the networkusing other scenarios accordingly, and also with a scenario EMB1A presenting no instructions on controlling the fan that can change the air pressure in the yellow pressure chamber. 
 === Step 1 === === Step 1 ===
-//Describe activities done in Step 1.//+Include a BME 280 control library: 
 +<code c> 
 +#include <Adafruit_BME280.h> 
 +</code> 
 + 
 +=== Step 2 === 
 +Declare BME's address, sensor controller class and variables to store readings: 
 +<code c> 
 +#define SCL 4 
 +#define SDA 5 
 + 
 +static const int BME280_addr = 0x76; //I2C address 
 + 
 +static bool isBMEOk = false; 
 + 
 +static float temperature; 
 +static float pressure; 
 +static float humidity; 
 + 
 +static Adafruit_BME280 bme280; //controller class 
 +</code>
  
 +=== Step 3 ===
 +Initialise the I2C bus and the controller class:
 +<code c>
 +Wire.begin(SDA,SCL); 
 +delay(100);
 ... ...
 +isBMEOk = bme280.begin(BME280_addr);
 +</code>
 +If ''begin'' returns ''false'', then initialisation failed. This may be due to an invalid I2C address provided as a parameter of the ''begin'' function, a broken sensor, or broken connections between the MCU and the sensor.
  
-=== Step === +<note important>You need to initialise the I2C bus only once. If you're using other I2C devices in parallel, do not call ''Wire.begin(...)'' multiple times.</note> 
-//Describe activities done in Step n.//+=== Step === 
 +Read environmental data (one at a time): 
 +<code c> 
 +  temperature = bme280.readTemperature(); 
 +  pressure = bme280.readPressure() 100.0F; 
 +  humidity = bme280.readHumidity(); 
 +</code> 
 +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 Altitude based on the sea-level pressure (needed to have a correct reading:
 +<code c>
 + float altitude = bme280.readAltitude(1013.00F);
 +</code>
 +
 +You need to know the sea level pressure (a parameter, here, 1013hPa). It uses ''readPressure()'' internally and returns the altitude level. 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 the current sea level pressure if only altitude and local air pressure are known. It does not read the sensor itself, however:
 +<code c>
 +  float seaLevelPressure = bme280.seaLevelForAltitude(230, bme280.readPressure());
 +</code>
 +In the example above, the first parameter is the altitude (230m).
 ==== Result validation ==== ==== Result validation ====
-//Provide some result validation methods for self-assessment.//+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 =====
-This section is to be extended as new questions appear. \\ +**I've got NaN (Not a Number) readings. What to do?**: Check if GPIO is OK (should be 47)check if you initialised the controller class and most of all, give the sensor some recovery time (at least 250ms) between consecutive readings.
-When using the printed version of this manualplease refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ. +
-//Provide some FAQs in the following form:\\ +
-**Question?**: Answer. +
-//+
  
 +<WRAP noprint>
 ===== Project information ===== ===== Project information =====
 {{:en:iot-open:logo_iot_200_px.png?200|}}\\ {{:en:iot-open:logo_iot_200_px.png?200|}}\\
Line 71: Line 118:
 {{:en:iot-open:ccbync.png?100|}} {{:en:iot-open:ccbync.png?100|}}
 </figure> </figure>
- +</WRAP>
- +
en/iot-open/practical/hardware/sut/esp32/emb1b_1.1709737613.txt.gz · Last modified: 2024/03/06 15:06 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0