Trying to use some switches through I2C directly on the Raspberry Pi in Hass.io

Hi there!

I am trying to activate some switches that will be connected on an MCP23017 that is connected to the GPIO pins of the Raspberry Pi 4 that runs Hass.io.

I followed the instructions from here to activate I2C.
https://www.home-assistant.io/hassio/enable_i2c/

Here are the steps:

  • Connect a USB drive to a device capable of adding and editing files to the USB drive. Format a USB stick with FAT32/EXT4/NTFS and name the drive CONFIG (uppercase).

  • In the root of the USB drive add a folder called /modules .
    (BTW, the folder name is /modules and not modules, right?)

  • Inside that folder add a text file called rpi-i2c.conf with the following contents:

i2c-bcm2708
i2c-dev
  • In the root of the USB drive add a file called config.txt with the following contents:
dtparam=i2c1=on
dtparam=i2c_arm=on
  • Insert the USB drive into your Raspberry PI.
  • Now go to your Home Assistant web interface, in the sidebar click Hass.io > System
  • Now click Import from USB .
  • This will restart your Hass.io instance, and load the new USB configuration.

How do I know that the Hass.io restarted? In my case, when I press the IMPORT FROM USB button, all I see is a time wheel for a millisecond and then the button turns green. Nothing seems to restart as I can use Hass.io instance immediately afterwards

And is there a way to check if I2C activated?

Then I followed the instructions from here to activate the switches.
https://www.home-assistant.io/integrations/mcp23017/

This is the code I am using in configuration.yaml:

switch:

# MCP switches
  - platform: mcp23017
    i2c_address: 0x20
    pins:
      11: Switch1
      12: Switch2

I cannot find the switches in the Entities Card.

Any help is truly appreciated!
ygreq

Hi,
I have PIR3 B + but it should be the same for you. After importing, my hassio didn’t reset. I2C also didn’t work immediately after importing. I had to manually reboot it by myself. After the reset it was ok.
Ideally, if you had any logic analyzer or oscilloscope you would see immediately if RPI is “talking” via i2c.

Also check if the address matches what you actually connected. In MCP23017 you have 3 pins with which you set the i2c slave address.

Hi Sebastian!

Thank you for your help!
Regarding the i2c activation, I restarted it a few times now. No avail. And unfortunately I don’t have neither do I know how to use logic analyzers and oscilloscopes. Can I check via code? For example can I check the i2c table somehow?

And another thing I read on the forums. In Hassio -> System -> Host System -> Hardware I should see the USB Stick somewhere in disk: , right? Now I only have this and maybe none of them is the actual USB Stick? What do you think?

disk:

  • /dev/mmcblk0
  • /dev/mmcblk0p8
  • /dev/mmcblk0p7
  • /dev/mmcblk0p5
  • /dev/mmcblk0p6
  • /dev/mmcblk0p2
  • /dev/mmcblk0p1
  • /dev/mmcblk0p3
  • /dev/mmcblk0p4

And I checked to use the recommended address for MCP2017 (0x20). I also tested it on an ESP via ESPHome and it worked there.

I don’t think you can check if i2c is physically running from hassio. Simple analyzers can be bought online for a few dollars. Using them is very easy, you would certainly manage :slight_smile:) But now, it will be best to check it on the actual device. What MCP board do you have?

Regarding USB stick. Unfortunately I don’t have access to hassio right now so I don’t know what it looks like.
After you press IMPORT button, scroll down and look on the log (press “refresh” of course). What does it look like at your log?

I will look into logic analysers for sure in this case. Maybe you can recommend something?
I am using a MCP23017 module. Like this: [https://www.aliexpress.com/item/32773642168.html](http://aliexpress store item)

This is what it says when I don’t have the USB Stick plugged in. And the same info is logged when it is plugged in and I press IMPORT FROM USB.

19-11-29 11:24:17 INFO (MainThread) [hassio.hassos] Syncing configuration from USB with HassOS.
19-11-29 11:24:17 INFO (MainThread) [hassio.host.services] Restart local service hassos-config.service
19-11-29 11:24:17 INFO (MainThread) [hassio.utils.gdbus] Call org.freedesktop.systemd1.Manager.RestartUnit on /org/freedesktop/systemd1

I found this about logic analysers: Cheap logic analyzer SPI i2c UART

I haven’t watched the whole movie you posted so I don’t know if they recommend it or advise against such an analyzer, but I definitely recommend it to you. There are no great features but for analyzing simple protocols it is perfect.

I like your module. It is simple (without unnecessary fountains) and cheap :slight_smile:
You have 3 pins A0, A1 and A2 to determine the address. You can consider this address or use the default one. I’m not sure how initialization is done in this mcp23 component. It’s best to connect all of them to GND.

You can try one more thing quickly. Different chips interpret “address” differently. It can be 7 or 8 bit. Try to use 0x10 or 0x40 instead

Still learning I2C, but considering that 0x20 worked on ESPHome, do you think it can change its default address without me doing anything to the address pins?

I will try nonetheless. Thank you for your advice.

BTW, my best guess right now is that the USB Stick didn’t install I2C. Just don’t know how to do it better. :slight_smile:

And as a side note, this help file https://www.home-assistant.io/integrations/mcp23017/ should definitely mention this help file about enabling i2c first: https://www.home-assistant.io/hassio/enable_i2c/. As of now it does not.

Appropriate interpretation of the i2c address is needed from both sides: master and slave. Changing ESP on raspberry you change the “master” side.
Try and let me know of the result.

Maybe you’re right they could write directly on the integration page, how enabling i2c. But you managed to find it without it :slight_smile:)

Do you have a simple multimeter? Check voltage at SDA and SCL pin. If i2c is enabled, they should have pull up enabled, i.e. they should be ~ 3.3V. Otherwise they will have 0V.

I will test with a multimeter. Thank you for the tips!!
Will let you know as soon as I find more info

I created a PR to add that to the mcp23017 documentation: https://github.com/home-assistant/home-assistant.io/pull/11425

You can contribute to the documentation creating a PR any time you see something missing, confusing or outdated.

Thanks.

What is a PR exactly? :slight_smile: Thank you!

I abandoned this project for now. I cannot find a solution to make this work. For now I will be using an extra ESPHome enabled ESP to manage all that I wanted to manage directly via the HASS.io Raspberry Pi. :frowning:

Sorry for assuming that you would know that, it is a Pull Request (PR). The source code of the www.home-assistant.io website is hosted on github so you can suggest changes to a piece of documentation by editing it’s page on github and submitting a Pull Request with your changes.
On every page of the documentation website there is a link that reads “Edit this page on Github”, it’s just a matter of clicking on that link, make some changes making sure you abide by the Documentation Standards and submit a PR. By doing so you would have contributed to this great project that is called Home Assistant.

Thank you for the intro. I know a thing or 2 about github. Just didn’t know what PR stood for.

Thank you. I will!

1 Like

Did you ever get this working @ygreq?

I thought I did answer this :D. Ooops!

Nope. I did not. I used an ESPHome enabled device