How to add the MPU6050 Accelerometer Gyro Temperature robot skill
- Load the most recent release of ARC (Get ARC).
- Press the Project tab from the top menu bar in ARC.
- Press Add Robot Skill from the button ribbon bar in ARC.
- Choose the I2C category tab.
- 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.
Question can we also add offsets to the MPU skill so it can be calibrated like you can in the Arduino code? See Below:
I have used this to help adjust the MPU in Arduino code using the MPU6050_6Axis_MotionApps20.h lib.
This would allow you to zero/calibrate the gyro. That has been used within your project as every MPU6050 is not the same.
You can modify the arduino code to do that. Or you can modify the values in ARC. You can do this with math functions, such as a + (addition) or - (subtraction)
For example, if you have a variable $AccelX, you can add to it by doing this.
$AccelX = $AccelX + 2
That will add the value of 2 to the previous value in the variable.
I agree a DJ that can be done but it would be nice to set it and forget it so to speak. You know work smarter not harder LOL
I understand - it's a lot of resources (costly) to have programmers spend a workday modifying a robot skill so it can add and subtract a number
@Jeremie, Well I finally got to the point where I hooked up the MPU6050 with the pull up resistors like you said but it starts out and after a short time the red LED on the ezb4 stays on and then the ezb4 connection disconnects so now what can I do to address this?
Hello @smiller29 that means you’re getting communication lock up. Try polling the sensor slower and see if that helps or you can adjust the pull-up values. There are plenty of different MPU6050 modules out there so I can’t really say what will work exactly for you. 330 ohm pull-ups worked with my modules.
You’re always welcome to post code and pictures if you’d like.
@Jeremie the loop has a sleep 2000 in it and does not help what do you think I should bump the pull up resistors to?
Hello again @smiller29,
When using DIY electronic modules with I2C sometimes some tinkering around needs to be done.
I really don't have a good idea of what your setup looks like. Are your I2C wires long? Which MPU-6050 module are you using? Have you tried changing the pullup resistors to a different value? Is there an LED on the MPU6050 module that tells you the 3.3V power is reaching the module? Are you powering the module with 3.3V before or after the voltage regulator?
I would try the following: shorten the wires, check your supply voltage to the module, and if all looks good then try bringing the pull-ups down to the next standard resistor value (likely 220 ohm).