Introduction: Adding the BMP180 to the ESP8266

About: I am a physician by trade. After a career in the pharmeceutical world I decided to take it a bit slower and do things I like. Other than my hobbies that involves grassroots medicine in S.E.&P Asia. I have buil…

After adding an RTC and an OLED to the ESP8266-01 through I2C, I presumed it should not be too difficult to add a BMP180 sensor as well, in spite of coming across some postings on Internet of people not succeeding.

My BMP180 module -from my Arduino days- was a 5 Volt module, which made me think I may need a level shifter, which would be a pity as the BMP180 is in fact a 3.3V chip.

The circuit of my BMP180 module shows that the I2C pull up resistors (4k7) are in fact connected to the 3.3 V line that is provided by a 662k (as was to be expected). This meant that even if I fed the module with 5 Volt, I would not need a level shifter. And as the 662K is a low drop regulator and the BMP 180 also works with voltages lower than 3.3, I presumed I didn't need 5 Volt whatsoever
The connection of the BMP180 is simple Vcc to Vcc, Ground to ground, SDA to SDA and SCL to SCL. On the ESP8266 I am using GPIO0 as SDA and GPIO2 as SCL


Just some remarks on the BOM

  • ESP8266-01: If you still have to buy this, consider an ESP8266-12. it isn't much more expensive and has more pins. Some modules like Wemos D1 even have an USB added
  • BMP180: If you still need to buy this, consider a BMP280 that is more precise and cheaper or even a BME280 that can also measure humidity. The BME280 is slightly more expensive. I have not been able to test it, but the BMP280 needs a different library and the BME280 needs a different library.
  • Adafruit BMP_085 Library. This is the 'Old' library. Adafruit has a newer one that I found less pleasant to work with and I seem to remember it also needed the Adafruit 'unified sensor' library. There is a Sparkfun library as well
  • The female and male headers and the piece of veroboard are used to make a breadboard friendly adapter for the ESP8266-01
  • If you dont have a 3.3 Volt USB-TTL adapter yet and are only planning to work with the ESP8266-01, consider this handy device.
  • The OLED is just used to display the values. Ofcourse you may use an LCD as well, or forget about the display and send it off to a website or Thingspeak

Step 1: The Connections

This couldn't be simpler:
I used GPIO0 as SDA and GPIO2 as SCL. The BMP180 and OLED have the pin nominations clearly stamped on them so you only need to connect as follows All Vcc-s together All Grounds together BMP180 and OLED SDA pins to GPIO0 BMP180 and OLED SCL pins to GPIO2 Finally connect the CH_PD pin with Vcc Make sure you identify the proper pins. Your modules may have a pin sequence that differs from mine

Step 2: The Code

I presume you do know how to program the ESP8266. In short:
Connect Tx<->Rx (meaning the Tx of your ESP to the Rx of your USB-TTL converter)
Connect Rx<->Tx
Connect CH_PD<->Vcc
Connect GPIO0 <->Grnd
Connect Vcc <-> Vcc (Only if you have a 3.3 volt Vcc)
Connect Grnd <-> Grnd

#include <Wire.h>
#include <Adafruit_BMP085.h>
#include "SSD1306.h"
Adafruit_BMP085 bmp;
SSD1306  display(0x3c, 0, 2);

void setup() {
  Wire.pins(0, 2);
  Wire.begin(0, 2);
  if (!bmp.begin()) {
    //   Serial.println("No BMP180 / BMP085");// we dont wait for this
    //   while (1) {}
  display.flipScreenVertically();// I turn the screen coz easier in my setup

void loop() {

  String t = "T=" + String(bmp.readTemperature()) + " *C";
  String p = "P=" + String(bmp.readPressure()) + " Pa";
  String a = "A=" + String(bmp.readAltitude(103000)) + " m";// insert pressure at sea level

  display.drawString(0, 10, t);
  display.drawString(0, 24, p);
  display.drawString(0, 38, a);
  // write the buffer to the display

As you can see, one of the parameters is the Altitude. This value is only correct if you supply the program with the pressure at sea level for your location. As that pressure can change, it is not of real value. On the other hand, as the altitude or elevation is much less likely to change (unless you are mobile), you could provide the known elevation for your location and then back calculate the pressure at sea level. Or... given the fact you have a WiFi processor available, read the current pressure at sea level from a web site and then calculate your altitude.
If you know your elevation and want to calculate the pressure at sealevel, use

String s="S="+ String(bmp.readSealevelPressure(19))+" Pa";

and then print the string 's' (without quotes)

The temperature readings of the BMP180, though precise, still can be off (too high) if the sensor is mounted too close to the ESP8266. Whether this is a result of the HF radio waves or just direct heat of the processor is still being argued. I think it is the latter