MCP23008 (i2c) Input Question

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

MCP23008 (i2c) Input Question

Postby DirtyRob » Sat Jun 30, 2012 10:13 pm

Hi Everyone,

I got my Arduino yesterday and I've been running through all the tutorials I can get my hands on. Everything seems to go smoothly, except the two that I'm most interested in!

The first is a problem with the 2.8" TFT Touch Shield, but I've posted that in the Shield forum. (Maybe an inspired individual will head over there and tell me I did everything right and am not crazy.) (http://forums.adafruit.com/viewtopic.php?f=31&t=30219)

The other issue is with the MCP23008 I ordered to add some pins that the LCD takes away. I did the toggle example first, with no issues at all. Even added extra LEDs to see how it worked on larger scale.

Toggle Example: https://github.com/adafruit/Adafruit-MCP23008-library/tree/master/examples/toggle

Next I tried the button example, but the input was not being read. I've confirmed the wiring several times and it looks fine. I've tried using buttons and switches to change the state of the pin. Eventually I ventured out and found another tutorial that only used the Wire library, but this one didn't work for me either.

Button Example: https://github.com/adafruit/Adafruit-MCP23008-library/tree/master/examples/button

Micro Clutter Example: http://microclutter.blogspot.com/2011/12/mcp23008-i2c-expander-button.html

Could I have a bunk chip? Have you guys had much luck with these? Is there anything I could be missing?

I appreciate any help you guys can give!

-Rob
User avatar
DirtyRob
 
Posts: 13
Joined: Mon Jun 25, 2012 7:46 pm

Re: MCP23008 (i2c) Input Question

Postby adafruit_support_rick » Sun Jul 01, 2012 1:25 pm

Are you certain that you have the button connected to pin 10 of the MCP23008? Please post a picture of your wiring.
User avatar
adafruit_support_rick
 
Posts: 3158
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: MCP23008 (i2c) Input Question

Postby DirtyRob » Sun Jul 01, 2012 2:18 pm

Hi driverbock,

The switch is connected to pin 10. I test with a few different switches and buttons that I had laying around in case there was something wrong with my hardware, but they all had the same response (and work fine in other applications).

I ran other demo where the MCP controlled LEDS and the worked fine. I used pins 10, 11, and 12 at that time.

I hope these pictures are clear enough to follow.

Thanks for your help!

Image

Image

Connection Instructions (button example header):
// Basic pin reading and pullup test for the MCP23008 I/O expander
// public domain!

// Connect pin #1 of the expander to Analog 5 (i2c clock)
// Connect pin #2 of the expander to Analog 4 (i2c data)
// Connect pins #3, 4 and 5 of the expander to ground (address selection)
// Connect pin #6 and 18 of the expander to 5V (power and reset disable)
// Connect pin #9 of the expander to ground (common ground)

// Input #0 is on pin 10 so connect a button or switch from there to ground
User avatar
DirtyRob
 
Posts: 13
Joined: Mon Jun 25, 2012 7:46 pm


Re: MCP23008 (i2c) Input Question

Postby adafruit_support_rick » Sun Jul 01, 2012 3:22 pm

Looks like you've got the switch wired to +5V. It should go to ground.
User avatar
adafruit_support_rick
 
Posts: 3158
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: MCP23008 (i2c) Input Question

Postby DirtyRob » Sun Jul 01, 2012 3:59 pm

Whoops, my bad. I actually did that when moved it to take the picture. :oops:

I plugged the lead back into the ground, fired it up, but still no luck. Here's an updated picture:

https://picasaweb.google.com/lh/photo/uEUIoa0ndogbdtap1ra0Z9MTjNZETYmyPJy0liipFm0?feat=directlink

You can see the green power light on, but the onboard test LED for pin 13 is not illuminated despite the switch being in the closed position.

Good eye though - I was hoping it would be that simple!

-Rob
User avatar
DirtyRob
 
Posts: 13
Joined: Mon Jun 25, 2012 7:46 pm

Re: MCP23008 (i2c) Input Question

Postby adafruit_support_rick » Sun Jul 01, 2012 4:38 pm

What about skipping the switch, and simply shorting pin 10 direct to GND?
User avatar
adafruit_support_rick
 
Posts: 3158
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: MCP23008 (i2c) Input Question

Postby DirtyRob » Sun Jul 01, 2012 5:01 pm

Same result. :(

Just for kicks, I tried switching to pin2 on the MCP and updated the demo sketch. Now the LED on 13 lights up regardless. Here are pictures with a lead (white) plugged directly into the ground and one with no lead at all.

Image

Image

One thing I did differently was update the address parameter provided in the mcp.begin method to reflect the change of pin. When I use the default (0), the LED stays off. When I use 2, it stays on...

Code: Select all
Adafruit_MCP23008 mcp;
 
void setup() { 
  mcp.begin(2);      // use default address 0
  mcp.pinMode(2, INPUT);
  mcp.pullUp(2, HIGH);  // turn on a 100K pullup internally
  pinMode(13, OUTPUT);  // use the p13 LED as debugging
}

void loop() {
  // The LED will 'echo' the button
  digitalWrite(13, mcp.digitalRead(2));
}


-Rob
User avatar
DirtyRob
 
Posts: 13
Joined: Mon Jun 25, 2012 7:46 pm

Re: MCP23008 (i2c) Input Question

Postby adafruit_support_rick » Sun Jul 01, 2012 7:25 pm

The address to mcp.begin() is the 3-bit number defined by the state of the 3 address pins. It's not related to the I/O pin address. You've got the address pins all grounded, so you will always use mcp.begin(0) (or mcp.begin(), which defaults to addr 0).

So, what should be happening is that the LED should be OFF with pin12/gpio2 grounded, and ON when the wire is removed.
User avatar
adafruit_support_rick
 
Posts: 3158
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: MCP23008 (i2c) Input Question

Postby DirtyRob » Thu Jul 05, 2012 9:04 am

Re: MCP23008 (i2c) Input Question

Postby DirtyRob » 05 Jul 2012 14:02
Thanks for all the help, driverblock. I'm pretty sure I have everything wired up correctly, so I'm going to order some extra ICs to test with in case the one I have is bad.

At $1.95 a piece I really should have ordered some extras - I've gotten a bad IC or two in the past from other vendors and should know better than to just get one.

I'll post back here if I have any luck to resolve the thread. Thanks again for your help! :D

-Robby
User avatar
DirtyRob
 
Posts: 13
Joined: Mon Jun 25, 2012 7:46 pm

Re: MCP23008 (i2c) Input Question

Postby jkelley » Thu Jul 12, 2012 7:50 am

I am having the exact same issue with inputs on the MCP23008, 2 different Arduino (ethernet and uno) with two different MCP23008's.
jkelley
 
Posts: 11
Joined: Tue Jun 12, 2012 10:28 am

Re: MCP23008 (i2c) Input Question

Postby adafruit_support_bill » Thu Jul 12, 2012 7:58 am

@jkelly - Best to start a new thread for this.
Describe what you are trying to do and post a photo showing all your connections.
User avatar
adafruit_support_bill
 
Posts: 16644
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino

Who is online

Users browsing this forum: No registered users and 7 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]