loading

MPU9250 is one of the most advanced combined Accelerometer, Gyroscope and Compass small size sensors currently available. They have many advanced features, including low pass filtering, motion detection, and even a programmable specialized processor. Having nearly 130 registers however, with many settings, they are also very difficult to work with from code.

Couple of weeks ago GearBest were nice enough to donate a MPU9250 module to sponsor adding support for it in Visuino. It took 2 weeks of hard work, but at the end I not only had the support for MPU9250 implemented, but I also added Acceleration To Angle converter, Complementary(First and Second order), and Kalman filters that can be used with it to improve precision.

This is the first Instructable on the new MPU9250 support in Visuino, and it shows how easy it is to use it with Visuino. In the following Instructables I will show you how you can use the Acceleration To Angle converter, the Complementary and Kalman filters and get really good results from your sensor module.

Step 1: Components

  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One MPU9250 Sensor Module (in my case generously donated by GearBest)
  3. 4 Female-Female jumper wires

Step 2: Connect the MPU9250 Accelerometer Gyroscope Compass to Arduino

  1. Connect 5V VCC Power(Red wire), Ground(Black wire), SDA(Green wire), and SCL(Yellow wire), to the MPU9250 Module (Picture 1)
  2. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board (Picture 2)
  3. Connect the other end of the 5V VCC Power wire(Red wire) to the 5V power pin of the Arduino board (Picture 2)
  4. Connect the other end of the SDA wire(Green wire) to SDA/Analog pin 4 of the Arduino Nano board (Picture 2)
  5. Connect the other end of the SCL wire(Yellow wire) to SCL/Analog pin 5 of the Arduino Nano board (Picture 2)
  6. Picture 3 shows where are the Ground, 5V Power, SDA/Analog pin 4, and SCL/Analog pin 5, pins of the Arduino Nano

Step 3: Start Visuino, and Select the Arduino Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select Arduino Nano as shown in Picture 2

Step 4: In Visuino: Add and Connect MPU9250 Component

  1. Type "mpu" in the Filter box of the Component Toolbox then select the "Accelerometer Gyroscope Compass MPU9250 I2C" component (Picture 1), and drop it in the design area (Picture 2)
  2. Connect the "Out" pin of the AccelerometerGyroscopeCompass1 component to the to the "In" pin of the I2C channel of the Arduino component (Picture 3)

Step 5: In Visuino: Add and Connect Packet Component

To send all the channels data over serial port from Arduino we can use the Packet component to packet the channels together, and display them in the Scope and Gauges in Visuino:

  1. Type "pack" in the Filter box of the Component Toolbox then select the "Packet" component (Picture 1), and drop it in the design area
  2. Connect the "Out" output pin of the Packet1 component to the "In" input pin of the "Serial[ 0 ]" channel of the "Arduino"component (Picture 2)

Step 6: In Visuino: Add 7 Binary Analog Elements to the Packet Component and Specify Their Names

  1. Click on the "Tools" button of the Packet1 component (Picture 1)
  2. In the "Elements" editor select the “Binary Analog” element, and then click on the "+" button (Picture 2) to add Analog element
  3. In the Object Inspector set the "Name" property of the Analog Element to "Compass(X)" (Picture 3)
  4. In the "Elements" editor select the “Binary Analog” element on the right, and then click on the "+" button on the left to add another Analog element
  5. In the Object Inspector set the "Name" property of the new Analog Element to "Compass(Y)" (Picture 4)
  6. In the "Elements" editor select the “Binary Analog” element on the right, and then click on the "+" button on the left to add another Analog element
  7. In the Object Inspector set the "Name" property of the new Analog Element to "Compass(Z)" (Picture 5)
  8. Repeat the same steps to add 7 more Binary Analog elements named "Accelerometer(X)", "Accelerometer(Y)", "Accelerometer(Z)", "Gyroscope(X)", "Gyroscope(Y)", "Gyroscope(Z)" and "Thermometer" (Picture 6)

Step 7: In Visuino: Configure the Visualization of the Packet Element for the Thermometer

The Visuino by default can display the analog elements from the packet component in gauges. It is nice however to display the temperature in Thermometer. Visuino allows customization of the way the analog elements are displayed.

  1. In the Elements editor, select the last Analog element named "Thermometer" (Picture 1)
  2. In the Object Inspector select the "Instrument" property and click on the "Arrow Down" button next to its value (Picture 1)
  3. From the Drop Down box select "Thermometer" (Picture 2)
  4. In the Object Inspector expand the "Instrument" property, then the "Scale" sub-property (Picture 3)
  5. In the Object Inspector set the value of the "Auto" sub-property of the "Scale" to False (Picture 3) This will disable the auto scaling for the thermometer
  6. In the Object Inspector set the "Max" sub-property of the "Scale" to 100 (Picture 4) This will configure the thermometer to have a scale from 0 to 100

Step 8: In Visuino: Specify Unique Packet Header

To make sure that Visuino will find the starting point of the packet, we need to have a unique header. The Packet component uses special algorithm to ensure that the header marker does not appear in the data.

  1. Select the Packet1 component (Picture 1)
  2. In the Object Inspector expand the "Head Marker"property (Picture 1)
  3. In the Object Inspector click on the "..." button (Picture 1)
  4. In the Bytes editor type some numbers, as example 55 55 (Picture 2)
  5. Click on the OK button to confirm and close the editor

