How do I set the I2C (Mpu-6050) slave address in my application?
@Middleware & OS Hello Guys, how do I set the I2C (Mpu-6050) slave address in my application, am getting the error
Failed to acquire bus access and/or talk to slave: Input/output error
Failed to acquire bus access and/or talk to slave: Input/output error
but i have Checked the wiring and confirmed the slave device address. here's my code below
int addr = 0x48; // The I2C address of the slave device if (ioctl(file, I2C_SLAVE, addr) < 0) { perror("Failed to acquire bus access and/or talk to slave"); return 1; }
int addr = 0x48; // The I2C address of the slave device if (ioctl(file, I2C_SLAVE, addr) < 0) { perror("Failed to acquire bus access and/or talk to slave"); return 1; }
Solution
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-6050if (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-6050if (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!