Small monochrome displays often use the slower but much simpler I2C interface to connect to a microcontroller. Almost all monochrome OLED displays, for example, use I2C, and because of their simplicity, they are a great way to start with displays.
Overview
The I2C interface is a two-wire bus system where multiple peripherals share the same bus and are distinguished by fixed device addresses. This has two real-world consequences:
- Efficient: Since all peripherals share the same bus, you just need two GPIOs, regardless of how many peripherals (i.e. displays, sensors, etc) you want to connect.
- Limited: Since each I2C peripheral needs to be targeted by its specific address, and since most peripheral classes use hard coded addresses, you can only use one display, or you would have to find multiple I2C displays with different built-in addresses. In addition, the data transfer speed of I2C is limited. While you can display text and static information, I2C is less ideal for high data rates such as streaming video or sophisticated animations.
Pins On Display
I2C displays typically have four pins, two of which are for their power supply. The other two pins resemble the I2C interface:
Pin | Description |
---|---|
SDA | Serial Data (data packages with payload and overhead information, i.e. the target address) |
SCL | Serial Clock (synchronizes the data speed) |
VDD | positive voltage, make sure the voltage matches the display requirements |
GND | ground |
Pins On Microcontroller
The pins you use for I2C on the microcontroller development board depends on the microcontroller type you use, and sometimes on the board design:
- Mandatory Pins: Older microcontrollers like the one on Arduino Mega have designated I2C pins that you must use.
- Assignable Pins: Microcontrollers like ESP32 have default I2C GPIOs that you should use (because they are more performant), but you can also use any other suitable GPIO instead (which then emulates I2C in software).
- Routable Pins: Modern microcontrollers like ESP32-C3 and ESP32-S3 have routable I2C controllers, so you can assign any suitable GPIO with their hardware-optimized I2C controller(s).
Here is a table with some suggestions:
The development board you are using may use different GPIOs. Modern ESP32 family members such as ESP32-C3 or ESP32-S3 can route any GPIO to its hardware I2C controllers, and development board designers may have designated arbitrary GPIOs.
Microcontroller | SDA Pin | SCL Pin | Pin Reassignment Allowed? |
---|---|---|---|
Arduino Uno R3 | A4 | A5 | No |
Arduino Uno Mini LE | A4 | A5 | No |
Arduino Uno R4 | A4 | A5 | No |
Arduino Uno WiFi | 20 | 21 | No |
Arduino Leonardo | D2 | D3 | No |
Arduino Nano | A4 | A5 | No |
Arduino MKR | D11 | D12 | No |
Arduino Giga R1 | 20 | 21 | No |
Arduino Due | 20 | 21 | No |
Arduino Mega 2560 | 20 | 21 | No |
ESP8266 Wemos D1 Mini | 4/D2 | 5/D1 | Yes |
ESP8266-01 | 0/D5 | GPIO2/D3 | Yes |
ESP32 | 21 | 22 | Yes |
ESP32-S2 | 8 | 9 | Yes |
ESP32-S3 | 8 | 9 | Yes |
ESP32-C3 | 5 | 4 | Yes |
Teensy | varies | varies | Yes |
STM32 (Blue Pill) | PB9 | PB8 | Yes |
Digispark (ATTiny85) | PB0/pin 5 | PB2/pin 7 | No |
When you are using a microcontroller that supports I2C pin reassignments, make sure you use a freely available GPIO that can read and write and has a built-in pull-up resistor.
Power Supply
It is crucial to connect the VDD pin on your display with a power source of appropriate voltage. Typically, you must decide whether you connect VDD to the 5V or 3.3V pin on your microcontroller board:
- Multiple Voltages: some displays use internal voltage regulators so you can supply both 5V and 3.3V
- Configurable Voltages: some displays have solder bridges that you can leave open or bridge with some solder. This activates or bypasses internal voltage regulators. Depending on the state of the solder bridge, such displays require either 5V or 3.3V
- Fixed Voltage: some displays support just one fixed voltage, either 3.3V or 5V.
If in doubt, try with the 3.3V pin first. If the display does not work with this lower voltage, you may want to use 5V.
Logical Level Voltage
Most displays internally use 3.3V logic levels for SDA and SCL. When your microcontroller uses 5V (i.e. older Arduinos), you need to use a I2C-compatible (fast) level-shifter, or at least some protective restistors for SDA and SCL.
Modern microcontrollers like the ESP32 family run on 3.3V and do not require level shifter.
I2C Device Address
For the programming part, you will also need to know the unique I2C device address for your display. It is assigned in hardware by the manufacturer.
Here is a list of typically used I2C addresses for displays. Some display types can use more than one address, so you either need to trial-and-error, or use a I2C Scanner to identify the device address.
I2C Address | Display Type | Description |
---|---|---|
0x20 |
Character LCD | Common for 16x2 or 20x4 character LCDs. |
0x21 |
Character LCD | Another common address for 16x2 or 20x4 character LCDs. |
0x27 |
Character LCD | 16x2 or 20x4 character LCDs with an I2C backpack. |
0x38 |
Character LCD | Often used for larger HD44780-based displays (e.g., 40x4). |
0x39 |
Character LCD | Used for some LCDs with different configuration setups. |
0x3C |
OLED Display | Common for OLED displays using the SSD1306 driver. |
0x3D |
OLED Display | Alternate address for SSD1306 OLED displays. |
0x3E |
OLED Display | Used for some OLED displays with the SH1106 driver. |
0x1D |
Color Display | Address for some color displays with touch control. |
0x62 |
Character LCD | Common address for LCDs with the PCF8576 chip. |
0x6A |
TFT Display | Address used by some I2C-connected TFT displays. |
0x73 |
Character LCD | Used for LCD displays with the PCF8574T I2C expander. |
0x7A |
TFT Display | Common for some TFT displays with I2C interface. |
0x7C |
TFT Display | Often used for TFT displays with I2C interfaces. |
0x5C |
TFT Display | Used for TFT displays with certain controllers. |
Slow Website?
This website is very fast, and pages should appear instantly. If this site is slow for you, then your routing may be messed up, and this issue does not only affect done.land, but potentially a few other websites and downloads as well. Here are simple steps to speed up your Internet experience and fix issues with slow websites and downloads..
Comments
Please do leave comments below. I am using utteran.ce, an open-source and ad-free light-weight commenting system.
Here is how your comments are stored
Whenever you leave a comment, a new github issue is created on your behalf.
-
All comments become trackable issues in the Github Issues section, and I (and you) can follow up on them.
-
There is no third-party provider, no disrupting ads, and everything remains transparent inside github.
Github Users Yes, Spammers No
To keep spammers out and comments attributable, all you do is log in using your (free) github account and grant utteranc.es the permission to submit issues on your behalf.
If you don’t have a github account yet, go get yourself one - it’s free and simple.
If for any reason you do not feel comfortable with letting the commenting system submit issues for you, then visit Github Issues directly, i.e. by clicking the red button Submit Issue at the bottom of each page, and submit your issue manually. You control everything.
Discussions
For chit-chat and quick questions, feel free to visit and participate in Discussions. They work much like classic forums or bulletin boards. Just keep in mind: your valued input isn’t equally well trackable there.
(content created Jan 22, 2025)