MCP23017 stopped to work after HA update to 0.115

Hello,

My name is Bartosz - this is my first post here so I would like to say warmly greet everybody :slight_smile:

My platform - this is docker version (RPI 4):
HA: 0.115 - fresh update
docker_version: 19.03.12

After update to 0.115 I have just lost my MCP23017 Expander for both: sensor and switch.
Example of config (the same setting was working perfect on previous version):

Binary sensors

binary_sensor:

  • platform: mcp23017
    i2c_address: 0x22
    pins:
    0: MCP_IN 8

#Switches
switch:

  • platform: mcp23017
    i2c_address: 0x20
    pins:
    0: MCP 8

For sensor I have got the following error:

Error while setting up mcp23017 platform for binary_sensor
Traceback (most recent call last):
File β€œ/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 193, in _async_setup_platform
await asyncio.shield(task)
File β€œ/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File β€œ/usr/src/homeassistant/homeassistant/components/mcp23017/binary_sensor.py”, line 48, in setup_platform
i2c = busio.I2C(board.SCL, board.SDA)
File β€œ/usr/local/lib/python3.8/site-packages/busio.py”, line 18, in init
self.init(scl, sda, frequency)
File β€œ/usr/local/lib/python3.8/site-packages/busio.py”, line 38, in init
from microcontroller.pin import i2cPorts
File β€œ/usr/local/lib/python3.8/site-packages/microcontroller/init.py”, line 29, in
elif chip_id == ap_chip.STM32:
AttributeError: module β€˜adafruit_platformdetect.constants.chips’ has no attribute β€˜STM32’

For switch:

Error while setting up mcp23017 platform for switch
Traceback (most recent call last):
File β€œ/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 193, in _async_setup_platform
await asyncio.shield(task)
File β€œ/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File β€œ/usr/src/homeassistant/homeassistant/components/mcp23017/switch.py”, line 41, in setup_platform
i2c = busio.I2C(board.SCL, board.SDA)
File β€œ/usr/local/lib/python3.8/site-packages/busio.py”, line 18, in init
self.init(scl, sda, frequency)
File β€œ/usr/local/lib/python3.8/site-packages/busio.py”, line 38, in init
from microcontroller.pin import i2cPorts
File β€œ/usr/local/lib/python3.8/site-packages/microcontroller/init.py”, line 29, in
elif chip_id == ap_chip.STM32:
AttributeError: module β€˜adafruit_platformdetect.constants.chips’ has no attribute β€˜STM32’

I would be grateful for help and support with solving the problem.

Thank you.
Bigu1975

Same issue… I hope a fast solution too.

I have the same Error :confused:

It has been reported by bigu1975:

Same here :frowning:

Downgraded to 0.114.4 and all is back to normal.
BTW, downgrading is very very easy - great HA system !

It working back again with 0.117.0 !

sorry for the intrusion but I’m going crazy with the MCP23017 integration. I have hassio installed in RP4 and was waiting for the version where the anomaly of i2c operation was repaired. I am pleased to read that 0.117 has been resolved, I proceed with the update but the mcp23017 still does not work. I’m trying frantically (I have the alarm driven by this chip !!) and I’m still in despair.
I am attaching what HA is telling me in the hope that someone will give me some advice. thank you

Logger: homeassistant.components.switch
Source: components/mcp23017/switch.py:38
Integration: Interruttore (documentation, issues)
First occurred: 10:13:25 (1 occurrences)
Last logged: 10:13:25

Error while setting up mcp23017 platform for switch

Traceback (most recent call last): File β€œ/usr/local/lib/python3.8/site-packages/adafruit_bus_device/i2c_device.py”, line 172, in __probe_for_device self.i2c.writeto(self.device_address, b"") File β€œ/usr/local/lib/python3.8/site-packages/busio.py”, line 116, in writeto return self._i2c.writeto(address, buffer, stop=stop) File β€œ/usr/local/lib/python3.8/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py”, line 49, in writeto self._i2c_bus.write_bytes(address, buffer[start:end]) File β€œ/usr/local/lib/python3.8/site-packages/Adafruit_PureIO/smbus.py”, line 308, in write_bytes self._device.write(buf) OSError: [Errno 121] Remote I/O error During handling of the above exception, another exception occurred: Traceback (most recent call last): File β€œ/usr/local/lib/python3.8/site-packages/adafruit_bus_device/i2c_device.py”, line 178, in __probe_for_device self.i2c.readfrom_into(self.device_address, result) File β€œ/usr/local/lib/python3.8/site-packages/busio.py”, line 106, in readfrom_into return self._i2c.readfrom_into(address, buffer, stop=stop) File β€œ/usr/local/lib/python3.8/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py”, line 56, in readfrom_into readin = self._i2c_bus.read_bytes(address, end - start) File β€œ/usr/local/lib/python3.8/site-packages/Adafruit_PureIO/smbus.py”, line 179, in read_bytes return self._device.read(number) OSError: [Errno 121] Remote I/O error During handling of the above exception, another exception occurred: Traceback (most recent call last): File β€œ/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 197, in _async_setup_platform await asyncio.shield(task) File β€œ/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run result = self.fn(*self.args, **self.kwargs) File β€œ/usr/src/homeassistant/homeassistant/components/mcp23017/switch.py”, line 38, in setup_platform mcp = MCP23017(i2c, address=i2c_address) File β€œ/usr/local/lib/python3.8/site-packages/adafruit_mcp230xx/mcp23017.py”, line 64, in init super().init(i2c, address) File β€œ/usr/local/lib/python3.8/site-packages/adafruit_mcp230xx/mcp230xx.py”, line 48, in init self._device = i2c_device.I2CDevice(i2c, address) File β€œ/usr/local/lib/python3.8/site-packages/adafruit_bus_device/i2c_device.py”, line 68, in init self.__probe_for_device() File β€œ/usr/local/lib/python3.8/site-packages/adafruit_bus_device/i2c_device.py”, line 180, in __probe_for_device raise ValueError(β€œNo I2C device at address: %x” % self.device_address) ValueError: No I2C device at address: 20