Step 9: In Visuino: Connect the MPU9250 Component to the Elements of the Packet Component

  1. Click in the "Out" box containing the pins of the "Compass" of the AccelerometerGyroscopeCompass1 component to start connecting all the Out pins at once (Picture 1)
  2. Move the mouse over the "In" pin of the "Elements.Compass(X)" element of the Packet1 component. The Visuino will automatically spread the wires so they will connect correctly to the rest of the pins (Picture 1)
  3. Click in the "Out" box containing the pins of the "Accelerometer" of the AccelerometerGyroscopeCompass1 component to start connecting all the Out pins at once (Picture 2)
  4. Move the mouse over the "In" pin of the "Elements.Accelerometer(X)" element of the Packet1 component. The Visuino will automatically spread the wires so they will connect correctly to the rest of the pins (Picture 2)
  5. Click in the "Out" box containing the pins of the "Gyroscope" of the AccelerometerGyroscopeCompass1 component to start connecting all the Out pins at once (Picture 3)
  6. Move the mouse over the "In" pin of the "Elements.Gyroscope(X)" element of the Packet1 component. The Visuino will automatically spread the wires so they will connect correctly to the rest of the pins (Picture 3)
  7. Connect the "Out" pin of the "Thermometer" of the AccelerometerGyroscopeCompass1 component to the "In" pin of the "Elements.Thermometer" input pin of the Packet1 component (Picture 4)

Step 10: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 11: And Play...

  1. In Visuino select the ComPort, and then click on the "Format:" drop down box, and select Packet1(Picture 1)
  2. Click on the "Connect" button(Picture 1)
  3. If you select the "Scope" tab, you will see the the Scope plotting the X,Y,Z values from the Accelerometer, Gyroscope, and Compass, as well as the Temperature over time(Picture 2)
  4. If you select the "Instruments" tab, you will see the Thermometer and the Gauges showing the same information (Picture 3)

You can see the connected and running MPU9250 Accelerometer, Gyroscope and Compass sensor on Picture 4.

Congratulations! You have created a MPU9250 Accelerometer, Gyroscope and Compass measuring project in Arduino, with Visual Instrumentation.

On Picture 5 you can see the complete Visuino diagram.

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com

<p>how can I use this to get roll, pitch and yaw?</p>
Add, and connect the &quot;Acceleration To Angle&quot; component ;-)
<p>Hey @boianM. Can you please give a detailed description of how to connect the &quot;Acceleration to Angle&quot; component in Visuino? That would be great help. Thanks!</p>
<p>Finally had a chance to make such Instructable:</p><p>https://www.instructables.com/id/Arduino-Nano-and-Visuino-Convert-Acceleration-to-A/</p>
<p>btw, I tried to install Visuino on my mac, via using wine. It was installed but the pop-up window to enter the license key wasn't working. clicking okay after entering the license key wasn't doing anything. </p><p>Any updates on when the mac version of the Visuino is going to be released? </p>
<p>great tutorial. Could you possibly let me know if there is any way to log or just get it on a sofware.serial ? </p>
Thank you! :-)<br>I have just released version 7_8_2_42 of Visuino which includes the option to log the serial :-) Enjoy!
<p>Wow, that was so quick.Thanks a lot. I have two more questions if you don't mind. </p><p>1- Do you know the sample rate of the visuino MPUs?</p><p>2- There is a significant between inconsistency betwen what visuino reports and what we read off of SparkFun_MPU-9250_Breakout_Arduino_Library. Would you feel comfortable looking into this issue? </p><p>We ended up writing our own code based on SparkFun_MPU-9250_Breakout_Arduino_Library to read the accelerometer data. It turned out when we graph the data, the accelerations in mg is quite different from what we read off of visuino's graphs. First, spakfun based code seems to have a higher sampling rate. Second, the accelerations are more alined with the datasheets of the devices we are testing. For example, the visuino was showing 16g while the sparked-fun code was reporting 8g. </p><p>Noted that we made sure that the data is not cut-off at 2g. </p>
<p>How can I make sensor fusion for MPU9250 and servo (rudder) control with PID? I would like to make a boat autopilot with a heading hold feature.</p>
<p>Visuino has a PID controller. You should be able to connect the signal from the MPU9250 through the PID to the Servo component in Visuino.</p>
<p>Love this one, simple yet very cool to play with.</p><p>Thanks Boian!</p>
<p>Cool! Thank you :-) Enjoy! Looks neat on the Breadboard too :-)</p>
Please help sir<br>Nano can b replaced by uno<br>With same A4 and A5 pins?
<p>It is easier with Uno. It has dedicated pins for SCL and SDA ;-) . However those pins are the same as A4 and A5 so yes you can use either the SCL/SDA pins or A4/5 on UNO. They will work.</p>
Please provide a GPS RX LCD based display tutorial if possible<br>Displaying lat log and speed
<p>Wish granted :-)<br>https://www.instructables.com/id/Arduino-Nano-Show-GPS-Location-on-I2C-2-X-16-LCD-D/</p>
Thanks alot bro<br>U rocks
<p>Will see what I can do ;-) Stay tuned...</p>
Ya I saw its pin configuration its same<br>Already performed d same with uno<br>Working perfectly fine.<br>
<p>$41 for the module from the link? Why not check aliexpress, found the same module for $5.50</p>
The module was donated by GearBest for the development. This is the reason for the link to there ;-)
<p>That is way cool.. Any news on a Mac OS version?</p>
<p>Working on it any time I get a gap between the adding of new modules... so much work that needs to be done thou :-( . Will happen I am sure...</p>
What is the difference between the mpu 6050 and the mpu9250 ?
<p>The main one is that mpu9250 has built in compass </p>
Thanks for your answer :)

About This Instructable

20,371views

42favorites

License:

More by BoianM:Assemble Kuman Wi-Fi Robot With Camera and Manipulator Arduino and Visuino: Long Distance Remote Light Sensor With RFM95W/RFM98W Makerfabs LoRa Shields  Arduino Nano and Visuino: Animate the Colors of RGB LED 
Add instructable to: