Help Needed: Error in Real-Time Data Acquisition Using I2C on BeagleBone Black

Hello guys, am settling up the BeagleBone Black for real-time data acquisition using I2C on an embedded Linux OS? I have tried setting up the BeagleBone Black with the embedded Linux OS, configured the I2C protocol on the BeagleBone Black, connected the I2C device to the BeagleBone Black, implemented the necessary code to communicate with the I2C device, attempted to acquire real-time data from the I2C device. But keep getting the error Failed to acquire bus access and/or talk to slave. This is my code
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/i2c-dev.h>

int main()
{
int file;
char filename[40];
int addr = 0x68; // I2C device address

snprintf(filename, sizeof(filename), "/dev/i2c-1"); // I2C bus
file = open(filename, O_RDWR);
if (file < 0) {
printf("Failed to open the I2C bus\n");
return 1;
}

if (ioctl(file, I2C_SLAVE, addr) < 0) {
printf("Failed to acquire bus access and/or talk to slave\n");
return 1;
}

// Code to communicate with the I2C device and acquire real-time data

close(file);
return 0;
}
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/i2c-dev.h>

int main()
{
int file;
char filename[40];
int addr = 0x68; // I2C device address

snprintf(filename, sizeof(filename), "/dev/i2c-1"); // I2C bus
file = open(filename, O_RDWR);
if (file < 0) {
printf("Failed to open the I2C bus\n");
return 1;
}

if (ioctl(file, I2C_SLAVE, addr) < 0) {
printf("Failed to acquire bus access and/or talk to slave\n");
return 1;
}

// Code to communicate with the I2C device and acquire real-time data

close(file);
return 0;
}
Can anyone help me with documentations or steps I can use or study to solve my current predicament @Middleware & OS @Helper
Solution:
Thanks, it worked can u help me with any documentations so I can study more in it
Jump to solution
7 Replies
MQ-FAE
MQ-FAE5mo ago
You can use i2cdetect command to check your slave address is exist or not
MQ-FAE
MQ-FAE5mo ago
I think it does not exist on bus
Marvee Amasi
Marvee Amasi5mo ago
Hi make sure your user has permission to access the I2C bus. You might need to add your user to the i2c group using
sudo usermod -a -G i2c $USER
sudo usermod -a -G i2c $USER
Might be problem with your i2C permission
Boss lady
Boss lady5mo ago
Okay I would try this now
Boss lady
Boss lady5mo ago
Okay, I should replacer $USER with the name of my user right??
Marvee Amasi
Marvee Amasi5mo ago
Yes sure, see if it works
Solution
Boss lady
Boss lady5mo ago
Thanks, it worked can u help me with any documentations so I can study more in it
Want results from more Discord servers?
Add your server