MCP23017 I2C 16 I/O Port Expander
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 3
- Joined: Mon Dec 03, 2012 11:14 pm
MCP23017 I2C 16 I/O Port Expander
I have recently ordered a MCP23017 to mess around with for a project on my Raspberry Pi and I am having issues with the address randomly jumping around whenever I am trying to run "sudo i2cdetect -y 1". I have even gotten it a few times where it says there is a device on 0x20 and 0x27 at the same time just about. I have nothing else hooked up to the I2C Bus and I am using a Pi Cobbler to connect my Raspberry Pi to the Breadboard, I then have 4 wires coming from the Pi Cobbler to the MCP23017 Chip for 3v3, Ground, SCL, & SDA. I have gone over the connections 20+ times now and I am 100% positive there is nothing wrong with the wiring but I am having the issues where the Address is jumping around randomly.
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: MCP23017 I2C 16 I/O Port Expander
Post a photo showing your soldering. And make sure all your breadboard connections are firm. The spring contacts do tend to loosen up over time. If it does not grip the wire tightly, try an adjacent hole in the same row.
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: MCP23017 I2C 16 I/O Port Expander
Looks like your address pins (15,16 & 17) are floating. You should tie them to ground. From the datasheet: http://www.adafruit.com/datasheets/mcp23017.pdf
The address pins should be externally biased
even if disabled
-
- Posts: 3
- Joined: Mon Dec 03, 2012 11:14 pm
Re: MCP23017 I2C 16 I/O Port Expander
Going over that datasheet I noticed the reset pin is externally biased as wrll so I would have to ground thst as well, right? In the tutorial for using this with the Raspberry Pi it should say that the address pins need to be grounded for normal operation like it says for the reset pin so it is clear.
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: MCP23017 I2C 16 I/O Port Expander
Reset is active low, so it should be pulled high. And yes, that would be good to mention in the tutorial.
We welcome comments & correction on the tutorials. If you post them in the "Feedback? Corrections" link on the left side of the Adafruit Learning System guide, it will be sure to get back to the author.
We welcome comments & correction on the tutorials. If you post them in the "Feedback? Corrections" link on the left side of the Adafruit Learning System guide, it will be sure to get back to the author.
- nigelf
- Posts: 1
- Joined: Sat Nov 03, 2012 1:26 am
Re: MCP23017 I2C 16 I/O Port Expander
I had the dreaded random detection of address and it would clash if all pins for address were selected
so I tried not connecting pin 17 to ground but to supply ie hold it high rather than leaving it floating ...
this seemed to do the trick
so I tried not connecting pin 17 to ground but to supply ie hold it high rather than leaving it floating ...
this seemed to do the trick
- goingoffroading
- Posts: 7
- Joined: Thu Jun 13, 2013 11:37 am
Re: MCP23017 I2C 16 I/O Port Expander
Hey all... I just got my MCP23017 and was pouring through the Adafruit tutorial and spec documents...
Following this diagram in teh tutorial
http://learn.adafruit.com/mcp230xx-gpio ... -it-all-up
And then looking at the pin diagram in the data sheet
http://www.adafruit.com/datasheets/mcp23017.pdf
http://d.pr/i/WYAU
Is it me or does the chip in the tutorial appear to be upside down? (when you look at Vss, Vdd, with the printed name on the chip facing down, the vss and vdd should be on top but in the tutorial, it's on teh bottom.
I tried wiring the chip like the tutorial but didn't have success... I'm going to completely redo it but wanted to see if anybody had input/insight.
Following this diagram in teh tutorial
http://learn.adafruit.com/mcp230xx-gpio ... -it-all-up
And then looking at the pin diagram in the data sheet
http://www.adafruit.com/datasheets/mcp23017.pdf
http://d.pr/i/WYAU
Is it me or does the chip in the tutorial appear to be upside down? (when you look at Vss, Vdd, with the printed name on the chip facing down, the vss and vdd should be on top but in the tutorial, it's on teh bottom.
I tried wiring the chip like the tutorial but didn't have success... I'm going to completely redo it but wanted to see if anybody had input/insight.
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: MCP23017 I2C 16 I/O Port Expander
Align the chip based on the notch. It is to the left in the tutorial diagram.
- goingoffroading
- Posts: 7
- Joined: Thu Jun 13, 2013 11:37 am
Re: MCP23017 I2C 16 I/O Port Expander
Gotcha, thanks Bill!
- goingoffroading
- Posts: 7
- Joined: Thu Jun 13, 2013 11:37 am
Re: MCP23017 I2C 16 I/O Port Expander
Hey Bill.... I was hoping for your expert advice...
I've followed the wiring of the MCP23017 from:
http://learn.adafruit.com/mcp230xx-gpio ... -it-all-up
With the exception of adding more LEDs to GPA2-7 (so there are LEDs hooked up to GPA0-GPA7). (pic attached)
I also installed WebIDE which is totally badass pic: http://d.pr/i/tsoK
So I opened up Adafruit_I2C.py in WebIDE, hit run and I get this error:
File "Adafruit_I2C.py", line 1
mcp = Adafruit_MCP23017(busnum = 1, address = 0x20, num_gpios = 16)
^
IndentationError: unexpected indent
But all of my indents are four spaces... No 3, 5 or tabs... Its the default 'Adafruit_I2C.py' with line one deleted (had notes about changing a code if it was a 256 Raspberry).
Here's the code with the comments removed:
mcp = Adafruit_MCP23017(busnum = 1, address = 0x20, num_gpios = 16)
# Set pins 0, 1 and 2 to output (you can set pins 0..15 this way)
mcp.config(0, OUTPUT)
mcp.config(1, OUTPUT)
mcp.config(2, OUTPUT)
mcp.pullup(3, 1)
print "%d: %x" % (3, mcp.input(3) >> 3)
while (True):
mcp.output(0, 1) # Pin 0 High
mcp.output(0, 0) # Pin 1 Low
What am I doing wrong?
I've followed the wiring of the MCP23017 from:
http://learn.adafruit.com/mcp230xx-gpio ... -it-all-up
With the exception of adding more LEDs to GPA2-7 (so there are LEDs hooked up to GPA0-GPA7). (pic attached)
I also installed WebIDE which is totally badass pic: http://d.pr/i/tsoK
So I opened up Adafruit_I2C.py in WebIDE, hit run and I get this error:
File "Adafruit_I2C.py", line 1
mcp = Adafruit_MCP23017(busnum = 1, address = 0x20, num_gpios = 16)
^
IndentationError: unexpected indent
But all of my indents are four spaces... No 3, 5 or tabs... Its the default 'Adafruit_I2C.py' with line one deleted (had notes about changing a code if it was a 256 Raspberry).
Here's the code with the comments removed:
mcp = Adafruit_MCP23017(busnum = 1, address = 0x20, num_gpios = 16)
# Set pins 0, 1 and 2 to output (you can set pins 0..15 this way)
mcp.config(0, OUTPUT)
mcp.config(1, OUTPUT)
mcp.config(2, OUTPUT)
mcp.pullup(3, 1)
print "%d: %x" % (3, mcp.input(3) >> 3)
while (True):
mcp.output(0, 1) # Pin 0 High
mcp.output(0, 0) # Pin 1 Low
What am I doing wrong?
- Attachments
-
- 2013-06-25 18.56.14.jpg (709.55 KiB) Viewed 1581 times
- goingoffroading
- Posts: 7
- Joined: Thu Jun 13, 2013 11:37 am
Re: MCP23017 I2C 16 I/O Port Expander
Sorry, I don't see a way to edit my previous post but I followed a tutorial here:
http://learn.adafruit.com/adafruits-ras ... guring-i2c
Ran sudo i2cdetect -y 1
Worked! http://d.pr/i/84Cr
I have LEDs hooked up to ports 21-28 (http://d.pr/i/Jq5m)
Changed the script around a little to
http://learn.adafruit.com/adafruits-ras ... guring-i2c
Ran sudo i2cdetect -y 1
Worked! http://d.pr/i/84Cr
I have LEDs hooked up to ports 21-28 (http://d.pr/i/Jq5m)
Changed the script around a little to
Code: Select all
mcp = Adafruit_MCP23017(busnum = 1, address = 0x20, num_gpios = 16)
mcp.config(28, OUTPUT)
mcp.config(27, OUTPUT)
mcp.config(26, OUTPUT)
mcp.config(25, OUTPUT)
mcp.config(24, OUTPUT)
mcp.config(23, OUTPUT)
mcp.config(22, OUTPUT)
mcp.config(21, OUTPUT)
mcp.pullup(3, 1)
print "%d: %x" % (3, mcp.input(3) >> 3)
while (True):
mcp.output(0, 1) # Pin 0 High
mcp.output(0, 0) # Pin 1 Low
- goingoffroading
- Posts: 7
- Joined: Thu Jun 13, 2013 11:37 am
Re: MCP23017 I2C 16 I/O Port Expander
Well... I must have done something right... I didn't change any of the wiring but borrowed somebody else's code:
http://www.raspberrypi.org/phpBB3/viewt ... 8&p=327020
I got the psuil from sudo apt-get install python-psutil
Worked out amazing
http://www.raspberrypi.org/phpBB3/viewt ... 8&p=327020
Code: Select all
#!/usr/bin/python -tt
import psutil as ps, smbus #make sure you have those modules!
bus = smbus.SMBus(1)
def write(*bytes):
bus.write_byte_data(*bytes)
write(0x20, 0x00, 0x00)
write(0x20, 0x01, 0x00)
def led_bar(usage):
nr_leds = int(round(usage/6.25))
bank_a = 1
bank_b = 0
if nr_leds <= 8 and nr_leds > 0:
bank_a = (1<<nr_leds)-1
bank_b = 0
elif nr_leds > 8:
bank_a = 255
bank_b = (1<<(nr_leds-8))-1
write(0x20, 0x12, bank_a)
write(0x20, 0x13, bank_b)
def main():
while True:
usage = ps.cpu_percent(interval=0.1, percpu=False)
led_bar(usage)
if __name__ == '__main__':
main()
Worked out amazing
- Attachments
-
- 2013-06-26 00.53.55.jpg (898.15 KiB) Viewed 1561 times
Please be positive and constructive with your questions and comments.