Hi, Welcome to Arduino tutorial form Robojax. In this video we are going
to see how we can use this MPU 9250 accelerometer gyroscope and magnetometer
all in one you can get the code for this project by clicking in the link in the
description below which will take you to www.robojax.com/learn/arduino
let's get started with this
My Name is Ahmad Shamshiri and I am presenting this tutorial from Canada.
This Tutorial is presented by Ahmad Shamshiri from Canada
this device has accelerometer magnetometer and gyroscope. The gyroscope
built in this chip will give you the orientation from the reference point as
soon as you turn it on at that point or maybe you can put your own offset and
from that point it will give you the direction in terms of Y X and Z. And
also to give you the acceleration from that point when the device accelerates
left in terms of X Y and Z. it can give you that. so you will know the speed or
acceleration of an object at any moment any device that this is installed.
also it has a magnetometer which means it can give you and at any moment it can
give you the magnetic field around this or the magnetic field of Earth and from
that you can use it as a compass as well on top of accelerometer and gyroscope we
have magnetometer here so that makes it very attractive for drone application
and for drone application and other devices that need to have independent reference with a magnetic
field of Earth so that is very useful because the accelerometer and gyroscope
has a reference point so when it starts from the certain point from that point
it knows how much it has moved in any direction and it will not
understand the direction North, South, East and West.. In case if the
GPS signal is lost and magnetometer can be used to find approximate direction
this is used in phones, tablets and many other devices that have compass built-in
Hardware Explained
it will come usually with this type of male-to-male header so we have to attach
it either from this site or on to this side depending on how you want to use it
I'm gonna solder it from this side because this side should be up for me so
I can understand better XY and Z, but doesn't matter this is the frame
synchronization recommended that if you're not using it this will be
connected to the ground then and NCS the chip selection and spi
mode. this is interrupt if you're using interrupts to control or interrupt the
process make the device awake or do something and then this is a ADO address
selection for the I2C. EDA and ECL both are
external data and clock if you're using it to sync at the external clock.
this is original SDA and SCL that we will use. And then grounded VCC. The module is
26 millimeters 26.1 in terms of length, and the Width is
15.5mm millimeter and the depth is 2.6mm millimeters. This
is Y this is X, Z is away from this surface and for this is for acceleration
and gyroscope and for the compass Y and X is fine and just for Z the positive
is down so Z goes down but for the acceleration and gyroscope Z is up so
I have soldered now the pin header here. I'm gonna connect my wires from the top.
Now let's have a look at the data sheet for MPU9250. Here
These are dimensions about the scale and range for example for the
acceleration for gyroscope this is you can set these values degrees per second
for acceleration you can set + - 2 4 8 or even 16 G or maybe follow for the
magnetometer you can go out to plus/minus 4800 micro Tesla an operating
temperature is from minus 40 to 80 and of written voltage that they have
mentioned is 2.4 to 3.6V but because we are using using this PCB module it has
internal regulators or 3.3V so we can connect it to 5V. chip and I
found the datasheet for it so this is the regulator the middle one 3.3V is
a ground input is pin 1 so that middle one is the ground and that is connected
to input and this is the output. I've connected it now to 5 volts to show you I
hope I'm not shortening it because this is very tight I'm connecting it to the
first one and you're reading 5 volts now on this side this is the 3.3 volts
output so you don't have to worry just connected to 5 volts and I work fine. and
again here are the values for gyroscope these are the values degree per second
it can show you at that speed and and the gyroscope current is 3.2 mA
and in sleep mode is 8 micro ampere and then for accelerometer these are the
values that I mentioned and then 8.4 micro amperes is when 0.98 Hertz this is
around 1 Hertz and it increases significantly not
to 19.8 microampere at 31 Hertz which in the case that you need faster data
acquisition. But the normal operation is 450 micro ampere and when you go to
sleep would that's 8 micro ampere and here are the data form magnetometer and
they mention about some other additional features. We can use I2C or SPI this
video is concerned that I2C and you can do SPI it the same way that's
not a problem. you can see Sleep Mode all of them will be off a thermometer
gyroscope and standby mode and you can see all of the combination you just
select different mode and that will act accordingly and here are the orientation
of the device the dots are the corners so the dot is at this corner when you
see this yellow capacitor the dot is at that corner and a based on that Yis
this way and then X is this way and Z is up this is for accelerometer and
gyroscope and for compass this Y is this way X is that way and and Z is down
from this from this page down these are the pins
starting from pin one which there will be a dot and it goes like that many of
these are not connected not connected and these are the labels not connected
so many of the not use those that have been used I've been explained
here when they use the chip as a piece as a module PCB then many of the pins
have been labeled definitely for example
AUX CL and AUX DAV labeled as easier and EDA which is external here it
says auxilary VD D IO and VD D they have been internally connected
because we have a voltage regulator and then SCL and SDA will be used for
I2C these two and if you are using
it al SPI they will be called SCL and SDA and then frame synchronization is
the same does have however have been used with capital N in CS chap selection
this is for SPI mood then you will see interrupt pin and the rest are not
displayed for example results result you will not see those out on module
Wiring Explained
now let me explain the wiring. I've used only these four wires so VCC from here
VCC is connected to 5 volt and because there's other regulator so you don't
have to connect it 3.3 volts and then ground GND is connected to the ground this
gray and then we have SDA and SCL. SDA connected to A4 and SCL the blue one
is connected to A5 some Arduino have hair is there a CL which you can connect
it directly. If you are using other other boards other than or the window so far
Arduino as I mentioned to use A4 and A5. A4 for SDA . On Arduino Omega for
SDA use pin 20 and SCL pin 21 Leonardo use pin 2 & 3. And for Arduino Due use these.
When I run the I2C scanners this is how it shows the address which
is 68 that's a hex 0x68 which is hex value. For the address and seed
address shows us 68 and now if I connect this ADO pin forth pin from the right
if I connect this to 5 volts pay attention then this becomes 69
so now we'll change to 69. If I disconnect this again it become 68 so in
case if you need different address you just connect this pin ADO to 5 volts
or connected to HIGH and address will change I will also provide the link for I2C Scanner
this when you visit the code page I will provide you the link for library
which has been downloaded from this page and then you will just come here
download it just download it from here extract it and put it inside the library
also I'll provide you a link directly from our website www.Robojax.com if
this page moves or changes but there is there are a lot of good explanation and
details for through the collaboration for acceleration and you can use this
one IMU.calibrateAccel() and the
result will be here and then you can test that F status is equal true or
false and then proceed with something and once you installed the library, go to
file->examples and then you will see MPU 9250 there are so many of their search
like I would not go through a lot but I'll try to see how much I can go let's
go for the basic one when you click on the basic this is the one that I've
changed a little to format this properly other than that I have not changed it so
this is the header line ensures that if the Serial.begin()
working the program will stop here after that in MPU.begin() that starts the
communication and I status which it will be true to proceed otherwise it
will stay here. So here we check if status is smaller than zero then it's an
elevation and successfully you see this text and this text and this and then
while(1) will be here which means stay forever in this line. After that inside the loop we
are saying it read sensor so this will read the value this is just a text and
this is a the acceleration meter per second will be
printed here this line that the first line is let me just stop it
this line is the acceleration this is the text XY and Z and then there's a tab
\T mean tab so that's the space for the tab and acceleration Y and then
it shows this will give you the acceleration meter per second and Y that
6 means shows up to 6 decimal place and after that does that so this is for
acceleration I put another space here and this is for gyroscope radian per
second so this shows here in one line and after that this is the compass X, Y and Z.
up to here and let me also add a space and this is for temperature and I've
changed it to 200 you can make it hundred or whatever speed you want and
after this the loop continues like that. Now let's open another one the
advanced example
only difference between the basic and the advanced one is that you can set a
acceleration range plus minus up to each G and then you can set the gyro range
degree per second plus minus 500 and here we have digital low-pass filter
bandwidth of up to 20 Hertz you can set different values and here the signal
data rate also can be set. Other than that the section is exactly the same as
the other sketch which will print all these value that I just explained
Demonstration
and here is a demonstration of this this is just fluctuating very quickly now it
shows as you can see here the acceleration is zero zero and except on the
Z Direction we have this minus nine that's an offset so you can see that if
I move it up and down it shows our acceleration and if I keep it still so
that is X and this is Y you can see it's changing otherwise if I hold it you will
get almost the same value and this is a gyroscope so this will give the
orientation in terms of X and this is y and that's X when I change it and this
is the Z and this is the magnetic orientation this is a compass and the
temperature is shown here at 25 degrees Celsius. Thank you for watching the
fourth introduction to this MPU 9250 a Accelerometer, gyroscope and three axis
compass. Please make sure to subscribe so you can get updates of my upcoming
videos if you have any question or comment please post it in the comment
section below I try to answer and reply
Feb 20, 2020 English Translation Completed