ESP32S2 5x OLED显示器(I2C)

2024-05-29 03:57:00 发布

您现在位置:Python中文网/ 问答频道 /正文

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

当我分配“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

我怎样才能解决这个问题? 谢谢


Tags: theinimportboardadafruiti2cwidthfill

热门问题