When I connect the GPIO expander MCP23008 to the raspberry pi 1 model B+ via I2C, the address of the MCP23008 on the raspberry pi keeps switching between 0x20 and 0x21, and sometimes it's not even detected (see the captions below). What's wrong? How can I stop this uncontrollable change of address on the I2C? The OS is the latest raspberry pi OS desktop version.

enter image description here

enter image description here

enter image description here

Here's the circuit:

enter image description here enter image description here

  • 2
    You have not wired the device correctly. If you want a solution we need to see your wiring.
    – joan
    Feb 11 '21 at 23:10
  • 1
    @joan I added the circuit diagram to my question.
    – S.E.K.
    Feb 12 '21 at 0:32
  • 1
    @S.E.K, Ah, you need to tie the hardware address pins to either High or Low. You cannot leave them floating, which usually means High, but not for this chip. One of the manufacturer's design bug for this chip is that floating means indeterminate. This is the MCP23008/017 newbie's sorrow. Another bug is a restriction on the use of one or more of the GPIO pins.
    – tlfong01
    Feb 12 '21 at 2:22
  • 1
    @tlfong01 - looks like pins 3, 4 and 5 are grounded though - according to the diagram - but who knows what is actually connected where, that image of the actual connections is next to useless Feb 12 '21 at 3:15
  • 1
    since the address is flipping between 20 and 21 it's likely to be the A0 address line that isn't grounded properly - that's pin 5 Feb 12 '21 at 3:47

Thanks to everyone's comments I've come to a solution. All comes down to not letting the wires float (as suggested by @Dougie). Connecting the wires in a breadboard does not guarantee that they be actually connected, so I soldered them, and that stabilized the address of the MCP23008 on the I2C bus.


Do you have pullup resistors on the I2C lines? I'd put a 10K resistor between the SCL/SDA lines and VCC

  • 1
    The Pi has hardwired 1k8 pull-ups to 3V3 on SDA and SCL. No more should be needed.
    – joan
    Feb 12 '21 at 10:57
  • 1
    Ok, I didn't know that.
    – jkp
    Feb 12 '21 at 15:44

Slightly off topic and a little late, but a few things that may generally help when dealing with high impedance/fast changing inputs/protocols; and this device in particular, having recently been developing with the MCP23008.

  • As mentioned, don't let inputs float; tie them high (preferably) or low. often the pull-ups provided via software are insufficient at (often) about 100K - 10K is usually fine.
  • Try to keep connecting wires short
  • remember that I2C was developed as a short-range communication protocol
  • Power supplies should be clean, try adding a 10, 22, or 100uF electrolytic, together with a 0.1uf cap across the supply on your development board/breadboard. Ensure that the PSU does not violate the device’s min/max requirements and that you can supply enough current
  • Add a 0.1uF capacitor to chips across their supply pins (as close as possible) - I have found that the GPIO register, 0x09 on this chip occasionally reports nonsense without such decupling. (being lazy will bite you! :D ). During setup for this device, I set the first 9 registers as required, and read them back for confirmation. This way we know that the chip is communicating/I2C is up/the chip exists!
  • Understand (as you have discovered) that breadboards are nasty things when it comes to noise, contact resistance, stray capacitance etc.
  • understand the susceptibility of devices to damage from static charges. Take the manufacturers precautions!
  • Most importantly read and understand the datasheet (and make sure that you read the actual manufacturers datasheet, not a generic one!). Almost without exception, EVERYTHING you need to know will be in there! Manufacturers want you to use their chips and so they give you every chance to make them work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.