2

I am using 8 MCP23008 GPIO expanders to connect 64 total switches to a Raspberry Pi Zero W. Here is my circuit diagram:

Circuit diagram

I also designed and purchased a custom PCB for the sensors/gpio expanders

Here are a couple pictures of the real-life wiring

I essentially have a wire for SDA, SCL, 5V, and GND, and connect each of the respective pins on each of the 8 MCP23008 GPIO expanders to these wires, and these wires to the Pi. I then connect the address pins to power/ground to correspond to their location.

I've now added a level shifter between the SDA/SCL pins on the Pi and the SDA/SCL lines from the GPIO expanders. Unfortunately this didn't resolve the problem.

However, only some of the devices are detected:

pi@raspberrypi:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 21 -- 23 -- 25 -- 27 -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 

This issue is not consistent! #2 disappears and reappears pretty frequently, #6 has worked once or twice but not often, and #7 disappeared once but works otherwise. This makes me fairly confident it's some kind of connection issue. That said, maybe it's correlated in that when one disappears another reappears at the exact same time sometimes?

What I've tried:

  1. Spent at least an hour with a multimeter measuring everything I can think of. I've tested the connection between every single IC pin and the main line it should be connected to, and the ones they shouldn't. I've turned the circuit on and measured the voltage between all the IC pins and ground (all seems correct. SCL and SDA read ~3V each). Admittedly I shorted the circuit in the process of measuring voltage a couple times here :( Doesn't seem to have affected anything, they still all work/stop working about as often as they ever did.
  2. Pulled #4 out of the board and completed rewired it on a breadboard with a pi - it worked fine.
  3. Set up i2cdetect in a loop and measured voltage of every pin while I watched it just in case me pushing on the pins was somehow reconnecting things.

I've done everything I can think of with the multimeter and probably tested every connection a dozen times now. I'm very new at soldering/electronics in general so it's not that surprising that some connection might be messed up, but I'm kind of at a loss on how to continue. How can I continue to debug this?

