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

by Utsav_25 in Circuits > Arduino

17335 Views, 22 Favorites, 0 Comments

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

IMG20210105223638.jpg
IMG20210105223103.jpg

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: https://www.instructables.com/I2C-With-the-ESP8266...

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 !

Knowing Your Sensor

IMG20210105223715.jpg
IMG20201227141105.jpg

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: http://cdn.sparkfun.com/datasheets/Sensors/Pressur...

The Block Diagram

Fritzing snap BMP180.png

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

Breadboard Test Setup

IMG20201227124414.jpg
IMG20201227112856.jpg

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: https://www.instructables.com/ESP-O-One-Making-You...

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.

The Code..

BMP code snap1.png
BMP code snap2.png
BMP code snap 3.png

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: https://github.com/adafruit/Adafruit_SSD1306
Link to Adafruit BMP library: https://github.com/adafruit/Adafruit-BMP085-Libra...

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

Downloads

Conclusion

IMG20201227123934.jpg
IMG20201227123926.jpg

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 in the comment section below 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!