Hard to read not formatted log (use the </> at the top of the edit box [when you type in] to paste the logs or config files).
Anyhow, what I see at the end is:
in __probe_for_device raise ValueError(β€œNo I2C device at address: %x” % self.device_address) ValueError: No I2C device at address: 20
which tells me that your RPi does not find a MCP chip at I2C bus at address 20.
I woudl do the following:

  1. make sure I2C is enabled on RPi
  2. make sure the MCP chip is connected with relevant GPIO pins from RPi
  3. make sure the MCP address (hard wired) is setup for 20 as in the configuration

Was your MCP chip working with 0.114.4 version ?

Thanks for the immediate reply. Sorry for the formatting, I went wild. I ask you for a clarification on your suggestions:

  1. on the hassio SD I see that the i2C components are present in a folder called β€œoverlays”.
  2. MCP is connected to GPIO00 pin 27 sda0 and to GPIO1 pin28 scl0. I also tried to connect it to the other I2C pin 03 sda1 and 05 scl1ma to no avail.
    3 mcp is with address 20. and reset is correctly set.
    The chip works because I tested it with a pic16f that I use for testing.
    thank you

just updated to 0117.1 and now the log has changed with this

Error while setting up mcp23017 platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 197, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/mcp23017/switch.py", line 37, in setup_platform
    i2c = busio.I2C(board.SCL, board.SDA)
  File "/usr/local/lib/python3.8/site-packages/busio.py", line 31, in __init__
    self.init(scl, sda, frequency)
  File "/usr/local/lib/python3.8/site-packages/busio.py", line 70, in init
    raise ValueError(
ValueError: No Hardware I2C on (scl,sda)=(3, 2)
Valid I2C ports: ((3, 3, 2), (1, 3, 2), (0, 1, 0))

Apologies for late response. I hope yo have find the solution now.
If not I would only double check the chip as the message in your log:
ValueError: No Hardware I2C on (scl,sda)=(3, 2)
to me indicates that the chip is not communicating with RPi. Maybe the next line:
Valid I2C ports: ((3, 3, 2), (1, 3, 2), (0, 1, 0))
indicates that there is something wrong with address ? But this is wild guess … nothing sure… :frowning:

Thank you. I am only now reading the answer. It is true that RPI does not communicate. The problem is just RPI, I connected an oscilloscope to the outputs: I2C GPIO02, GPIO03 and also to GPIO00 and GPIO01. Can not see anything. I also tried reloading Hassio and restoring the snapshot but to no avail.
Could it be that RPI has damaged the I2C control?
I am really disheartened.

In my opinion it would be very unusual.
I am using only GPIO2 (SDA) and GPIO3 (SCL) to connect to MCP23017 (not using GPIO0 i GPIO1).
I assume you have followed the guideline to enable I2C on RPi (in my case there was a challenge to make USB folder name starting with /)…

I would look more for some commands to check I2C interface on RPI

Also if you have another MCP chip I woudl connect this one to check if the current one is not broken. If you do not have another MCP chip you may connect this one to another β€œmaster” like ESP8266 or ESP32 chip - easily programmable via ESPHome. This would give you more info if the issue is with RPi or with MCP chip.

Thanks. I tried with 5 chips, on esphome they work regularly but with RPI nothing.
I have some Wemos d1 but I don’t know how to interface them to RPI: is it possible to do this with HA ???

I suspected that both the breadboard I use for testing; I am building a pcb to have fixed welds. I will continue with the tests.
I have to win …

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)
obraz

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?

thanks

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 ?

Hello,

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:
dtparam=i2c_arm=on

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

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:
1.
Check if config.txt has line (without # at the beginning):
dtparam=i2c_arm=on
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?
thanks

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.