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

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.

Finland
#1  

when this come sell?

PRO
Canada
#3  

Nice look forward to this and other addons , like Neopixel, an LCD display, an OLED display and also a Infrared transmitter (change channels and  triangulate position) and maybe a laser pointer for entertaining the cat.

#4  

Quote:

and maybe a laser pointer for entertaining the cat.
I have a Laser Diode mounted to the head/camera of my Roli for just this purpose.

Used this discussion for instructions for connecting it:  https://synthiam.com/Question/Laser-Pointer-7542

Bought 10 for $5 from Amazon.  https://smile.amazon.com/GeeBat-10pcs-Laser-Module-Lasers/dp/B01ITK4PEO

I would send you one for free since I have 8 extras (gave one away already), but the mailing cost from US to Canada is more than you would spend getting 10 from Amazon.

Alan

PRO
USA
#5  

Quote:

I wonder if other commercial offerings of this board will work? There are many other companies selling these.
I am wondering this as well. I just got back from my local frys and they sell a flavor of the MPU6050. Would this work with current ARC and code?

PRO
Canada
#6  

It should, but one thing you should note is that the MPU6050 needs pretty strong pull-up resistors on the SDA and SCL lines to communicate at any kind of distance. In the past I've had to replace the on-board 4.7kohm surface mount resistors with 330ohm ones.

PRO
USA
#7  

Thanks For the info Jer. I will test it out.

#8  

Jeremie,  Does EZ Robot still sell these I don't see them on your website?  Also can you use a standard MPU6050 board?

"It should, but one thing you should note is that the MPU6050 needs pretty strong pull-up resistors on the SDA and SCL lines to communicate at any kind of distance." What is any kind of distance?   Where would you add the the resistors on the standard MPU6050?

#9   — Edited

Quote:

strong pull-up resistors on the SDA and SCL lines
You would place separate pull up resistors from the SDA and SCL lines to the VCC Power In.

What size? The short and easy answer is that you want a resistor value on the order of 10k for the pull-up. A low resistor value is called a strong pull-up (more current flows), a high resistor value is called a weak pull-up (less current flows). You may have to play around with different values to get it right. I've always ended up using 10k though.

Quote:

What is any kind of distance?
I think he's saying any length of wire you have attached to the unit.

Quote:

Does EZ Robot still sell these I don't see them on your website? Also can you use a standard MPU6050 board?
It's been my experience that if it's not listed on their website that they have discontinued or stopped selling the part.  These boards sell dirt cheap on Amazon. You could probably buy a couple different brands and try them out. Return the ones that don't work or keep a back up.

Have FUN!!! It sounds like you are elbow deep in something very interesting.

#10  

@Dave,  Well I am trying to get into something interesting but the skill for the MPU6050 running on a EZB Arduino UNO firmware does not work or at least I can't get it to work for me.  Jeremie made I comment in that post I may want to use a EZB4 in my project so then I looked at this skill and the part they show being used with it is no longer for sale by EZ-Robot so this skill has not been updated with more current information.  I am working on trying to build a 4 foot tall walking robot and I wanted to try and use the Auto Position skill in ARC but I also need to be able to leverage a MPU 6050 in ARC also.

On the distance question above: the wire run would be about 15" tops.

It would be nice to know how this works in more detail but I guess it is another trial and error type of exercise.

#11  

I understand, trial and error is my middle name. Lol. Good luck I hope you find your results.Usually I have to try different things in different combinations before I am happy. Do you have an ezb You can start out with. Maybe you get it to work on that first?

#12  

Yep I do.  I need to strip it from another project to try it and see if I can make it work.

PRO
Canada
#13  

Hello @smiller29

This board above was prototyped but never sold. I believe I had to use pull-ups as strong as 330ohms on the SDA and SCL lines. You can use off the shelf MPU-6050s but you may have to replace the pull-ups that the board comes with.

#14  

Jeremie not sure what to parts to replace on a standard MPU 6050. Do you have a picture of what components on the board needs to be replaced.

User-inserted image

PRO
Canada
#15  

You’ll have to trace back the resistors that are connected to the SDA and SCL lines. It looks like they are the 2.2kohm (222) resistors in this case but you’ll need a ohmmeter to confirm.

#16  

Thanks guy but at my age I am not sure I can change those out LOL!  Eyes and hands not as good they’d use to be.

So now I am really thinking I am screwed.  Leaving me my only option doing it all with arduino’s and custom arduino code and not using ARC.   This was not my plan but it sounds like it is my only option.

PRO
Canada
#17  

