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

Commit b11eda5

Browse files
committed
Resolve #30 #31 #32 by fixing MCP230xx_GPIO class parameter order and adding CharLCD with MCP230xx example.
1 parent f8085fe commit b11eda5

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Adafruit_CharLCD/Adafruit_MCP230xx.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Adafruit_MCP230xx/Adafruit_MCP230xx.py

Adafruit_CharLCD/LCD_MCP230XX_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/python
2+
# Example script to show usage of MCP230xx GPIO extender to drive character LCD.
3+
4+
from Adafruit_CharLCD import Adafruit_CharLCD
5+
from Adafruit_MCP230xx import MCP230XX_GPIO
6+
7+
bus = 1 # Note you need to change the bus number to 0 if running on a revision 1 Raspberry Pi.
8+
address = 0x20 # I2C address of the MCP230xx chip.
9+
gpio_count = 8 # Number of GPIOs exposed by the MCP230xx chip, should be 8 or 16 depending on chip.
10+
11+
# Create MCP230xx GPIO adapter.
12+
mcp = MCP230XX_GPIO(bus, address, gpio_count)
13+
14+
# Create LCD, passing in MCP GPIO adapter.
15+
lcd = Adafruit_CharLCD(pin_rs=1, pin_e=2, pins_db=[3,4,5,6], GPIO=mcp)
16+
17+
lcd.clear()
18+
lcd.message(" Adafruit 16x2\n Standard LCD")

Adafruit_MCP230xx/Adafruit_MCP230xx.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class Adafruit_MCP230XX(object):
4040
OUTPUT = 0
4141
INPUT = 1
4242

43-
def __init__(self, address, num_gpios):
43+
def __init__(self, address, num_gpios, busnum=-1):
4444
assert num_gpios >= 0 and num_gpios <= 16, "Number of GPIOs must be between 0 and 16"
45-
self.i2c = Adafruit_I2C(address=address)
45+
self.i2c = Adafruit_I2C(address=address, busnum=busnum)
4646
self.address = address
4747
self.num_gpios = num_gpios
4848

@@ -162,7 +162,7 @@ class MCP230XX_GPIO(object):
162162
BCM = 0
163163
BOARD = 0
164164
def __init__(self, busnum, address, num_gpios):
165-
self.chip = Adafruit_MCP230XX(busnum, address, num_gpios)
165+
self.chip = Adafruit_MCP230XX(address, num_gpios, busnum)
166166
def setmode(self, mode):
167167
# do nothing
168168
pass

0 commit comments

Comments
 (0)