Boss lady
Boss lady
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?
Thanks everyone!, I didn't realize the address for the MPU-6050 was different. I changed the address to 0x68 and now my code looks like this:
int file;
if ((file = open("/dev/i2c-1", O_RDWR)) < 0) {
perror("Failed to open the i2c bus");
return 1;
}

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;
}
int file;
if ((file = open("/dev/i2c-1", O_RDWR)) < 0) {
perror("Failed to open the i2c bus");
return 1;
}

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;
}
I ran it with sudo and it worked! Thanks again for your help!
7 replies