Pakistan
Asked — Edited

I2c In C# Not Reading Values

I have mpu-6050 6dof imu. I want to read the value of who_am_i register with register number 0x75. The register returns address 0x68. But I am getting 255. The device address is 0x68 as well. Code is as follows:

byte[] ret = ezB_Connect1.EZB.I2C.Read(I2C.ReadArgsEnum.Auto,0x75,1);

here is the register description for the device:RM-MPU-6000A.pdf

I checked my imu with arduino and it works fine. So, any help here?


ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

PRO
Synthiam
#2  

You got it working? Can you share your code please :)

#3  

Sure! But it will take a couple of days in applying the filter and all, then I would share the final product! :)

PRO
Synthiam
#4  

awesome! I'm looking forward to seeing your success :D

#5  

Hi I have mpu-6050 too and i try to read the value from C# and i have some problems...

I tried this command : ezB_Connect1.EZB.I2C.Read(I2C.ReadArgsEnum.Auto,0x75,1); and it does't work cause there is this method "I2C.ReadArgsEnum.Auto" more over the read method accept only 2 values.... Does it exist some where a sample to use the device mpu-6050 by using C# ?

confused confused

PRO
Synthiam
#6  

Please share your code.

Also, in visual studio there is auto complete, which shows you the command syntax as you type.

Removed duplicate thread.

PRO
Synthiam
#7  

ps, i upgraded the EZ-SDK today - ensure you upgrade as well.

Now that i'm in front of a PC, here's example code...


  public class MPU6050Example {

    MPU6050  _mpu;

    public FormMPU6050() {

      InitializeComponent();

     // Create the mpu6050 object 
     // Include a reference to the EZB (most likely in your EZB Connection UserControl)
      _mpu = new MPU6050(ucEZBConnect1.EZB);
    }

    private void btnInit_Click(object sender, EventArgs e) {

      // Init is required before you can begin obtaining data
      _mpu.Init();
    }

    void getData() {

      try {

        EZ_B.Classes.MPU6050Cls response = _mpu.GetData();

        // do something with the data

      } catch (Exception ex) {

        // handle your exception
      } finally {

      }
    }
  }

#8  

Hi DJ Sures You are crédible :-) , i just ask a new api and you made it in few minutes. thank you very much. I have included your code in my visual studio and tried to print the value of the Gyro but the values of the gyro are initials

label2.Text = response.GyroX.ToString(); // value 0 label3.Text = response.GyroY.ToString(); // value 0

there is something wrong in my code i think. i keep on to look for and keep you inform thank you again. tired

#9  

Hi DJ sures It's OK, that works fine when i call the init function before the get data. Thank you have a good week end. Bye Christophe:) :)

#10  

Hi DJ Sures My projet works fine but I have just a remark to say. I think that you have reversed :

  • the value GyroX with the AccelX
  • the value GyroY with the AccelY Thank you again.
    Bye Christophe
PRO
Synthiam
#11  

The data collected is correct, they are not reversed.


    public Classes.MPU6050Cls GetData() {

      _ezb.I2C.Write(0x68, new byte[] { 0x3B });

      byte [] everything = _ezb.I2C.Read(0x68, 14).Reverse().ToArray();

      Classes.MPU6050Cls cls = new Classes.MPU6050Cls();

      cls.AccelX = BitConverter.ToInt16(everything, 12);
      cls.AccelY = BitConverter.ToInt16(everything, 10);
      cls.AccelZ = BitConverter.ToInt16(everything, 8);
      cls.TmpC = (BitConverter.ToUInt16(everything, 6) / 340) + 35;
      cls.GyroX = BitConverter.ToInt16(everything, 4);
      cls.GyroY = BitConverter.ToInt16(everything, 2);
      cls.GyroZ = BitConverter.ToInt16(everything, 0);

      return cls;
    }