ESP8266-01 With Multiple I2C Devices?! || Exploring ESP8266:Part 2
Introduction: 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: 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 !
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: http://cdn.sparkfun.com/datasheets/Sensors/Pressur...
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. 832
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.
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: 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. 158