MCP23017 stopped to work after HA update to 0.115

You WILL WIN, there is no doubt!

Your tests means that chip is OK. Then on RPI you can try to make completely fresh SD card with fresh installation and add I2C and see what will happen then.
Ideally if you have another RPI (or can borrow for test) to see how this will work on another RPi hardware.

Wemos D1 shoudl work with ESPHome: (see below printscreen from hardware selection)

Out of curiosity: what does this log line mean?

“Valid I2C ports: ((3, 3, 2), (1, 3, 2), (0, 1, 0))”

In particular which pin is it referring to if I2C only uses 2 pins. Are they combinations of pins or what?


No idea :frowning:
Maybe there are combination of logical addresses as physical pins seems to be fixed.
I would look for this “Valid I2C ports: ((3, 3, 2), (1, 3, 2), (0, 1, 0))” more in google ?


In overall RPI has two hardware I2C interfaces (buses):
I2C bus 1 (this one, which MCP23017 integration is using) - physical pins: 3 and 5 (GPIO2 and GPIO3)
I2C bus 0 - physical pins: 27 and 28 (GPIO0 and GPIO1).

To have enabled I2C bus 1 it is crucial to have following line in /boot/config.txt file:

To have enabled I2C bus 0 it is crucial to have following line in /boot/config.txt file:

So far I understand MCP23017 integration use only I2C bus 1.

Now my guess for “Valid I2C ports: ((3, 3, 2), (1, 3, 2), (0, 1, 0))”
This may be related to configuration of pins for SDA and SCL: (2, 3) for i2c bus 1
but if I good understand, there is nothing to be configured for MCP23017 integration.
It must work out of the box.

To troubleshoot I would do:
Check if config.txt has line (without # at the beginning):
2. in RPI shell type (this is for i2c bus 1):
i2cdetect -y 1
and check output /if no errors/ - you should get something similar /numbers means i2c chip founds some devices - in my example I have 4 MCP23017 and one OLED display):

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 – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- 3c – -- –
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

I hope this will bring you close to the solution.

1 Like

thanks for the suggestions you give me.
I have both lines enabled in the config.txt file.
I got another 64gb SD and am reloading Hassos_rpi4-4.16. Before restoring HA via snapshot I try the “clean” installation by enabling only I2C integration.

I wanted to ask Bartosz:

  1. in RPI shell type (this is for i2c bus 1):
    i2cdetect -y 1
    and check output /if no errors/ - you should get something similar /numbers means i2c chip founds some devices - in my example I have 4 MCP23017 and one OLED display):

sorry for the ignorance but how do you verify this?

Well I am using quite different instalation because I have HA in docker on Raspian.
So I have easy access to my shell :slight_smile:

Basically You need to access to shell command on your Raspberry.
I have no access to my system now but there is the addon on HA, which allows you to have shell access. It is called SSH & Web Terminal

There you need to type the: i2cdetect -y 1
It may be you need to install two dependences:
sudo apt-get install -y python-smbus
sudo apt-get install -y i2c-tools

at least second one provides i2cdetect

Hope this helps a bit.

Finished to reinstall but still nothing:
“ValueError: No Hardware I2C on (scl, sda) = (3, 2)”

At this point I don’t know what to do.
I express a few questions dictated by “despair”:

The instructions to enable I2C are clear and so I wrote them but I ask you if the words are capitalized like
— new folder called CONFIG

and those in lower case type
— new folder called modules
should they be written like this?

At the end of the instructions is this sentence:
–The I2C devices should now be present under /dev.–

but on the hassio SD I don’t have this / dev but a folder called “overlays” where inside there are a lot of .dtbo files including some for the MCP27013.

I reiterate that the chips all work.
I am really considering giving up.

This is all you have to do in /boot/config.txt file
You can do it removing your SD card from RPI and put to PC/MAC and edit file simple by adding this line at the end of file.

Another question - to which pins you connect?
From that link it must be connected to physical pin: 2 and 5: (GPIO2 and GPIO3)

I use the GPIO Header downloaded from the official RPI website:
Pin 03 -> GPIO02 (SDA1)
Pin 05 -> GPIO03 (SCL1)

