我的代码是使用raspberry pi pico和oled(ssd1306)编写的,如下所示:
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import framebuf
width = 128
height = 64
i2c = I2C(1, scl=Pin(15), sda=Pin(14), freq=400000)
oled = SSD1306_I2C(width, height, i2c)
oled.fill(0)
oled.text("Hola perro", 5, 8)
oled.text("2022", 5, 18)
oled.show()
和错误:
Traceback (most recent call last):
File "<stdin>", line 12, in <module>
File "ssd1306.py", line 118, in __init__
File "ssd1306.py", line 37, in __init__
File "ssd1306.py", line 74, in init_display
File "ssd1306.py", line 123, in write_cmd
OSError: [Errno 110] ETIMEDOUT
如果我将
print(i2c.scan())
添加到我的程序中,它会向我显示以下内容:
>>> print(i2c.scan())
[]
我已经让你的代码工作了。问题出在引脚号上。代码中提供的数字应该是 GPIO 编号,而不是引脚的物理编号。
所以这有效:
i2c = I2C(0, scl=Pin(21), sda=Pin(20), freq=400000)
GP21 上有 SCL(物理引脚 27),GP20 上有 SDA(物理引脚 26)。请注意,我的代码的第一个参数是 0,因为我使用的是 I2C 零。