Reputation: 9
I have a callback method being triggered on a GPIO pin that when fired calls for a read of a input devices register, however when called I get -
Traceback (most recent call last): File "/home/coder/Try2.py", line 35, in NewPins x = self.mcp.readGPIO() AttributeError: 'int' object has no attribute 'mcp'
If I enter-
a.mcp.readGPIO()
<- from python shell I get
`BitArray('0xffff')` <-expected result
>>>
where the RotaryEncoder class is instantiated as 'a'
`class RotaryEncoder:`
`def __init__(self,IntPin, Start, Id):`
.... initialise some variables then open the device as 'mcp' -
`self.mcp = MCP23S17(bus=0x00, pin_cs=0x00, device_id=Id)`
`self.mcp.open()`
`def NewPins(self):`
` global OldPins`
` x = self.mcp.readGPIO()`
..... irrelevant code
callback line is
gpio.add_event_detect(IntPin, gpio.FALLING, callback=NewPins)
expected read value is a BitArray actual result is AttributeError: 'int' object has no attribute 'mcp'
Upvotes: 0
Views: 300
Reputation: 9
Ok my dumb.... - the RPiGPIO library I'm using returns the GPIO channel number in the callback, hence the callback function requires two arguments and not one. I had thought I'd messed up my namespaces and so was trying to code around this when I encountered the error above - I'm a novice python programmer and didn't know where to look! That'll teach me to not to read the documentation thoroughly...
Upvotes: 0