I2C Communication
Understanding I2C Addresses
When we use I2C communication, more than one device can be connected to the same two wires.
So how does the microcontroller know which device to talk to?
Each device has its own I2C address.
What is an I2C Address?
An I2C address is just a number given to a device.
The microcontroller uses this number to choose which device it wants to communicate with.
Simple Example
Imagine you are calling someone on the phone.
- You dial a phone number.
- Only that person’s phone rings.
An I2C address works the same way.
- The microcontroller sends data to an address.
- Only the device with that address responds.
For Your OLED
Your OLED usually uses the address:
0x3C
This means the microcontroller sends data to 0x3C, and the OLED responds.
How many addresses exist?
I2C uses 7-bit addresses. That means there are 128 possible numbers (from 0x00 to 0x7F) that a device could use.
However, some addresses are reserved for special purposes, so not all 128 are available for normal devices.
Why the OLED has two addresses
Even though I2C supports many addresses, your OLED module only allows two possible addresses:
- 0x3C – This is the default address. Most beginner setups use this.
- 0x3D – This is an alternative address that can be selected by changing a small jumper (a tiny metal connection) on the back of the OLED module.
You only need the alternative address (0x3D) if you want to connect two OLEDs to the same I2C bus. Each device on the bus must have a unique address.
How this works in code
When initializing the OLED in your Arduino code, you write:
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- SSD1306_SWITCHCAPVCC – Tells the OLED to use its built-in voltage booster to power the display correctly.
- 0x3C – Tells the microcontroller which device to communicate with (the OLED at address 0x3C).
If your OLED jumper is changed to 0x3D, you must update the code to:
display.begin(SSD1306_SWITCHCAPVCC, 0x3D);
This ensures the microcontroller talks to the correct device.
Summary in simple words
- I2C address = device’s unique number on the I2C bus.
- Your OLED supports two addresses: 0x3C (default) or 0x3D (alternative).
- Default 0x3C is fine if you have only one OLED.
- Alternative 0x3D is only needed if there are two OLEDs on the same bus.
- The microcontroller uses this address to know exactly which device to talk to.
Understanding SCL and SDA (I2C Communication)
The OLED display uses a communication method called I2C. I2C allows devices to talk to each other using only two signal wires.
What is SCL?
SCL stands for Serial Clock Line.
- It controls the timing of communication.
- It sends clock pulses from the microcontroller.
- It tells the display when to read data.
Think of SCL like a heartbeat or rhythm that keeps everything in sync.
What is SDA?
SDA stands for Serial Data Line.
- It carries the actual data.
- This is where text, numbers, and commands are sent.
If SCL is the rhythm, SDA is the actual message being sent.
Why Are Both Needed?
- Without SCL → devices would not know when to send or receive data.
- Without SDA → no information would be transferred.
Both wires work together to make communication possible.
Where Do You Connect Them?
On the RP2040 board, there are specific pins labeled:
- SCL
- SDA
You must connect:
OLED SCL → RP2040 SCL pin
OLED SDA → RP2040 SDA pin
Do not swap them. SCL must connect to SCL, and SDA must connect to SDA.
Complete Connection Summary
OLED → RP2040
-----------------------------
GND → GND
VCC → 3.3V
SCL → SCL
SDA → SDA
Only four wires are needed because I2C communication shares the same two signal lines (SCL and SDA).