I2c not working on the Pi4

Just in the middle of moving my Home Assistant from a Pi3 to a Pi4 and it seems i2c isn’t working on the Pi4.

Just tested the same USB stick called CONFIG with the relevant folder and two files (following these steps here on a Pi3, it works fine - i2c enabled on reboot. On a Pi4, it doesn’t do anything.

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/smbus/smbus.py", line 81, in open
    self._fd = os.open(path, os.O_RDWR, 0)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'

Has anyone come across this yet?

1 Like

Same issue. :confused: Doesn’t seem to be working on the Pi4!

Same situation with me. I was able to enable the i2c bus in HASSIO on all my other Raspberry Pis, but I can not enable it on my Pi4 running hass.io 3.8 - 32bit. I need this to work because I just bought several 4gb RAM Pi 4s and I integrate the mcp23017 i/o expander chips to them. Anyone figure this out yet?

I got I2c working with the BME680 sensor and a Pi4. I did this by editing the files directly from the SD card plugged into a laptop.
Need to add this file:
hassos-overlay/etc/modules-load.d/rpi-i2c.conf
Containing only these two lines:

i2c-bcm2708
i2c-dev

Need to edit this file:
hassos-boot/config.txt
Uncomment only this one line:

dtparam=i2c_arm=on

On occasion the sensor doesn’t connect on boot, but a restart fixes it.

2 Likes

This webpage could maybe help you to activate the i2c bus on Pi4 (sorry it is in French…)

1 Like

Thanks for the reply. So I guess this is why we are having a problem, I am using the latest version of Hass.IO, version 3.8, and it does not have a “hassos-boot” partition on the SD card. The only partitions are: hassos-overlay, hassos-data, 268MB Volume, and hassos-kernel. None of which contain a “config.txt” file. Which version of HA are you using when you got this to work?

OK! from your clues, I got it working! I wrote up the procedure:

How to enable i2c on the Pi4 board Running HassOS 3.8 in HASS.IO

Issue: the “import from USB” procedure to enable i2c does not work on a Pi4 (only tested on HassOSv3.8)

Resolution: manually edit the required files in linux (I used KALI Linux)

1) remove the sd card from the pi and plug it into a pc running Linux
2) most likely linux will not mount the partition "hassos-boot" because it is FAT
	a) open a terminal window
	b) type > blkid
	c) in the resulting output, you'll see "LABEL="hassos-boot", note the location, mine is /dev/mmcblk0p1
	d) type > sudo mkdir /mnt/msdos
	e) type > sudo mount -t vfat /dev/mmcblk0p1 /mnt/msdos
	d) now you can open the file /mnt/msdos/config.txt
	e) uncomment the line "dtparam=i2c_arm=on"
3) If the hassos-overlay partition mounted, (if not, do step 2 for this partition)
	a) open the file: hassos-overlay\etc\modules-load.d\rpi-i2c.conf
	b) ensure it has only these 2 lines: (mine already did, likely from when trying "import usb" method)
		i2c-bcm2708
		i2c-dev
4) replace the sdcard back into the pi and start normally
	a) the i2c bus should be functioning now
3 Likes

Awesome! Glad I found your post. I was fighting with the i2c interface for a few days now. Checking whether it might be Raspi 4 related was a lucky punch. It worked right away.
Perhaps a note should be added to the official how-to page (https://www.home-assistant.io/hassio/enable_i2c/) indicating that the described method is not yet working for Raspberry Pi 4.

Hi Dan!

I am on Ubuntu now trying to follow your steps. On step 2.d, should I just type /mnt/msdos/config.txt in the console and a text editor should pop up? Because I am getting: /mnt/msdos/config.txt: line 65: [all]: command not found.`

BTW, I have rPi 3b, but the Import from USB does nothing to my system. So I found your post.

Not OP, but the answer is no. As you found, just typing that will try to execute / launch “config.txt.”

What you want to do is put the name of your favorite text editor in front of that (nano, gedit, vim, etc).

Thank you so much! I’ve used nano a year ago so I forgot how it’s done. Newbie here obviously :slight_smile:
Any idea how to rename in linux a format type from .txt to .conf for step 3? :smiley:
Because I created a text file, added the lines but I am stuck again as I have a rpi-i2c.conf.txt file instead of a rpi-i2c.conf file

Thank you so much!

Hmmm… how did the file end up with .txt at the end? Regardless, the command you are looking for is “mv” (move), as in “mv original.file new.file”

The file was not present there in its specific place and from my understanding you have to upload it in order to make i2c work. https://www.home-assistant.io/hassio/enable_i2c

So what I did is create it in the Ubuntu interface. Probably I should have created it in the cli but I don’t know how. :confused:

So like I said, what I did is create a file in the Documents folder in Ubuntu because it did not let me save it in the hassos-overlay\etc\modules-load.d folder. Now I am trying to move it and it does not let me as I do not have enough privileges. So back to square one.

Thanks to your help, I managed to create the file in nano.

Once again, thank you so much, @mrand and @dankrill!

If you are absolutely sure you have the file correct and are not overwriting an existing file that you might want to keep, you elevate your permissions by putting “sudo” before your command.

If there is already a file with the same name at the destination location, you can rename it so that it’s still available for future reference: “sudo mv filename filename.original”

I managed to do that. Thank you!! A bit offtopic, but how do you elevate your privileges in the Ubuntu interface and not in the cli?

Assuming you’re using the default window manager, looks like http://ubuntuhandbook.org/index.php/2020/04/open-as-administrator-ubuntu-20-04/ might allow you to open a directory with elevated access. Just be aware it’s powerful… if you mis-drag and drop, you can overwrite files that could take your system down.

1 Like

Hi Dan,

I managed to get I2C working on RPi4. For ONE sensor, sitting on the default SDA, SCL pins (GPIO2 and GPIO3). However I have 5 other BME280 sensors, sitting on different GPIO-s.

The below code in config.txt worked on RPi2 earlier, but with RPi4, hassio is not booting if I add these.

dtoverlay=i2c-gpio,bus=7,i2c_gpio_delay_us=1,i2c_gpio_sda=5,i2c_gpio_scl=6
dtoverlay=i2c-gpio,bus=6,i2c_gpio_delay_us=1,i2c_gpio_sda=14,i2c_gpio_scl=15
dtoverlay=i2c-gpio,bus=5,i2c_gpio_delay_us=1,i2c_gpio_sda=11,i2c_gpio_scl=8
dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24
dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=17,i2c_gpio_scl=27

Any idea on how to enable multiple i2c buses?

Everyone with similar issues (I2C not working on Pi4), please upvote this feature request: Allow enabling I2C and 1wire via Home Assistant CLI :+1:

For me, the easiest way to enable I2C, on Windows, was to follow these steps: https://github.com/Misiu/argon40/issues/1#issuecomment-657207579

this is still not working for me , I have been trying for days with every possible combination
I might just give up on Hassio if such a basic function of Pi is not available …
is there a hardware version of the Pi4 board I need to check for ? mine is brand new bough 2 weeks ago ( trying to move up from Pi3 )