I want to use the ESP32-S2 with CircuitPython and 5x 0.96inch OLED I2C displays. It's working fine, but only with 2 displays.

When I assign "i2c3" or more, I'm getting an error. When I keep only "i2c1 and i2c2" or "i2c4 and i2c5" for example, it's working fine again.

But never more than 2 displays at the time.


import time
import os
import board
import busio
import adafruit_ssd1306
from numbers import *

WIDTH = 128

SDA1 = board.IO41
SCL1 = board.IO42

SDA2 = board.IO39
SCL2 = board.IO40

SDA3 = board.IO37
SCL3 = board.IO38

SDA4 = board.IO35
SCL4 = board.IO36

SDA5 = board.IO33
SCL5 = board.IO34

i2c1 = busio.I2C(SCL1, SDA1)
i2c2 = busio.I2C(SCL2, SDA2)
i2c3 = busio.I2C(SCL3, SDA3)
i2c4 = busio.I2C(SCL4, SDA4)
i2c5 = busio.I2C(SCL5, SDA5)

#    print("i2c1.scan(): " + str(i2c1.scan()))
#    i2c1.unlock()

display1 = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c1)
display2 = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c2)
display3 = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c3)
display4 = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c4)
display5 = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c5)

display1.fill(0) # Clear the display
display2.fill(0) # Clear the display
display3.fill(0) # Clear the display
display4.fill(0) # Clear the display
display5.fill(0) # Clear the display

for y, row in enumerate(ZERO):
    for x, c in enumerate(row):
        display5.pixel(x + 0, y + 0, c)
for y, row in enumerate(ONE):
    for x, c in enumerate(row):
        display5.pixel(x + 76, y + 0, c)


Traceback (most recent call last):
  File "code.py", line 31, in <module>
ValueError: All I2C peripherals are in use

How can I fix that?

  • There are only 2 I2C controllers in an ESP32-S2... but i2C is a bus, if there’s some way to change the address of the screens you could have several on the same bus... alternatively you may need to emulate a chip select function.
    – jcaron
    May 16, 2021 at 21:35
  • 1
    The SSD1306 can have two different i2C addresses, configured via SA0, so you can have at most 4 using two buses and two addresses on each. To use 5, you’ll either have to switch to a different interface (the chip supports SPI and parallel, though the details may vary depending on the board you use), or emulate chip select.
    – jcaron
    May 16, 2021 at 21:41
  • 1
    oh, thanks a lot, that make sense. Was using ESP32 before, and there is more I2Cs. Used it with tca9548a and it's working now :) May 17, 2021 at 0:39
  • Even the regular ESP32 only has 2 I2C controllers. But good thing you found a solution!
    – jcaron
    May 17, 2021 at 13:53


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.