python - 为什么在我的 Beaglebone Black 上运行此 i2c 示例代码时会出现 IOError?

标签 python beagleboneblack i2c

下面是 Adafruit SSD1306 Library 中的 image.py 示例,用于在 BeagleBone Black 上通过 i2c 驱动 OLED 显示器。它给了我一个 IOError,但我对它的含义感到困惑。 IOError 可能是代码本身的问题,还是 BeagleBone 上的 i2c 配置问题?

import time

import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306

import Image

# Beaglebone Black pin configuration:
RST = 'P9_12'
# Note the following are only used with SPI:
DC = 'P9_15'
SPI_PORT = 1
SPI_DEVICE = 0

# 128x32 display with hardware I2C:
#disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# Initialize library.
disp.begin()

# Clear display.
disp.clear()
disp.display()

# Load image based on OLED display height.  Note that image is converted to 1 bit color.
if disp.height == 64:
        image = Image.open('happycat_oled_64.ppm').convert('1')
else:
        image = Image.open('happycat_oled_32.ppm').convert('1')

# Alternatively load a different format image, resize it, and convert to 1 bit color.
#image = Image.open('happycat.png').resize((disp.width, disp.height), Image.ANTIALIAS).convert('1')

# Display image.
disp.image(image)
disp.display()

请看下面的痕迹:

/usr/local/lib/python2.7/dist-packages/setuptools-3.5.1-py2.7.egg/pkg_resources.py:1031: UserWarning: /home/ubuntu/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
Traceback (most recent call last):
  File "image.py", line 47, in <module>
    disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
  File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 239, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py", line 105, in __init__
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 64, in get_i2c_device
  File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 75, in __init__
IOError: [Errno 2] No such file or directory

最佳答案

尝试:

Image = Image.open('happycat_oled_64.ppm','r').convert('1')

Image = Image.open('happycat_oled_64.ppm','w').convert('1')

关于python - 为什么在我的 Beaglebone Black 上运行此 i2c 示例代码时会出现 IOError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27575768/

相关文章:

linux - Beaglebone 黑色视频捕获 : Error "select timeout"

c - K22F 上的 I2C 初始化作为主机

linux-kernel - Linux I2C通信问题

beagleboneblack - 无法在 BeagleBone Green Wireless 上配置 SPI0

debian - 永久删除Beaglebone Black服务

c - 使用 I2C 读取时间 (Ds1307)

python - 将数据框转换为字典

Python Mechanize 找不到链接

python - 如何在区分 None 和 False 时判断变量是 None、False 还是 True

python - 使用正则表达式在网页中查找电子邮件地址