PROJECT VI : ESP32 Multiple I2C (OLED + BMP32)

Rayhan Naufal Luthfi
3 min readMar 21, 2022

Welcome to my sixth project of ESP32. This project is a form of implementation of the knowledge that i got from Embedded System course. In this next project, we’re going to learn to use a different I2C on ESP32. In this project we’re going to use OLED and BMP32.

#Required Hardware and Software

First things first we need to know what components are needed for this project. These components are just the examples I used for this project, you can use different types of components that you can find easily on the internet.

  1. ESP32 Development Kit
  2. Male to Male Wire Cable
  3. Micro USB Cable
  4. Breadboard
  5. BMP32 Sensor
  6. OLED Display

As for the Software we need to install the library we need for BMP32 Sensor and OLED Display. You can check my previous article about BMP32 Sensor and OLED Display or you just can simply click this link below,

BMP32 Sensor Article : https://rayhannaufall.medium.com/project-iv-esp32-external-sensor-484704a535b

OLED Display Article : https://rayhannaufall.medium.com/project-v-oled-display-and-pwm-signal-de46849ac6e

#Assemble The Circuit

We can use this schematic for the circuit,

Source : randomtutorials.com

Assemble the components on the breadboard and the circuit should be like this, make sure it is assembled correctly to avoid hardware damage, especially OLED Display damage

And to test this project you can use this code as an example, this code will show us what are the temperature and the pressure that the BMP32 Sensor detect

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_BMP280 bmp; // I2C
void setup() {
Serial.begin(115200);
// inisialisasi alamat bme280
bmp.begin(0x76);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed or couldn't find a valid bme280"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop() {
delay(5000);
//read temperature and humidity
float t = bmp.readTemperature();
float h = bmp.readPressure();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from bmp sensor!");
}
// clear display
display.clearDisplay();
// display temperature
display.setTextSize(1);
display.setCursor(0,0);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(30,10);
display.print(t);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(2);
display.print("C");
// display pressure
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Pressure: ");
display.setTextSize(2);
display.setCursor(30, 45);
display.print(h/1000);
display.print("kPa");
display.display();
}

After verify and upload the code, your OLED Display should display the temperature and the pressure like this

And so that’s my experience in working on the sixth project. Thank you for reading this article and I hope this article can be helpful for people who want to start trying to learn ESP32.

Rayhan Naufal Luthfi
Information System Technology ITB 2020
18220048

--

--