MCP23017 freeze


I have a HomeAutomation project which uses the MCP23017 chip but sometimes this locks up and only thing that helps is to reset the Arduino.

I have designed a IO expander board that contains 2 chips. All inputs are opto isolated (earlier I experienced disturbances on the inputs causing the outputs going nuts).

The problem I have is that for some reason one of the chips freezes and at the same time it changes the status of the outputs for the freezed chip to 0.

Can anyone see anything obvious in my schematic for the IO card?

The HomeAutomation project can be found here:

It was happening today twice for me...Just switchin' on the light in the room put the MC in an undefined state, all outputs were cut off...I think the internal registers were overwritten by that spike, and it requests a reset to start again...Pretty bad, becouse you can't rely on this chip for some serious apps...

I have had problems with these and interference in the data or clock line. Make them very short or in shielded cables and see if that don't help ya out. We use these in lots of things and when properly wired haven't had any problems even pushing them beyond there suggested current.

I have also been suspecting the clock/dataline but haven't seen any pattern yet in what causes it to freeze. The inputs should be well protected from spikes as they are optoisolated and also the inputs on the relay board are optoisolated so that should also protect the outputs of the MCP. One pattern I have managed to see is that only one of the 2 chips on a board freezes, so there might be some design issue on the PCB. I have also played around with the pullup resistor values without success. I could post a picture of the PCB if you feel it might give you some more ideas on where the problem might be.

Regards, Tom

I doubt those chips can be used in an industrial environment where heavy EMI are present. An expander board usually is not in the same place with the "motherboard",so the lenght of I2C can reach 1-2 feet...Imagine what could happen if those chips are used in a traffic light controller ...Things become more complicated than shielding a cable, nevertheless to say about power lines EMI ...I can't even move my hand closer to the MCP's, they are veritable antennas..:)...

@drksam , can you tell us where those things which are using MCP's are used? Or give us an example of a proper made pcb or schematic which you are using in the real life.Maybe we are doing something wrong, having not enough experience with those chips..Thank you

Sure l, I don't have any pics with me but will upload a schematic Monday if needed. We use them mainly to run air valves (24v valves) so the expand expanders are running logic level mosfets at 5v with just a 1k resistor in line and a 10k pull down. The data lines are soldered to the board 2 to 3 mm from the expander pin the trace is on the top layer and I use high quality shielded audio cable to go to the controller. I have found that not disturbing the clock/data is kinda hard to do on a pcb but if you don't really use the pcb for them it works great. Now I assume that If you really knew pc design (I am still kinda new at that) you can probibly find a path for them on the board but In our environment there is lots of welders and I haven't been able to do any data comm i2c spi or serial with out nice shielded cables

ok, I'll wait until Monday to see some pictures..By the way, which is the aproximate lenght of the data cables you are using between expanders and the main processor ?

With i2c and spi none are longer than 10" but I have read that they can be longer altho I’ve never tried. I have used a pair from a piece of cat5 in desk work on bread boards to maybe 10" as well but my desk isn’t around the shop so interference hasn’t been an issue.

I did find a couple pics from a bread board project that uses cat5 wires as data and clock I pointed them out in the pics this project works great and is using 4 expanders a 7" tft touch screen and an arduino mega to control 36 air valves and accept 36 digital inputs with manual override and status on the tft. I did have a problem at first because the tfts SD card slot is on the same bus and was having some kind of issue but after disconnecting it it worked fine.

Sorry pics too large to do more than one at a time.

hmmm..same wire jungle on my desk, too..:)..But my i2c is also a twisted pair, 4 inches long, not more...When I'm switching a lamp (led bulb !!!) which is 2 feet near the MCP,s, they freezed..Also if I'm getting my hand over the MCP's ,sometimes they freeze, sometimes not..:)..The board( olimexino-328) is fine, i2c sends the signals,the gsm module next to them works also fine...Only this MCP has a problem with his life :)...

