Pressure, humidity and temperature, BME280
Temperature, humidity and air pressure as raw counts, and the datasheet sums that turn them into weather.
- 4 pins
- 4 settings
- In 3 projects
- In 1 lesson
The Pressure, humidity and temperature, BME280 in brief
What it is, and every setting the properties panel gives it.
The BME280 is Bosch’s pressure, humidity and temperature sensor, almost always bought on the purple GY-BME280 breakout with four pins: VIN, GND, SCL and SDA. The module has its own regulator and pull-ups, so VIN takes 3.3 or 5 V; on an Uno SDA and SCL go to A4 and A5, and on an ESP32 DevKit to GPIO 21 and 22. Its address is 0x76 on most purple boards, which is the part’s default, or 0x77 with the strap, where Adafruit’s library looks first. Mokxi models the register map from the datasheet: chip id 0x60 at 0xD0, raw twenty-bit counts plus the factory calibration a driver has to apply, sleep at power-up, forced and normal modes, measurement times from 8 ms at 1x oversampling to 113 ms at 16x, and the IIR filter. The temperature, pressure and humidity sliders are worked backwards into counts, so a correct driver reads them back. The classic mistake is begin() failing at the wrong address; in a hand-written driver it is humidity set in ctrl_hum, which only takes effect at the next ctrl_meas write. Noise, SPI mode and the humidity sensor’s slow response are not modeled.
- Family
- Sensors
- Pins
- 4
- address
- 118
- temperature
- 22
- pressure
- 1013.25
- humidity
- 50
4 pins
Named as the editor names them, so a wire lands where you expect it.
How to use the BME280 with an Arduino or ESP32
Four wires: VIN to 3.3 V or 5 V, GND to GND, and SDA and SCL to the board’s I2C pins. The project here runs on an ESP32-C3, whose I2C pins are GPIO 8 for SDA and GPIO 9 for SCL, and puts a BME280 at 0x76 and a BMP280 at 0x77 on the same two wires: the address strap is what lets them share. The chip id at 0xD0 tells them apart, 0x60 for the BME280 and 0x58 for the BMP280.
With Adafruit_BME280, give begin() the address. Most purple boards are at 0x76 and the library looks at 0x77 unless told, so a bare begin() fails on them; it also fails on a BMP280, which has no humidity. The project instead runs the datasheet’s integer formulas itself, temperature first, because pressure and humidity both need its t_fine. Drag a pressure slider and the altitude moves about 100 m for every 12 hPa.
On an Uno the module goes to A4 and A5 at 5 V, and on a classic ESP32 DevKit to GPIO 21 and 22; its regulator takes either supply.
#include <Wire.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
if (!bme.begin(0x76)) {
Serial.println("No BME280");
while (1);
}
}
void loop() {
Serial.println(bme.readTemperature());
Serial.println(bme.readPressure() / 100.0F);
Serial.println(bme.readHumidity());
delay(1000);
}What is true about the Pressure, humidity and temperature, BME280, here
In its help article’s own words: what the simulation gets right, and where it stops.
Modeled
The register map and the reset values: asleep at power-up, data registers at
0x80000 and 0x8000 until something is measured, im_update set for the 2 ms the
chip spends copying its coefficients. Forced mode takes one measurement and goes
back to sleep; normal mode measures, waits the standby time, and repeats. A
measurement takes the datasheet's typical time, from 8 ms at 1x oversampling to
113 ms at 16x, with measuring set while it runs.
ctrl_hum only takes effect at the next write to ctrl_meas, and humidity
oversampling left at 0 means no humidity at all: the register reads its reset value.
Both are straight from the datasheet and both catch people.
Resolution follows oversampling, 16 bits at 1x up to 20 at 16x, and the IIR filter blends each result into the last, so a slider moved with the filter on is followed smoothly rather than in a jump.
Not modeled
Noise. A real reading wanders by a few pascals and a few hundredths of a degree,
which is what oversampling and the filter are for; here more samples change only the
time and the number of bits. The drivers use Bosch's 32-bit pressure formula, since
the smaller boards have no 64-bit multiply, and it reads a few pascals off the 64-bit
one. SPI mode, and so CSB and SDO as pins, are not modeled: this is the I2C
module. The humidity sensor's slow response to a change in the air is not modeled.
From BME280 and BMP280 pressure sensors, in full.
See the Pressure, humidity and temperature, BME280 in a project
3 built-in projects use it. Each opens in the editor, already wired.
Where it turns up in a lesson
One lesson places it in its own circuit.
The boards it is shown on
Each of these 2 boards has a built-in project with the Pressure, humidity and temperature, BME280 in it.
The Pressure, humidity and temperature, BME280 on each board
The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Pressure, humidity and temperature, BME280
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.