ESP32-S2 CircuitPython 5x OLED 显示器 (I2C)

物联网 ESP32 Python
2021-06-20 14:43:54

我想将 ESP32-S2 与 CircuitPython 和 5x 0.96 英寸 OLED I2C 显示器一起使用。它工作正常,但只有 2 个显示器。

当我分配“i2c3”或更多时,出现错误。例如,当我只保留“i2c1 和 i2c2”或“i2c4 和 i2c5”时,它又可以正常工作了。

但当时不会超过 2 个显示器。

代码:

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


WIDTH = 128
HEIGHT = 64
CENTER_X = int(WIDTH/2)
CENTER_Y = int(HEIGHT/2)

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)


#if(i2c1.try_lock()):
#    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)
display5.show()

输出:

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

我该如何解决?

0个回答
没有发现任何回复~