6
  • Doing some googling on an idea now that I might need a 5V <-> 3.3V level shifter between the components and the Pi... When I was first researching this it indicated I wouldn't need it, and in my tests it worked with 2 gpio expanders at 5V fine, but maybe that doesn't scale for some reason?
    – James
    Sep 7, 2022 at 4:47
  • 1
    (1) Tricks to detect I2C devices, (Ref 1) (2) I once successfully detect 8 mcp23017's, but not stable. (3) (3.1) Rpi4B I2C bus not working correctly - Asked 2 years ago, Viewed 12k times stackoverflow.com/questions/62757687/… (3.2) Detect 8 mcp23017's forums.raspberrypi.com/… (3.3) Search found 178 matches: mcp23017 tlfong01 forums.raspberrypi.com/…
    – tlfong01
    Sep 7, 2022 at 5:22
  • Just added a level shifter (adafruit.com/product/757), no change unfortunately :(
    – James
    Sep 7, 2022 at 6:31
  • I'm not seeing the source of the pullups on the SDA and SCL lines. What is providing the pullup needed by the I2C spec? I note that it is mostly the even numbered (ie LSB of address low) units that are not working. I imagine a scope trace will tell a lot.
    – user85471
    Sep 7, 2022 at 22:42
  • @user85471 My understanding is that the Pi has builtin pullups: pinout.xyz/pinout/i2c. My roommate has an oscilloscope, I'll see if I can borrow and it muddle my way through the results.
    – James
    Sep 8, 2022 at 4:21

4 Answers 4

1

Two more options to try for troubleshooting in addition to previous suggestions:

  1. Since the behavior is not very reproducible, try getting rid of open reset pins on MCP23008. I.e. pull up reset pin (from data sheet it seem to be a "not reset", if I'm not mistaken, otherwise pull it down).
  2. For in-depth debugging I can recommend using a logic analyzer. One can get a chip version which typically do a good job in combination with PulseView.
3
  • 1
    Thanks for the advice - unfortunately the floating reset pins were just a mistake I made in the circuit diagram, I already had them connected to power. Just updated the circuit diagram. I'll check out the logic analyzer!
    – James
    Sep 7, 2022 at 19:11
  • Puzzling... Did you try changing i2c addresses? Do you have Arduino or any thing else that can be used as i2c master to check if the issue with Pi?
    – Vadim
    Sep 8, 2022 at 7:26
  • Thanks for this. Nudging me towards the reset pins was essentially what allowed me to finally notice the issue. The logic analyzer was also a helpful suggestion.
    – James
    Sep 13, 2022 at 2:11
2

Power the MCP23017 from 3V3 or use level shifters on the Pi GPIO.

When powered from 5V they need more than 3V3 at their inputs for the inputs to be reliably seen as high.

4
  • Unfortunately no change when I added an i2c-safe level shifter between the Pi and the SDA/SCL lines (i.imgur.com/NAryftJ.jpg)
    – James
    Sep 7, 2022 at 6:39
  • @Milliways thanks for the advice, just edited the question. Could you help me understand why I need level converter/buffer for the address lines when the address pins are already being connected directly to the 5V power on the Pi, which is the same as the Vdd for the GPIO expanders?
    – James
    Sep 7, 2022 at 6:43
  • You did not use the level shifter correctly. We can't guess how you connected it.
    – joan
    Sep 7, 2022 at 7:28
  • Just updated the post with a circuit diagram of how I connected the level shifter
    – James
    Sep 7, 2022 at 19:10
2
  1. That rats nest of wiring is just asking for trouble, particularly with all the uninsulated junctions.
  2. WHY are you powering with 5V? I use MCP23017 (admittedly not so many) powered by 3.3V

Normally the Pi has no problem driving I²C on 5V devices BUT the MCP23017 data sheet says
for A0, A1 VIH 0.25 VDD + 0.8 i.e. 2.05V for 5V supply
for CS, GPIO, SCL/SCK, SDA, A2 VIH 0.8 VDD i.e. 4V for 5V supply.

If you REALLY need to run from 5V I would use a level converter on SDA/SCL

5
  • 1) Do you have a suggested alternative? I agree it's messy, but I'm new to this and not really sure how this is typically done other than ordering another (expensive) PCB. A bunch of terminal blocks connected with wires or something? 2) I'm powering with 5V because the hall effect switches that I have connected to the GPIO pins require 5V (elecrow.com/download/A3141-2-3-4-Datasheet.pdf) and shifting all 64 HE switch output levels seemed like it'd be lot more complicated than just powering the GPIO expander on 5v
    – James
    Sep 7, 2022 at 6:28
  • I'm not sure I understand the last part of your answer. Since I'm connecting the address pins to the 5V rail shouldn't that provide sufficient voltage? Is that too much above VIH?
    – James
    Sep 7, 2022 at 6:30
  • The Pi GPIO only output max 3.3V which is less than the minimum required. Level converter modules are available inexpensively and you could connect between the Pi and your circuit. One example adafruit.com/product/757 but they are readily available.
    – Milliways
    Sep 7, 2022 at 6:38
  • But I'm not connecting the address pins to the GPIO pins, I'm connecting them to the 5V power. For the GPIO, I see no change when I added a level shifter between the SDA/SCL pins on the pi and the SDA/SCL lines from the GPIO expanders :( i.imgur.com/NAryftJ.jpg
    – James
    Sep 7, 2022 at 6:40
  • That's why we were given breadboards I'm not saying they are good for everything, but are nice for simple circuits. I would try adding one port expander, and testing before adding the next.
    – NomadMaker
    Sep 7, 2022 at 22:07
1

Sadly, the answer turned out to be dead simple. In trying to wire the RESET pins to power, I misread the datasheet and instead wired the INT pins to power.

Wiring picture

I think I made this mistake once wiring the first one, then just referenced the first one when soldering the rest of them.

Definitely a lesson for me to double check not just that everything is connected, but that it's also connected to the right thing! Honestly, I might have even done that but because the datasheet was almost upside down from my reference point I'm sure I wasn't careful enough.

pi@raspberrypi:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 21 22 23 -- 25 26 27 -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --      

They're working entirely now after I've connected them correctly, except for one that I haven't put back into the circuit yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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