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
but i have Checked the wiring and confirmed the slave device address.
here's my code below
Solution:Jump to 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:
```c
int file;
if ((file = open("/dev/i2c-1", O_RDWR)) < 0) {...
5 Replies
Hey @Boss lady , I think the issue might be with the address you're using. The MPU-6050 typically has an I2C address of either 0x68 or 0x69, depending on the AD0 pin's state. Try changing the address to 0x68 and see if it works. Also, double-check the wiring for the AD0 pin to ensure it matches the address you're using.
Yeah 👍, you should also ensure that the I2C bus you're trying to access is the correct one. Sometimes, the I2C bus number can differ based on the hardware platform. For example, on a Raspberry Pi, you might need to use /dev/i2c-1 instead of /dev/i2c-0. Can you share the part of your code where you open the I2C bus?
@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:
Also, ensure you have the I2C device open correctly:
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:
I ran it with sudo and it worked! Thanks again for your help!
Thanks for pointing that out, @Marvee Amasi . Here's the part of my code where I open the I2C bus:
It seems like I might be using the wrong I2C bus. I have changed it to /dev/i2c-1 . I appreciate the suggestion!