Thumbnail

MPU6050 Accelerometer Gyro Temperature

How to add the MPU6050 Accelerometer Gyro Temperature robot skill

  1. Load the most recent release of ARC (Get ARC).
  2. Press the Project tab from the top menu bar in ARC.
  3. Press Add Robot Skill from the button ribbon bar in ARC.
  4. Choose the I2C category tab.
  5. Press the MPU6050 Accelerometer Gyro Temperature icon to add the robot skill to your project.

Don't have a robot yet?

Follow the Getting Started Guide to build a robot and use the MPU6050 Accelerometer Gyro Temperature robot skill.


How to use the MPU6050 Accelerometer Gyro Temperature robot skill

The MPU6050 EZ-Bit module is an all-in-one Gyro/Accelerometer/Temperature sensor over an i2c connection. This ARC control will read data from the sensor and set EZ-Script Variables, respectively. The control will require an Initialization (INIT) before the sensor will return data. If the sensor is not connected, the EZ-B v4 will lock up. This control will not read data automatically. We have provided a ControlCommand() for querying the device and setting the variables. Each time you wish to receive data from the MPU6050, you must ask the control to RUN ONCE with ControlCommand().

Here is an example code for looping every 100 milliseconds to request data from the MPU6050. The data from the MPU6050 will be stored in EZ-Script Variables. You may press the CONFIG button on the control to see what variables are being set with data. Ensure you have an MPU6050 ARC control added and an MPU6050 connected to the i2c of the EZ-B, and paste this code into an EZ-Script control. When this script runs, the MPU6050 will continually update the specified variables with data every 100ms... Check the Variable Watcher to view the data from the sensor.
ControlCommand("MPU6050", Init)

:loop

ControlCommand("MPU6050", RunOnce)
  
sleep(100)

goto(loop)


In this video below, I am using the JD project with MPU. The project can be found on the EZ-Cloud as JD With MPU6050 Accelerometer.

How It Works

Interested in how the IMU Sensor works? Find out by reading this fantastic article HERE.

Video


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

#41  

@Jeremie,  thanks for the reply here is a picture of the setup.  The ezb4 is being power with 8.4 volts the MPU6050 is being powered by the 3.3V from the i2c port on the ezb4 the wire is about 17inchs long. The SDA and SCL pins have 330 resistors connected to the Vcc pin.

User-inserted image

User-inserted image

The sda pins on the ezb4 and the MPU connected together and the same goes for the scl pins.

Is there anything else I can provide for you.

In the skill it shows the temp but as soon as I click the int button in the skill it normally makes the red LED light up and stays on and the ezb4 disconnects from the network.

PRO
Canada
#42  

Thanks for the photos! 2 things:

  1. Your wires may be too long I would look at shortening those.

  2. It looks like you used 470ohm resistors in parallel with the onboard pull-ups, I would recommend going lower (220 ohms).

It looks like we have very similar boards. Here's my setup (works solidly):

8 inch cable:

User-inserted image

220 ohm Pull-up resistors soldered in place of the original (2.2Kohm resistors) I believe:

User-inserted image

Yeah, I also powered it from the EZ-B 3.3V.

I just use the example code from above for testing:

ControlCommand("MPU6050", Init)

:loop

ControlCommand("MPU6050", RunOnce)
  
sleep(100)

goto(loop)
#43  

@Jeremie, I installed the 220 ohm resistors and it is working great now thanks for your help!

#44  

DJ,  Is there anyway I can get the source for this skill I would like to see if I can enhance it for my project. by making a new version that is more feature rich.  Please let me know if this is something we can do.

#46  

DJ, Thanks but it looks like I am not going to be able to do this because my Windows 11 is on an Arm64 and you can only install Visual Studio 2022 Community for ARM64.  Based on what is posted there are issues with 2022 Community version.   But thank you for providing the source code.

PRO
Synthiam
#47  

Yeah Microsoft has a pretty big bug that they refuse to fix about that.

#48  

DJ, I am trying to understand which MPU6050 class you guys are using and what type of values that class is sending back so if you can provide any information on that class it would be a big help.  I just need to understand what type of pre processing the class is doing to the values.

The following code is from the MPU6050.cs file in the source you sent me.  Just as an FYI this skill is not returning the correct temp value.  I get a value of like 217c in the skill.

using System;
using System.Linq;

namespace EZ_B {

  public class MPU6050 {

    EZB _ezb;

    public MPU6050(EZB ezb) {

      _ezb = ezb;
    }

    public void Init() {

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

    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;
    }
  }
}