Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Commit e704414

Browse files
author
K. Townsend
committed
Fixed OUTPUT and SMBus location problems
1 parent a0cac2a commit e704414

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Adafruit_MCP230xx/Adafruit_MCP230xx.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,13 @@ class Adafruit_MCP230XX(object):
4141
INPUT = 1
4242

4343

44-
def __init__(self, busnum, address, num_gpios):
44+
def __init__(self, address, num_gpios):
4545
assert num_gpios >= 0 and num_gpios <= 16, "Number of GPIOs must be between 0 and 16"
46-
self.i2c = Adafruit_I2C(address, smbus.SMBus(busnum))
46+
self.i2c = Adafruit_I2C(address)
4747
self.address = address
4848
self.num_gpios = num_gpios
4949

5050
# set defaults
51-
5251
if num_gpios <= 8:
5352
self.i2c.write8(MCP23008_IODIRA, 0xFF) # all inputs on port A
5453
self.direction = self.i2c.readU8(MCP23008_IODIRA)
@@ -152,15 +151,12 @@ def pullup(self, pin, value):
152151

153152

154153
if __name__ == '__main__':
155-
# Use busnum = 0 for older Raspberry Pi's (pre 512MB)
156-
mcp = Adafruit_MCP230XX(busnum = 0, address = 0x20, num_gpios = 16)
157-
# Use busnum = 1 for new Raspberry Pi's (512MB)
158-
# mcp = Adafruit_MCP230XX(busnum = 1, address = 0x20, num_gpios = 16)
154+
mcp = Adafruit_MCP230XX(address = 0x20, num_gpios = 16)
159155

160156
# Set pins 0, 1 and 2 to output (you can set pins 0..15 this way)
161-
mcp.config(0, OUTPUT)
162-
mcp.config(1, OUTPUT)
163-
mcp.config(2, OUTPUT)
157+
mcp.config(0, mcp.OUTPUT)
158+
mcp.config(1, mcp.OUTPUT)
159+
mcp.config(2, mcp.OUTPUT)
164160

165161
# Set pin 3 to input with the pullup resistor enabled
166162
mcp.pullup(3, 1)

0 commit comments

Comments
 (0)