Hello! I’m trying to use the Software I2C (i2c-gpio) interface instead of the hardware i2c interface on a raspberry pi cm4 to work with a sensor that needs clock stretching support.
I just tested this on my Raspberry Pi 3 and 4.
For the Raspberry Pi 3, your setup worked perfectly, for the Raspberry Pi 4, I had to add dtparam="i2c-gpio=on".
I also noticed there is a difference in numbering.
With the Raspberry Pi 3, my I2C device was numbered 3, with the Raspberry Pi 4, it was numbered 11.
Oh perhaps my mistake was just setting “i2c-gpio” instead of “i2c-gpio=on”. I’ll try this on my end once the Balena API issues this morning are sorted out.
Just to confirm @TJvV, your full configuration with the Raspberry Pi 4 was as shown below?
i2cdetect -l is how I arrived at the number 11 for my software device.
For reference, I tested it with balenaOS 2.83.10+rev1 in development mode, device type raspberrypi4-64.
Thank you so much @alanb128 ! If I can get this working it will really help out my open source project! There are lots of people that will be quite thankful!
As I mentioned, feel free to poke around at the device I linked above as well!
You’re welcome @keenanjohnson! In my setup, I have a CM4 (104016) in the IO board with balenaOS 2.85.2+rev3 in development mode, device type Raspberry Pi CM4 IO Board. In the dashboard, I changed the “Define DT overlays” to the following value: "vc4-fkms-v3d","i2c-gpio","i2c_gpio_sda=2","i2c_gpio_scl=3"
Running i2cdetect -l gives:
Is that what you would expect to see? I’m not sure how to confirm that software I2C is being utilized - the documentation seems a bit sketchy. (I’m learning a bit about this as I go along!) I do have a BMP280 on pins 3 and 5 that seems to be detected either way.
So this is interesting because I believe (I’m not an expert) that the second interface (i2c-11) is a software i2c interface that bit-bangs the GPIOs to create an I2C bus while the first interface (i2c-1) is the hardware periphial.
What is weird is that the default i2c bus is on the same pins you’ve defined for the software bus (i2c-11) pins 2 and 3, so I’m not sure what that means haha. That’s why I was trying to disable the hardware bus via my dt_params above. I’m assuming you haven’t set any of those?
What is the vc4-fkms-v3d? Is that related to the I2C? Is seems to be something about the video drivers from my googling?
I was able to replicate this on my device. Interesting, I wasn’t able to do it via custom configuration variables (BALENA_HOST_CONFIG_dtoverlay), but had to select the “Define DT overlays" thing in the Balena web UI.
This allows me to see the i2c interface as interface 11, but unfortunately, I can’t see any of my devices. Digging into this further, I see that DMESG reports it has started the i2c drive on different pins than I specified above. I’m not sure why that would be, but perhaps you have some insight @alanb128 ?