Oh! My bad, sometimes I make assumptions about people who are DIYers. You could easily place resistors in parallel with the 2.2kohm resistors to drop the resistance and strengthen the pullup. No soldering required! They can even be through hole for that matter.

You simply place a 470ohm resistor between SDA and 3.3V pins and you will be putting it parallel with the 2.2kohm. Do the same for the SCL side.

#18  

Well I think I did this ok.   Jeremie question for you is there anyway to get another ezb4 case?  Not the power base.

User-inserted image

PRO
Canada
#19  

So if you’d like to 3D print one I believe the STL file is available for the top and bottom plastic pieces for the EZ-Bv4. Otherwise, you could send a message to ez-robot customer service to see how much it would be to send you some plastics.

#21  

Too bad you don't need the power base. I have like 5 sitting here empty I could just give you. A number of years ago I needed a new case for the EZB board set. I sent a request like Jeremie suggests and was able to get one right away. Hopefully they still have them available for you. Good luck!

#22   — Edited

Jeremie,   Thanks but I could not find them on the EZ Robot website.  Please don't take this the wrong way but that site needs a lot of work has lots of bad links and also old data.  Kind of looks like the your web master needs to be replaced LOL.

PRO
Canada
#23  

@smiller29 I’d have to have a look on the website myself but you’ll also find the STLs on Thingiverse (EZ-Robot).

If you’re looking for the injection molded plastics themselves they aren’t listed on the website, you’ll have to contact customer service directly through the website.

The EZ-Robot website was migrated over the last couple years and does still need some maintenance and corrections. In due time it will see improvements.

#24  

Jeremie, I meant the .stl files. I could not find them on the site.

#25  

@smiller29

Not sure what .stl files you are asking about but here are the ones I know about.

---Link---

#26  

Herr Ball,  Thanks for the link I found what I needed on this site thanks to you. I did not think to look here for those files. I could not find these items on the EZ Robot website.

PRO
Canada
#27   — Edited

Looks like we'll need to update our site to have more STL files.

Besides Thingiverse, I forgot that the files were still hosted here and I also forgot that you can get some of the STLs from within the ARC Robot design skill and in the build instructions.

User-inserted image

PRO
Canada
#28  

Several of my EZ-Robots are either in part or fully 3D printed.  I purchased a stack of the development kits a while ago for parts and 3D print the other pieces. When you have a bunch of kids building robots they will break things.

This is probably the best way to go to market. No one can afford $1000 for a robot but a handful of servos, a microcontroller and the 3D printer at school or library and you have a fully functional robot.

#29  

DJ,  above it says "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."  I would love to see the code you created for this can you provide a link to it, because I am not sure where to find EZ-Cloud?

#30  

You can find the EZ-Cloud in ARC. Look at the top menu bar on the main screen and you will see it right in the center. Once you get there there will be several ways to look at what's available. On the left menu there is a drop down menu showing everyone who has uploaded a project. Scroll down and find DJ's name and click on it. Depending what you have checked in the search box above there depends on what is returned in the right window. Good luck. It gets some getting used to and experimentation to find what you what.

#31  

Thanks Dave I was looking for it on the website.   Then I thought it may of been on the EZ Robot website but I could not find it there also.   Did not think to check ARC:(

#32  

I'm glad I was able to help. There's a ton of good examples and projects to download and look through. Doing this really helped me learn how ARC works and gave me ideas on how to write scripts and set up my project. Have fun!!

#33  

Question can we also add offsets to the MPU skill so it can be calibrated like you can in the Arduino code? See Below:

 // supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(17);
mpu.setYGyroOffset(-69);
mpu.setZGyroOffset(27);
mpu.setZAccelOffset(1551); // 1688 factory default for my test chip

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.

PRO
Synthiam
#34  

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.

#35  

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

PRO
Synthiam
#36   — Edited

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:)

#37  

@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?

PRO
Canada
#38  

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.

#39  

@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?

PRO
Canada
#40  

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).

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

Can anyone at Synthiam in the development team provide the details about the MPU6050 class being used in this service?  Are these values YAWPITCHROLL or QUATERNION or EULER or REALACCEL or WORLDACCEL?

PRO
Synthiam
#50   — Edited

You’re looking at the code that you pasted. There is no class. That is the class. It reads the values and assigns them to variables as you can see.

it appears from reading the code that there is 14 bytes read and they’re split into different variables that have names which explain what they are.

#51   — Edited

Thanks, DJ sorry for the stupid question.  This is just bringing back raw data from the MPU6050.