Before you start
- Board and software
- Classic ESP32-WROOM DevKit / ESP32 Dev Module, Arduino IDE 2 and Arduino-ESP32 3.3.2 review baseline, not a latest-release claim. Match GPIO labels, not header positions.
- Circuit and dependencies
- SDA21 and SCL22, common GND and documented 3.3 V-compatible breakouts. Keep bus pull-ups at 3.3 V. Built-in Wire only; an address ACK does not identify the device.
- Before this lesson
- OLED Display with ESP32
- Evidence limits
- Expected behavior describes the example, not a hardware test performed in this review. Contributor media, where present, is identified separately; no compilation, board upload or accuracy measurement is claimed.
Make ESP32 Talk to Smart Modules
The Story
In Mission 09, the OLED worked because the ESP32 knew how to send instructions over two wires. That was I2C at work.
Now you will slow down and learn the rule system behind that connection. Once I2C makes sense, displays, environmental sensors, clocks, expanders, and many other modules stop feeling mysterious.
Explain Like I'm 12
Imagine one teacher and several students sitting in the same classroom. The teacher calls a student's name before asking a question. Everyone hears the question, but only the student with that name answers.
I2C works like that. The ESP32 speaks on shared wires, says an address, and the device with that address responds.
Mission Goal
Understand how I2C communication works and use an I2C scanner to find an OLED and BME280 connected to the same ESP32 bus.
Estimated Time
45-50 min
Difficulty
Beginner
Prerequisites
Skills You'll Learn
- Explain what a communication protocol is
- Describe I2C in beginner-friendly language
- Identify SDA, SCL, device address, controller, and peripheral roles
- Wire an OLED and BME280 to the same ESP32 I2C bus
- Run an I2C scanner sketch and interpret detected addresses
Components Required
- ESP32 DevKit boardActs as the I2C controller
- SSD1306 0.96 inch I2C OLED displayCommon I2C display, usually address 0x3C
- BME280 sensor moduleI2C environmental sensor, usually address 0x76 or 0x77
- Breadboard and jumper wiresConnect shared power, ground, SDA, and SCL
- USB data cableUpload the scanner and read Serial Monitor
I2C Is a Shared Conversation Bus
A protocol is a rulebook for communication. It defines who talks, when they talk, how bits are timed, and how the receiver knows the message is meant for it.
I2C uses two signal wires. SDA carries data. SCL carries the clock. The ESP32 usually controls the conversation, and the connected modules respond when their address is called.
Older tutorials often say master and slave. You will still see those words in datasheets and library code. A clearer modern way to say the same idea is controller and peripheral. In this mission, the ESP32 is the controller. The OLED and BME280 are peripherals.
Engineering Explanation
The ESP32 needs protocols because raw wires are not enough. A GPIO can be HIGH or LOW, but a display or sensor needs structured information: start here, send this address, write this command, read these bytes, stop now.
I2C solves that with a bus. The bus is shared by all connected I2C devices. The controller pulls the clock line to create timing. The data line changes in sync with that clock. At the start of a transaction, the controller sends a device address. Only the peripheral with that address should respond.
This is why the OLED and BME280 can both use GPIO21 and GPIO22 in this mission. GPIO21 and GPIO22 are the common Arduino ESP32 example pins used across this site, but ESP32 I2C pins are configurable in code when Wire.begin(SDA, SCL) matches the wires.
They are not connected to private signal wires. They share the same bus, but they use different addresses. The OLED might answer at 0x3C or 0x3D, while the BME280 might answer at 0x76 or 0x77. If two devices have the same fixed address on one bus, the ESP32 cannot reliably choose between them without changing an address or adding extra hardware such as an I2C multiplexer.
I2C lines normally rest HIGH because of pull-up resistors. Devices communicate by pulling the lines LOW at the right times. Many breakout modules already include pull-up resistors, which is why beginner circuits often work without adding extra resistors. But if the wires are long, the modules are many, or the pull-ups are missing or too strong together, the bus can become unreliable.
I2C is excellent for short, low-pin-count communication inside a project. It is not the best choice for long cables, very high speed, or devices that all have the same fixed address.
For this classic ESP32 circuit, use documented 3.3 V-compatible I2C breakouts and pull SDA/SCL up to 3.3 V. A regulator on a module does not prove its bus is level shifted. Check where onboard pull-ups connect before powering a module at 5 V; use suitable bidirectional I2C level shifting if the bus levels differ. The ESP32 internal pulls are weak and should not replace appropriate external bus pull-ups. For a short 100 kHz breadboard bus, 4.7 kOhm on each line is a common starting point when none are fitted; verify rise time/loading for your circuit rather than adding another pair blindly. Parallel module pull-ups reduce the effective resistance.
The scanner prints 7-bit addresses, not the shifted 8-bit read/write bytes some datasheets show. A response at 0x76/0x77 can come from BME280 or BMP280; compare the chip-ID register and module documentation in the BME280 guide. A response at 0x3C/0x3D does not establish OLED controller or dimensions. Two devices sharing an address may appear as one response; isolate modules to diagnose collisions.
Real-World Analogy
Think of I2C like an apartment building intercom. Everyone is connected to the same intercom system, but the visitor presses one apartment number. Only that apartment should answer.
SDA is the spoken message. SCL is the rhythm that keeps the message understandable, like a metronome.
The address is the apartment number. Without the address, every device would hear noise and nobody would know who should respond.
Wiring Diagram
Follow these steps in order. Unplug USB before you change any wires.
-
1
Unplug the ESP32 USB cable before wiring.
-
2
Identify each module/interface from its documentation. Use short wires and verify SDA/SCL pull-ups go to 3.3 V; add suitable external pull-ups only if absent. For a BME280 breakout in I2C mode, follow its CS/SDO strap instructions and SDA/SDI, SCL/SCK labels in the component guide.
-
3
Connect OLED VCC to ESP32 3.3 V.
-
4
Connect OLED GND to ESP32 GND.
-
5
Connect OLED SDA to ESP32 GPIO21.
-
6
Connect OLED SCL to ESP32 GPIO22.
-
7
Connect BME280 VIN or VCC to ESP32 3.3 V.
-
8
Connect BME280 GND to ESP32 GND.
-
9
Connect BME280 SDA to the same GPIO21 SDA row used by the OLED.
-
10
Connect BME280 SCL to the same GPIO22 SCL row used by the OLED.
-
11
Plug USB back in, upload the scanner sketch, and open Serial Monitor at 115200 baud.
GPIO Table
| Signal | ESP32 Pin | Mode | Notes |
|---|---|---|---|
| I2C SDA | GPIO21 | I2C data | Data line shared by OLED SDA and BME280 SDA. GPIO21 is the common example pin here, not a universal fixed requirement. |
| I2C SCL | GPIO22 | I2C clock | Clock line shared by OLED SCL and BME280 SCL. GPIO22 is the common example pin here, not a universal fixed requirement. |
| OLED power | 3V3 and GND | Power | Powers the SSD1306 OLED module. |
| BME280 power | 3V3 and GND | Power | Powers the BME280 sensor module. |
| Serial debug | USB | Serial | Prints detected I2C addresses in Serial Monitor. |
Arduino Code
Copy this into Arduino IDE, then click Upload.
#include <Arduino.h>
#include <Wire.h>
constexpr int I2C_SDA = 21;
constexpr int I2C_SCL = 22;
void setup() {
Serial.begin(115200);
delay(1000);
if (!Wire.begin(I2C_SDA, I2C_SCL, 100000)) {
Serial.println("I2C initialization failed: check board and pin selection.");
while (true) delay(1000);
}
Wire.setTimeOut(50); // Milliseconds per transaction, not the scan interval.
Serial.println("I2C scanner: SDA GPIO21, SCL GPIO22, 100 kHz");
}
void loop() {
unsigned int found = 0;
unsigned int faults = 0;
for (uint8_t address = 0x08; address <= 0x77; ++address) {
Wire.beginTransmission(address);
const uint8_t status = Wire.endTransmission();
if (status == 0) {
Serial.printf("ACK at 7-bit address 0x%02X (identity not checked)\n", address);
++found;
} else if (status != 2) { // 2: address NACK; no response at this address.
Serial.printf("Bus error %u at 0x%02X\n", status, address);
++faults;
}
}
Serial.printf("Scan: %u responding address(es), %u bus error(s)\n", found, faults);
if (found == 0) Serial.println("Check power, common GND, pins and pull-ups.");
delay(5000);
}
Classic ESP32-WROOM DevKit / ESP32 Dev Module; Arduino-ESP32 3.3.2 review baseline, not a latest-release claim. Only built-in Wire is required. SDA is GPIO21, SCL is GPIO22, bus speed is 100 kHz. Other ESP32 families/boards may need different pins. Documentation reviewed; compilation and hardware testing were not performed.
This scanner tests non-reserved 7-bit addresses 0x08β0x77. An ACK proves only that something answered at an address: it does not identify an SSD1306, BME280 or BMP280, validate all wiring, or prove measurement/display operation. Use the device-specific guide next. Do not scan a bus containing parts whose datasheet prohibits this probe.
Line-by-line Explanation
- Wire.h gives the ESP32 Arduino core its I2C functions.
- I2C_SDA is set to GPIO21, the common ESP32 SDA example pin used in this mission.
- I2C_SCL is set to GPIO22, the common ESP32 SCL example pin used in this mission.
- Serial.begin(115200) starts Serial Monitor so you can see the scan results.
- Wire.begin(I2C_SDA, I2C_SCL, 100000) checks initialization on the declared pins at 100 kHz; setTimeOut(50) bounds each transaction in milliseconds.
- The loop probes non-reserved 7-bit addresses 0x08 through 0x77, skipping reserved address blocks.
- Wire.beginTransmission(address) prepares a message to one possible address.
- Wire.endTransmission() sends the address and returns an error code.
- If the error code is 0, a device answered at that address.
- The sketch reports ACKs without inferring identity. Use the component documentation and initialization checks after scanning.
Recorded I2C scan with two responding addresses
Explore the build photos and recorded results. Open any image to inspect the details.
About this recorded build
Owner-supplied build records, not an independent retest or a calibrated accuracy comparison. Use the wiring table and module labels; photos can hide breadboard contacts.
The supplied scanner exactly matches the lesson code: GPIO21/SDA, GPIO22/SCL, 100 kHz, 115200 baud and a five-second pause between scans.
The capture reports ACKs at 0x3C and 0x76, with 2 responding addresses and 0 bus errors. An ACK does not identify the chip or prove that its display or sensor measurements work.