Odd have you tried any projects that just use MCPs to see if it is some crazy interference on the GSM not sure as I've never used a GSM with arduino but it may be that there is some crazy problem with the traces on the pcb sometimes these things are made and tested with out trying other devices on the bus and may work great that way. If you find that the expanders work without the GSM on there you can switch to spi expanders that are not much harder to use.

@drksam You write about 1k resistor inline and 10k pullups, are these on inputs or on the SDA/SCL lines?

Tried to look on the routing of the SDA and SCL traces today but didn´t see anything special really, except that I have got a powerplane on both sides of the PCB and that the SCL line takes a unnecessary long way to the other chip.

Attached you can see the PCB with and without the powerplanes, I also added a picture of the install (however I experince same problems on the workbench with just one expander card, mega and a relay card)


@tom_rosenback...I think those resistors are for FET's commands, tyed on the outputs of MCP...On the other hand, it would be much better if you'll use some optotriacs ( personally I'm using only SHARP's S202S02 ) to command any lights or any other device up to 8 amps/triac whitout any spikes or glitches...And yes, the only cure I found ,like drksam, is using a twisted shielded pair of wires...There are some nice cables made especially for RS485, which allows also to power the boards. Just a last remark regarding your pcb's..Using two gnd planes rises another problem,regarding ground loops.If you had connected those planes in just one single point,is ok, otherwise some weird things can happen. Try to arrange your mcp's as close you can one each other and keep the SDA and SCL toghether, not spreaded. Maybe those things will help..:)

Thank you @Costin for those comments!

Based on the comments above I think I'll try to make a new PCB withe at least the following mods: - Remove power planes completely, one is GND and the other one is 5V - move SDA / SCL next to each other, and also give the routing of these a little more thought (noticed that one of them takes an unnecessary long way) - try to move the MCPs closer to each other

Regarding the outputs, the relay cards which I use has got opto isolation on the input side so that should be safe and good already.


If you still want to use those relay boards, then make a good filter for the supply lines.Relays are allways spikes generators,that's why I'm not using them anymore...Opto SSDs for ac, power MOSs for dc.. Use them confidently and give away those relays, your life will be happier..:)

The relay boards are operating on 12V and have a 5V output on the header. This I have earlier used to feed the IO expanders and from there the Arduino. I have now (yesterday) disabled the feedback from the relay cards and now instead use USB to feed the Arduino which then feeds the expanders. What I can see this must be a configuration that is safe from spikes, as the 5V inputs on the relay cards are optically isolated from the 12V relays. Or am I thinking wrong?

Made the changes as proposed in earlier posts to the PCB. What do you think of the design now? Worth manufacturing? :D

Hi, it seems to be better.Watch out for the ground loops and get rid of those resistors tied to reset.Put resets straight to +5. I had removed my resistor from reset pin to +5, and now it seems everythings is ok, so far...Also, make your ground traces as thick you can, to have low impedance and put right near the +5 and gnd input on the board 2-3 smd capacitors (1206)in parallel(0.1uF each). Regarding spikes, even the smallest relay produce them, regardless of working voltage,that's why I gave up on them. But it's worth trying this board..Good luck..:)


I really appreciate your comments and that you are taking time to look at my PCBs!! Thank you!!

I made some more adjustments to the layout itself but also widened traces as much as possible for GND and some of the other powerlines too. I did not yet remove the RESET resistors, I think I will try with them in, I could just put a jumper instead of the resistors if problems still occur.

One thing that bothers me with this design now is that the MCP on the right is much more further away from the SDA/SCL headers. Have tried to find som other place for them but as there is traces all over the place I find it difficult to move them somewhere else. In the middle would be optimal.

I´m sure to what you are referring regarding "ground loops". Is there something on the PCB that could cause this that I have totally missed or are you referring to the cables between Arduino and these cards?


Hi again...a ground loop is a closed contour made by a ground trace, for example when you are routing a ground signal and at the end the result is a closed loop, with no matter shape..It happens, but here, as I can see , is not the case...To shorten the i2c traces you have an option, but you must rework a little....Rotate the left MCP, and put the input header just between the MCP's, to have almost equal lenghts of the signal...