ich arbeite mich gerade damit ein einen MCP23017 (I2C 16 Kanal Expander) über den FT232H (USB zu I2C/SPI Chip) vom RPi aus anzusteuern. Ich nutze dabei die adafruit GPIO-Libs.
Was geht ist, das er die LEDs an den ersten 8 Kanälen ansteuert und beim beenden alle 8 LEDs ausschaltet.
Was nicht geht, das er die Kanäle 9-16 als Eingänge abfragt und mir den Staus wiedergibt, hier kommt es zur Fehlermeldung:
Code: Alles auswählen
Traceback (most recent call last):
File "FT232H_MCP23017_inputtest.py", line 32, in <module>
u = mcp1.input(2)
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/MCP230xx.py", line 95, in input
return self.input_pins([pin])[0]
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/MCP230xx.py", line 103, in input_pins
gpio = self._device.readList(self.GPIO, self.gpio_bytes)
File "/home/pi/test/FT232H.py", line 726, in readList
self._verify_acks(response[:-length])
File "/home/pi/test/FT232H.py", line 646, in _verify_acks
raise RuntimeError('Failed to find expected I2C ACK!')
RuntimeError: Failed to find expected I2C ACK!
Code: Alles auswählen
#!/usr/bin/python
# using I2C devices with FT232H USB to SPI/I2C breakout
import FT232H as FT232H
from Adafruit_GPIO import MCP230xx as MCP230xx
from time import sleep
# Temporarily disable FTDI serial drivers to use the FT232H device.
FT232H.use_FT232H()
# Create FT232H device instances.
ft232h1 = FT232H.FT232H(serial='FTYSYJZ6') # I2C device
# Create MCP23017 (I2C 16 Channel Expander) device with FT232H as I2C provider.
# Like the FT232H guide mentions, when using I2C you'll need to setup
# your circuit with external pull-up resistors (4k7) connected to the
# I2C clock (pin D0) and data lines (pin D1+2 together).
# This is necessary because the FT232H is a general purpose chip which
# doesn't include built-in pull-up resistors.
mcp1 = MCP230xx.MCP23017(i2c=ft232h1, address=0x21)
# Set pin 1-8 on mcp1 as output
for o in range(0,8):
mcp1.setup(o, 0)
# Set pin 9-16 on mcp1 as input
for i in range(9,16):
mcp1.setup(i, 1)
mcp1.pullup(i, 1)
# read pin 2 on mpc1
u = mcp1.input(2)
print u
Gruß
Thilo