Adafruit BMP085 library: pressure and altitude from a BMP180
Yes. You can use the Adafruit BMP085 Library online in Mokxi with nothing to install, and the sketch runs in your browser against the simulated part (BMP180 pressure sensor). The example below, "Barometer", runs on the Arduino Uno R3.
Built in on Mokxi: #include <Adafruit_BMP085.h> and it builds, with nothing to install. Free, and no account needed.
What Adafruit BMP085 Library does
Bosch’s BMP085 gave way to the BMP180 long ago, but the two chips share a register map, so the library named after the old one is what BMP180 (GY-68) tutorials include. It reads temperature and barometric pressure over I2C at 0x77, and from the pressure it works out an altitude.
The chip never reports degrees or pascals directly. It gives raw counts, and at begin() the library reads eleven calibration words stored in the chip at the factory; every reading then goes through the datasheet’s integer compensation with them. The mode passed to begin(), from BMP085_ULTRALOWPOWER up to BMP085_ULTRAHIGHRES (the default), trades conversion time against noise.
Watch the units. readPressure() returns pascals as a whole number, near 101325 at sea level, and readAltitude() expects the sea-level reference in pascals as well, not hectopascals. The altitude is only as good as that reference: weather moves it by tens of meters. In Mokxi the bmp180 part has sliders for temperature and pressure, and the barometer project below prints all three values twice a second.
| Library Manager name | Adafruit BMP085 Library |
|---|---|
| Author | Adafruit |
| Include | #include <Adafruit_BMP085.h> |
| Boards | every board Mokxi compiles for but ATtiny85 |
| In the simulator | Simulated: it runs against the part the way it does on the bench. |
| Parts it drives | BMP180 pressure sensor |
Install it
It builds on every board Mokxi compiles for but ATtiny85.
In Mokxi it is built in: #include <Adafruit_BMP085.h> and the sketch compiles, with no download, no zip and no Library Manager.
On a real board, install "Adafruit BMP085 Library" by Adafruit from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit BMP085 Library to lib_deps in PlatformIO. Mokxi follows the calls of release 1.2.4, so a sketch written here builds there too.
- ESP32-C3
- Arduino Uno
- Arduino Nano
- Arduino Mega 2560
- Arduino Leonardo
- SparkFun Pro Micro
- Arduino Micro
- ESP32-C6
- WCH CH32V003
- Raspberry Pi Pico
- Raspberry Pi Pico W
- Seeed XIAO SAMD21
- STM32
- STM32 Nucleo-F411RE
- STM32 Blue Pill
- micro:bit V2
- Arduino Uno R4
- ESP32 DevKit
- ESP32-S3-DevKitC-1
- ESP8266 NodeMCU
- Arduino Pro Mini 3.3 V
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- Arduino Nano RP2040 Connect
- Seeed XIAO RP2040
- Waveshare RP2040-Zero
- Arduino Uno R4 WiFi
The calls you will use
In the order a sketch meets them.
Adafruit_BMP085 bmp
Creates the driver; nothing goes on the bus until begin().
bmp.begin()
Checks the chip ID at 0x77, reads the calibration words and returns false if the sensor is missing. bmp.begin(BMP085_STANDARD) picks a quicker, noisier mode.
bmp.readTemperature()
Degrees Celsius as a float, to a tenth of a degree.
bmp.readPressure()
Pressure in pascals as an int32_t. Divide by 100.0 for hectopascals, which are the same as millibars.
bmp.readAltitude(102000)
Meters above sea level for a given sea-level pressure in pascals. With no argument it assumes the standard 101325.
bmp.readSealevelPressure(250)
The reverse: from your known altitude in meters, the pressure at sea level in pascals, which is the figure weather reports quote.
bmp.readRawTemperature()
The uncompensated temperature count, for checking the arithmetic by hand. readRawPressure() returns the pressure count.
Example: Barometer
On the Arduino Uno R3. It runs in the browser exactly as printed.
// Barometer: a BMP180 read with the Adafruit BMP085 library, which drives the
// BMP180 too: temperature, pressure and altitude.
//
// BMP180 (GY-68) SDA -> A4 SCL -> A5 VCC -> 5 V GND -> GND
//
// The sensor does not hand over degrees and pascals. It gives raw counts and
// eleven calibration words, and the library runs the datasheet's integer
// arithmetic to turn them into a temperature to a tenth of a degree and a
// pressure to a pascal. The altitude is the barometric formula against
// standard sea-level pressure, 101325 Pa, so it is only right on a day when
// the sea-level pressure is standard: weather moves it by tens of meters.
//
// Drag the two sliders on the breakout.
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {
}
}
Serial.println("Barometer ready");
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bmp.readTemperature(), 1);
Serial.print(" *C Pressure = ");
Serial.print(bmp.readPressure());
Serial.print(" Pa Altitude = ");
Serial.print(bmp.readAltitude(), 0);
Serial.println(" meters");
delay(500);
}Open it in the editor, wired and ready to run · Barometer: the project page
Common errors and how to fix them
Could not find a valid BMP085 sensor, check wiring!
begin() did not find the BMP180’s chip ID at 0x77. Check that SDA reaches A4 and SCL reaches A5 on an Uno, and that the module has power and ground.
Altitude comes out as thousands of meters, or far below zero
readAltitude() was handed hectopascals, such as 1013.25, where it wants pascals. Pass 101325, or the local sea-level pressure multiplied by 100.
The altitude wanders by tens of meters while the board sits still
Changing weather moves the pressure, and the formula reads that as height. Update the sea-level reference from a forecast, or measure height differences over minutes rather than hours.
Questions and answers
Will this library read a BMP280?
No. The BMP280 has a different register map and needs Adafruit_BMP280.h, which Mokxi also has. Code for one does not compile against the other.
Why is the default mode the slowest one?
BMP085_ULTRAHIGHRES averages the most samples per pressure reading, which gives the steadiest figure. For a weather station read every few seconds that cost does not matter.
Keep going
Try Adafruit BMP085 Library without installing anything
Open the example, change the sketch, and keep your version in a free account.