RED HAT
RED HAT
DIIDevHeads IoT Integration Server
Created by Boss lady on 7/2/2024 in #middleware-and-os
How do I set the I2C (Mpu-6050) slave address in my application?
@Boss lady Another thing to consider is permissions. Make sure you have the necessary permissions to access the I2C bus. If you're running your application as a non-root user, you might encounter this error. You can try running your application with sudo to see if that resolves the issue. Here's a modified version of your code with the updated address:
Copy code
int addr = 0x68; // The I2C address of the MPU-6050
if (ioctl(file, I2C_SLAVE, addr) < 0) {
perror("Failed to acquire bus access and/or talk to slave");
return 1;
}
Copy code
int addr = 0x68; // The I2C address of the MPU-6050
if (ioctl(file, I2C_SLAVE, addr) < 0) {
perror("Failed to acquire bus access and/or talk to slave");
return 1;
}
Also, ensure you have the I2C device open correctly:
Copy code
int file;
if ((file = open("/dev/i2c-1", O_RDWR)) < 0) {
perror("Failed to open the i2c bus");
return 1;
}
Copy code
int file;
if ((file = open("/dev/i2c-1", O_RDWR)) < 0) {
perror("Failed to open the i2c bus");
return 1;
}
7 replies