I reloaded three times from scratch.
The GPIOs all work as both “switches” and “binary sensors”. I also connected a DHT22 with no problems.
sure there is something that escapes me.
Unfortunately I tried with SSH and WEB Terminal but it doesn’t read and I don’t know how to install the dependencies you suggested.
This is getting absurd !!!

By now I believe the I2C ports are compromised. Maybe they received a 5volt spike during testing, I don’t think there is any other explanation.

MCP23017 can by supplied with 3.3V than you are fine with RPI
Are you convinced your expanders are fine?

I have connected couple of them - no problems.

I saw couple post ago your statement:
“3 mcp is with address 20. and reset is correctly set.”
I hope you are connecting only one chip in one time? Otherwise it will not work - the same addresses.
/I am sorry I know it is obvoius/.

The chips I use work correctly with a pcb running a wemos d1 and esphome.
I only use one chip to test it and A0, A1, A2 are connected to ground. Reset pin a + vcc. I don’t use INTERRUPT.

I tried to power MCP23017 with both 3v3 and 5v.

I remember that I had challenge with this as in the manual to enable I2C using USB stick it was stated that this folder has to have name “/modules” - the slash “/” at the beginning of the name “modules”.
From Windows laptop I was not able to make it. Was trying different options as I do not have linux machine either. At the end it was possible to do it on Mac laptop (putting USB stick to Mac and renaming the folder to /modules .
Then applying this configuration via Supervisor and restarting Pi was working fine.

There might be some info on this topic as well: MCP23017 I/O Expander

Hi, thanks for your help.
So are you telling me I need to call the “/ modules” folder?
How did you manage to write the “/” character with Windows?

@fraygon - I am sorry but now I am confused.
I am 100% sure I have use method with USB stick and I did not remove SD card from RPi.
This method is mentioned in few places (like this) but now on the official Home Assistant page is not described. :frowning:
With current description (adding data directly on SD card) there seem to be no need to add slash “/” in front of the “modules” folder.

What comes to my mind now is that if you trying to adjust folders using Windows computer - it might be a challenge as I do not think Windows file system can read Lynux one (used by RPi)…
Here is some info: I2c not working on the Pi4

I saw the link you sent me.
Have all users using RPI4 for HA failed to activate the I2C function?
It seems strange to me: the forum would be jammed with requests.

I am perplexed. If RPI4 is truly not compatible, my entire home automation project needs to be reviewed. I created my pcbs to have states and commands from expanders.
In order not to abandon HA I would have to migrate to esphome.

A disaster!!!

I am not sure if this can help you but when I go to Supervisor, System and then under three vertical dots select Hardware, under the gpio i can see the following:

  - gpio26
  - gpio17
  - gpio22
  - gpiochip0
  - gpio10
  - gpiochip504

I guess gpiochip0 is my MCP23017. Or under gpiochip504 - not sure which. I have only one connected at this point.

alleluia!!! :smiley: :smiley: :smiley:
i managed to get my expander to work.
I’m not sure what happened because I reinstalled hassio a dozen times.
After reading the various forum posts I also deleted the file in
“/config/home-assistant_v2.db” and after reboot the entities I had written in configuration.yalm magically appeared.

I don’t really understand what happened but I’m happy with it. I took three snapshots for safety.
And now on with the tests.
Thanks to all who have helped and endured me: you are magnificent. :smiling_face_with_three_hearts:

Great News !

home-assistant_v2.db file is the main HA database. Strange if this was the reason…
Ideally it would be good if you have any suspicion what was the problem… just for others.

I wish you knew what happened. The attempts were frantic and continuous. Sorry I’m not useful.
Even now I have problems, yesterday I was driving both inputs and outputs. Today only inputs: switches don’t want to know.
Also I always have to restart when it gets confused.
At least it gives a sign of life!

OK. I have also observed once a while strange behaviour. Was planning with some support to adjust the integration to more effective. I believe I will have a time to work with this in next weeks. Will see. If you have any string evidence related to root cause or problems with this chip then please share it.