The same contributed BME280/OLED wiring setup used for the scanner demonstration.
View full-size image
Contributor upload capture: written data verified.
View full-size image
Recorded response addresses: 0x3C and 0x76. Device identity was not checked by this scanner.
View full-size imageCode and files
Expected Behaviour
Illustrative output, not a recorded hardware result:
I2C scanner: SDA GPIO21, SCL GPIO22, 100 kHz ACK at 7-bit address 0x3C (identity not checked) ACK at 7-bit address 0x76 (identity not checked) Scan: 2 responding address(es), 0 bus error(s)
Your addresses may differ. 0x3C/0x3D are common OLED addresses; 0x76/0x77 can belong to BME280 or BMP280. Confirm controller, sensor and interface using their documentation and component-specific initialization. The count is responding addresses, not necessarily physical devices. An ACK does not prove that a display works or sensor data is valid.
Status 2 is an address NACK, normally expected at unused addresses. Other statuses are reported as bus errors; status 5 means a transaction timeout on the reviewed ESP32 Wire implementation. Check power and common ground, shorten wires, inspect pull-ups and isolate one module. A stuck-low line can produce repeated timeouts; disconnect power before rewiring.
Common Mistakes
Swapping SDA and SCL
The clock and data lines have different jobs.
Forgetting common ground
The ESP32 and modules need the same voltage reference.
Using a non-I2C OLED
Some displays use SPI and have more pins.
Expecting all BME280 modules to use the same address
Module boards can configure the address pin differently.
Two devices share the same fixed address
I2C addresses must be unique on one bus.
Using long jumper wires
I2C is sensitive to wiring length, capacitance, and weak pull-ups.
Thinking the scanner reads sensor data
The scanner only checks whether a device answers at an address.
Ignoring address output
Copying a tutorial address without checking the real module can cause blank screens or failed sensors.
Troubleshooting
Most ESP32 problems are wiring, power, library, or timing issues. Check these first.
Scanner prints no devices
Likely cause: Power, ground, SDA, SCL, or pin selection is wrong.
Fix: Check 3.3 V, GND, GPIO21, GPIO22, and make sure Wire.begin(21, 22) is used.
Only the expected OLED address appears
Likely cause: The other module may be unpowered, wired incorrectly, in SPI mode or at a different address.
Fix: Identify the responding module by testing one at a time. Check BME280 power, CS/SDO straps and SDA/SCL labels; do not infer sensor identity from the scan.
Only an address at 0x76/0x77 appears
Likely cause: The OLED may be unpowered, on another address or interface, or incorrectly wired.
Fix: Check OLED VCC, GND, SDA to GPIO21, and SCL to GPIO22.
Addresses appear sometimes but disappear later
Likely cause: Loose breadboard wires, long wires, or weak pull-ups can make the bus unstable.
Fix: Shorten wires, reseat jumpers, and test one module at a time.
Code uploads but Serial Monitor shows unreadable text
Likely cause: Serial Monitor baud rate does not match the sketch.
Fix: Set Serial Monitor to 115200 baud.
Engineer Tip
Before debugging a complex display or sensor program, run an I2C scanner. It separates wiring problems from code problems. If the scanner cannot see the device, a bigger library example will not fix the hardware connection.
Remember This Forever
I2C is not many private conversations.
It is one shared conversation where each device answers only when its address is called.
Mini Challenge
No wrong answers β experiment and have fun!
- Run the scanner with only the OLED connected and write down the address.
- Add the BME280 to the same SDA and SCL wires, then confirm the scanner finds two addresses.
- With USB unplugged, intentionally swap SDA and SCL on one module, then predict what the scanner will show before testing.
- Find whether your BME280 reports 0x76 or 0x77 and save that value for the next mission.
- Explain why two devices can share GPIO21 and GPIO22 but cannot share the same fixed address.
FAQs
What is a communication protocol?
A communication protocol is an agreed set of rules for how devices send and receive information. Without a protocol, the ESP32 and a sensor would not know how to understand each other.
What does I2C mean?
I2C means Inter-Integrated Circuit. It is a two-wire communication bus used by many displays, sensors, clocks, memory chips, and small modules.
Which pins does ESP32 use for I2C?
This site's ESP32 DevKit examples use GPIO21 as SDA and GPIO22 as SCL. ESP32 I2C pins can be changed in code, but the wiring and Wire.begin(SDA, SCL) call must match.
What is SDA?
SDA is the data line. It carries the bits that represent addresses, commands, and data.
What is SCL?
SCL is the clock line. It provides timing so devices know when each data bit should be read.
What is an I2C address?
An I2C address is a small number that identifies one device on the bus. The ESP32 sends the address first so only the selected device responds.
Why can multiple devices share SDA and SCL?
They can share the wires because each device listens for its own address. The ESP32 talks to one addressed device at a time.
What address does an SSD1306 OLED usually use?
Most SSD1306 0.96 inch OLED modules use 0x3C. Some use 0x3D.
What address does a BME280 usually use?
Many BME280 modules use 0x76 or 0x77 depending on the module wiring.
What is an I2C scanner?
It probes addresses and reports acknowledgements. An ACK does not identify the chip, confirm OLED dimensions, or prove valid sensor readings. Different chips can use the same address.
Do I need pull-up resistors for I2C?
Yes, I2C needs pull-up resistors on SDA and SCL. Many breakout modules already include them, but long wires or many modules can still cause problems.
Can I use 5 V I2C modules with ESP32?
Module supply and signal voltage are separate. ESP32 SDA/SCL must not be pulled up to 5 V. Verify module pull-up connections and use suitable bidirectional I2C level shifting when required; a regulator alone does not prove compatibility.
Why does the scanner show no devices?
The most common causes are missing power, missing ground, swapped SDA/SCL, wrong pins, or a module that is not I2C.
Can two I2C devices have the same address?
Not on the same bus unless you use extra hardware such as an I2C multiplexer or can change one device address.
Is I2C good for long cables?
I2C is best for short connections on the same board or inside the same small device. Long wires can make the signals unreliable.
Previous Mission
Next Mission
Continue Learning
Technical references
- Arduino-ESP32 3.3.2 Wire implementation β Explicit controller pins, transaction return codes and timeout behavior.

