Due to server issues & outages with Endicia - There is no USPS / Postal service orders at this time - Read more.

having trouble with the mcp230xx library and python.
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

having trouble with the mcp230xx library and python.

by IslandMedic on Mon Feb 18, 2013 6:49 pm

I am having some troubles reading an input. A little back ground. I have the early version of Pi. I have two gpio extender chips wired up. I have the i2c, and mcp230xx file in the same directory as the script you see below. I am able to turn off and on LED lights on pins 5,6,7 on chip 1 at address 20 just fine. When I put a selector switch to pull pins 8,9,10 on chip 2 @ address 21 the if statements don't catch and only the else statement gets run. When I print out the values of the 3 input pins I get 256,512 and 1024 respectively. When I change the inputs by applying 3.3v to the pins the print out doesn't change.

Some other issues I ran into was that when I did mcp0.config(7, OUTPUT) the code said that OUTPUT was not defined. So I used the 0 instead. The other thing that happens is when I try to use the mcp1.config(8, INPUT) I get input not defined. When I try mcp1.config(8, 1) I get the error pin 8 not set to input. So I used the pullup function and that seemed to not generate any errors but it also doesn't seem to work properly.

thanks for any help or advice. this is not production code. I am just trying to get my feet wet with how to use the code.


Code: Select all | TOGGLE FULL SIZE
from Adafruit_MCP230xx import Adafruit_MCP230XX

mcp0 = Adafruit_MCP230XX(busnum = 0, address = 0x20, num_gpios = 16)
mcp1 = Adafruit_MCP230XX(busnum = 0, address = 0x21, num_gpios = 16)

mcp0.config(7, 0)
mcp0.config(6, 0)
mcp0.config(5, 0)


print mcp1.input(8)
print mcp1.input(9)
print mcp1.input(10)

while (True):
    if mcp1.input(8) == 1:
        mcp0.output(7, 0)
        mcp0.output(6, 1) 
        mcp0.output(5, 0)
    elif mcp1.input(9) == 1:
        mcp0.output(7, 0)
        mcp0.output(6, 1) 
        mcp0.output(5, 0)
        mcp0.output(7, 0) 
        mcp0.output(6, 0) 
        mcp0.output(5, 0)

Posts: 9
Joined: Fri Feb 01, 2013 3:19 pm

Re: having trouble with the mcp230xx library and python.

by tldr on Mon Feb 18, 2013 7:10 pm

i think you want mcp0.OUTPUT and mcp1.INPUT.

are you pulling a0, (pin 15), high on the second mcp23017?
"If I had known it was harmless, I would have killed it myself." - Phillip K. Dick, A Scanner Darkly
User avatar
Posts: 466
Joined: Thu Aug 30, 2012 12:34 am

Re: having trouble with the mcp230xx library and python.

by adafruit_support_rick on Mon Feb 18, 2013 9:16 pm

The pullup function is the right way to configure a pin as input. However, you are using a value argument of 0, which will NOT enable the pullup. Does your circuit expect the pullup to be enabled?
User avatar
Posts: 12009
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY