MCP23008 (i2c) Input Question

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dirtyrob
 
Posts: 38
Joined: Mon Jun 25, 2012 8:46 pm

MCP23008 (i2c) Input Question

Post by dirtyrob »

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-MC ... les/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-MC ... les/button

Micro Clutter Example: http://microclutter.blogspot.com/2011/1 ... utton.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
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MCP23008 (i2c) Input Question

Post by adafruit_support_rick »

Are you certain that you have the button connected to pin 10 of the MCP23008? Please post a picture of your wiring.

User avatar
dirtyrob
 
Posts: 38
Joined: Mon Jun 25, 2012 8:46 pm

Re: MCP23008 (i2c) Input Question

Post by dirtyrob »

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: 38
Joined: Mon Jun 25, 2012 8:46 pm

Re: MCP23008 (i2c) Input Question

Post by dirtyrob »

The forum didn't link my picasa images!

Here are the direct links:

https://picasaweb.google.com/lh/photo/I ... directlink

https://picasaweb.google.com/lh/photo/h ... directlink

-Rob

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MCP23008 (i2c) Input Question

Post by adafruit_support_rick »

Looks like you've got the switch wired to +5V. It should go to ground.

User avatar
dirtyrob
 
Posts: 38
Joined: Mon Jun 25, 2012 8:46 pm

Re: MCP23008 (i2c) Input Question

Post by dirtyrob »

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/u ... 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
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MCP23008 (i2c) Input Question

Post by adafruit_support_rick »

What about skipping the switch, and simply shorting pin 10 direct to GND?

User avatar
dirtyrob
 
Posts: 38
Joined: Mon Jun 25, 2012 8:46 pm

Re: MCP23008 (i2c) Input Question

Post by dirtyrob »

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
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MCP23008 (i2c) Input Question

Post by adafruit_support_rick »

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
dirtyrob
 
Posts: 38
Joined: Mon Jun 25, 2012 8:46 pm

Re: MCP23008 (i2c) Input Question

Post by dirtyrob »

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

jkelley
 
Posts: 11
Joined: Tue Jun 12, 2012 11:28 am

Re: MCP23008 (i2c) Input Question

Post by jkelley »

I am having the exact same issue with inputs on the MCP23008, 2 different Arduino (ethernet and uno) with two different MCP23008's.

User avatar
adafruit_support_bill
 
Posts: 88140
Joined: Sat Feb 07, 2009 10:11 am

Re: MCP23008 (i2c) Input Question

Post by adafruit_support_bill »

@jkelly - Best to start a new thread for this.
Describe what you are trying to do and post a photo showing all your connections.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”