Sub topic 5
Finding Your Display’s I2C Address
Assume you can upload an Arduino sketch, open the Serial Monitor, and install libraries through the Arduino IDE. You should also know how to connect power, ground, and signal wires on a breadboard.
An I2C display communicates over a shared two-wire bus. The two signal lines are:
- SDA, the data line
- SCL, the clock line
Each device on the bus has a 7-bit address. The Arduino sends that address before each message so the correct device can respond. An I2C LCD backpack often uses 0x27 or 0x3F. An SSD1306 OLED often uses 0x3C or 0x3D, but your particular module may use another address.
Wire the display to the Arduino
On an Arduino Uno or Nano, use these connections:
| Display pin | Arduino Uno or Nano |
|---|---|
| VCC | 5V or the voltage specified by the display |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
Some boards label the I2C pins separately. On an Arduino Uno R3, the pins marked SDA and SCL are electrically connected to A4 and A5.
Check the display’s voltage requirements before connecting VCC. Many small OLED breakout boards accept 5 V because they include a regulator and level shifting, but not all do.
Upload an I2C scanner
The scanner tries each possible 7-bit address. When a device acknowledges an address, the scanner prints it to the Serial Monitor.
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("I2C scanner");
for (byte address = 1; address < 127; address++) {
Wire.beginTransmission(address);
byte result = Wire.endTransmission();
if (result == 0) {
Serial.print("Device found at 0x");
if (address < 16) {
Serial.print("0");
}
Serial.println(address, HEX);
}
}
Serial.println("Scan complete");
}
void loop() {
}Select the correct board and port, then upload the sketch. Open Tools > Serial Monitor and set the baud rate to 9600. You should see a result such as:
I2C scanner
Device found at 0x27
Scan completeThe scanner uses Wire.beginTransmission(address) to select a possible device. Wire.endTransmission() sends the request. A return value of 0 means that a device acknowledged the request.
Understand the result
A single display may report one address. If several I2C devices are connected, the scanner prints every responding address. This is useful when checking a sensor and display on the same bus.
The scanner does not identify the device type. An address only proves that something responded there. Use the wiring and module documentation to determine whether the response came from an LCD backpack, OLED, sensor, or another device.
Some modules let you change their address by moving solder bridges or jumpers. This is useful when two identical devices would otherwise use the same address. Both devices cannot normally share one address unless the hardware supports a different addressing method.
If the scanner finds nothing
Check these causes in order:
- Confirm that VCC and GND are connected correctly.
- Confirm that SDA and SCL are not reversed.
- Use the correct I2C pins for your Arduino board.
- Make sure the display is powered while the scanner runs.
- Inspect loose breadboard jumper wires.
- Check whether the module needs 3.3 V instead of 5 V.
- Try shorter wires and remove other I2C devices temporarily.
- Reset the Arduino after correcting the wiring.
A display can remain blank even when the scanner detects it. For example, an LCD backpack may respond at 0x27 while its contrast potentiometer is set incorrectly. Address detection confirms communication, not readable output.
Exercise
The scanner reports 0x3D, but your OLED example uses 0x3C. What should you change?
Show answer
Change the OLED constructor or initialization call to use 0x3D, then upload the sketch again. The scanner result is the address to use for that module.