ESP8266-01 With Multiple I2C Devices?! || Exploring ESP8266:Part 2

Hello all! This instructable happens to be part 2 of my ESP series where I continue to experiment and explore the various features of the ESP 8266-01 board. In the first part of the series I have mentioned the wonderful capability of this little board to support I2C communication.

You can read more about this feature in Part 1: ESP-I2C Part-1

In this part of the series, we will look at the possibility of connecting multiple I2C devices and see wheather is board can handle the same.

The second I2C device used in this project is the BMP 180, temperature, altitude and pressure sensor( more details about that in the later steps). Our objective here is to acquire the temperature and pressure value from the BMP 180 sensor and then display the same on the OLED screen.

Let's dive right into it !

Step 1: Knowing Your Sensor

The BMP180 sensor is the Bosch BMP180 high-precision, low-power digital barometer.

These are the following features of this little module:

  1. I2C interface to communicate with any microcontroller
  2. 1.8 to 3.6 volts supply range (this sensor comes in with a 3.3v voltage regulator so we can power it up with standard 5 volts)
  3. 300 to 1100 hPa pressure measuring range
  4. -40 to +85 degree Celsius temperature measuring range( this is the absolute maximum)

As you can see that this module is tiny(like really tiny) but packs in a whole lot of good stuff.

This module can easily be used in weather stations or simple IoT project applications

If you want more information on this, I have attached the datasheet for your reference:

Step 2: The Block Diagram

Here, both the OLED and the BMP180 sensors are connected to the WiFi module via the I2C protocol which means that we can connect the SDA and SCK pins of both modules directly to the ESP as each module can individually be accessed using its particular address.

The connection of the OLED and the WiFi module is same as that shown in part 1, here the only addition is the BMP180 circuit.

The connection scheme is as follows:

Vcc -- > 5 volts

Gnd -- > GND

SDA --> GPIO2 of ESP8266

SCK -- > GPIO0 of ESP8266

Step 3: Breadboard Test Setup

If you are not aware, I have made a small development board based out of the ESP8266 module so that it is much much easier to access the pins, and directly program it via laptop without external programmer as it contains the programmer in itself.

I call this board ESP-O-One which has a CH340 based programmer, voltage regulator, status LEDs, access to GPIO pins, toggle switch for programming mode and operation mode and also a reset button. It is a complete system in itself and makes working with ESP8266 a lot easier.

You can check out the following instructable:

Over here with the ESP-O-One, things were quite easy to setup and for adding the two modules, I simply hooked both the display and sensor to 5 volts and connected the I2C pins together which ultimately connects to the GPIO pins of the ESP.

Step 4: The Code..

After the hardware setup, let's get to the coding part and display the values on the OLED screen. We would need a few libraries to interface the OLED as well as gather data from the BMP 180 sensor

The libraries can be found in the following link:

Link to Adafruit OLED library: Adafruit_SSD1306
Link to Adafruit BMP library: Adafruit-BMP085

The code basically can be broken down into the following steps:

  1. Importing the libraries
  2. Initialising the OLED display dimensions and address
  3. Initialising the BMP 180 library
  4. Set up the Wire library for I2C communication
  5. Setting the character size
  6. Measuring the data from the sensor and displaying it properly on the screen

I have also used the millis() function to display the amount of time that has elapsed since the project was powered on.

The code is attached in this step for your reference

    #include <SPI.h>
    #include <Wire.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    #include <Adafruit_BMP085.h>
    #define SCREEN_WIDTH 128 // OLED display width, in pixels
    #define SCREEN_HEIGHT 32 // OLED display height, in pixels
    #define OLED_RESET     1 
    Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

    char PRESSURESHOW[4];// initializing a character of size 4 for showing the  result
    char TEMPARATURESHOW[4];// initializing a character of size 4 for showing the temparature result
    Adafruit_BMP085 bmp;

    void setup() 
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
    delay(2000); // Pause for 2 seconds  
    display.setCursor(0, 0);

    if (!bmp.begin())
    display.setCursor(0, 0);  
    display.print("ERROR");///if there is an error in communication
    while (1){}


    void loop() {
        String PRESSUREVALUE = String(bmp.readPressure());
        String TEMPARATUREVALUE = String(bmp.readTemperature());
        display.setCursor(0, 0);
        display.print("Press: ");
        display.println(" hPa");
        display.setCursor(0, 10);
        display.print("Temp: ");
        display.println(" *C");
        display.setCursor(0, 20);
        display.display(); //you have to tell the display to...display

  1. Importing the Libraries that are used for initialising and setting up the OLED display
  2. Importing the Wire Library for the I2C communication.
  3. Setting up the width and height of the OLED
  4. Initialising GPIO 0 as the SDA pin
  5. Specifying the OLED address and setting up the text size and colour of the display
  6. The remaining part of the code can be found in the Adafruit library example. I have just added hose codes from there.

With everything in place, now we have to select the proper COM port and select generic ESP8266 as our target board.You can check the code snippets in this step.

Step 5: Conclusion

Handling multiple I2C devices is surely possible by this ESP module as we have seen in the example above. This opens up quite a lot of possibilities for interesting projects that can be integrated with the internet.

I hope you like part 2 of this series and I will share further updates on this project series in the upcoming instructables.

Feel free to share your feedbacks and suggestions and do watch the video at the beginning of the tutorial so as to get detailed information about this project and while you are there, don't forget to give that video a like and even consider subscribing! that would be awesome. Thanks again for going through my instructable and have a good day!