How can I initialize the I2C bus on the BeagleBone Black Rev C running Embedded Linux?

Hey guys, how can I initialize the I2C bus on the BeagleBone Black Rev C running Embedded Linux? I am getting the error Failed to open the bus: No such file or directory, but I have verified that the I2C module is loaded and checked the device tree overlay. Here are the steps I took to verify the I2C module: 1. Loaded the I2C module using modprobe i2c-dev. 2. Checked that the device tree overlay for I2C is applied correctly. The error occurs when attempting to open the I2C bus
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

int main() {
int file;
char *bus = "/dev/i2c-1";
if ((file = open(bus, O_RDWR)) < 0) {
perror("Failed to open the bus");
return 1;
}
return 0;
}
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

int main() {
int file;
char *bus = "/dev/i2c-1";
if ((file = open(bus, O_RDWR)) < 0) {
perror("Failed to open the bus");
return 1;
}
return 0;
}
8 Replies
Sterling
Sterling5mo ago
Well, @Boss lady I would suggest you check if the I2C device nodes exist under /dev. Normally, it's named as /dev/i2c-X .
Sterling
Sterling5mo ago
And the X stands for Bus No.
Ming
Ming5mo ago
Some other things to check (Examples and responses from my BBB which has i2c working): The version of the BBB Image you are using

debian@BeagleBone:~$ cat /etc/issue
Debian GNU/Linux 11 \n \l

BeagleBoard.org Debian Bullseye IoT Image 2023-09-02
Support: https://bbb.io/debian
default username:password is [debian:temppwd]

debian@BeagleBone:~$ cat /etc/issue
Debian GNU/Linux 11 \n \l

BeagleBoard.org Debian Bullseye IoT Image 2023-09-02
Support: https://bbb.io/debian
default username:password is [debian:temppwd]
If the i2c modules are loaded (not always an issue if not)
debian@BeagleBone:~$ lsmod | grep i2c
debian@BeagleBone:~$
debian@BeagleBone:~$ lsmod | grep i2c
debian@BeagleBone:~$
(No modules on my system) Any messages in the bootlog:
debian@BeagleBone:~$ dmesg | grep i2c
[ 8.803295] omap_i2c 4802a000.i2c: bus 1 rev0.11 at 100 kHz
[ 9.367701] omap_i2c 4819c000.i2c: bus 2 rev0.11 at 100 kHz
[ 10.567358] i2c /dev entries driver
[ 10.744849] input: tps65217_pwr_but as /devices/platform/ocp/44c00000.interconnect/44c00000.interconnect:segment@200000/44e0b000.target-module/44e0b000.i2c/i2c-0/0-0024/tps65217-pwrbutton/input/input0
[ 10.747918] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 400 kHz
debian@BeagleBone:~$ dmesg | grep i2c
[ 8.803295] omap_i2c 4802a000.i2c: bus 1 rev0.11 at 100 kHz
[ 9.367701] omap_i2c 4819c000.i2c: bus 2 rev0.11 at 100 kHz
[ 10.567358] i2c /dev entries driver
[ 10.744849] input: tps65217_pwr_but as /devices/platform/ocp/44c00000.interconnect/44c00000.interconnect:segment@200000/44e0b000.target-module/44e0b000.i2c/i2c-0/0-0024/tps65217-pwrbutton/input/input0
[ 10.747918] omap_i2c 44e0b000.i2c: bus 0 rev0.11 at 400 kHz
I have the i2c devices
debian@BeagleBone:~$ ls /dev/i2c*
/dev/i2c-0 /dev/i2c-1 /dev/i2c-2
debian@BeagleBone:~$ ls /dev/i2c*
/dev/i2c-0 /dev/i2c-1 /dev/i2c-2
Boss lady
Boss lady5mo ago
@Sterling I have checked and it does exist
Sterling
Sterling5mo ago
Alright then, @Boss lady you will have to load in the I2C modules. It's simple, just run the following code;
sudo modprobe i2c-dev
sudo modprobe i2c-dev
Afterwards, check if it's successful by running the following on your terminal;
lsmod | grep i2c
lsmod | grep i2c
Sterling
Sterling5mo ago
I hope this helps ☺️
Boss lady
Boss lady5mo ago
Thanks @Sterling although, I have already loaded my I2C module using the mod probe command it's still not displaying any output
Ming
Ming5mo ago
@Boss lady What version of the Kernel are you running? You can find out by executing
uname -r
uname -r
I'm running the stock BBB image with the 5.10 kernel and am using my i2c.
Want results from more Discord servers?
Add your server