Matlab Support Package for Arduino Hardware Installation
Introduction
This post is about the MPU-9150 and Arduino and how to read data from information technology using from Simulink. The MPU-9150 is a 9-DOF inertial measurement unit (IMU) that you can get from Sparkfun. Information technology comes with a three-centrality accelerometer, 3-axis gyroscope, three-centrality magnetometer and Digital Motion Processor.
If you're wanting to embed lawmaking into an Arduino to grab sensor data from it, hither's a review on two methods to get the data in Simulink.
(This postal service will describe getting the accelerometer and gyro data simply.)
Downloading the Libraries, Connection and Exam in Arduino IDE
Download the MPU-9150 libraries from hither. Excerpt the I2Cdev and MPU6050 folders in the Firmware folder and paste them into your <Arduino Support Package base installation folder>\libraries. For me, this is: C:\MATLAB\SupportPackages\R2016a\arduino-1.6.one\libraries.
To connect the sensor with the Arduino, follow the schematic beneath. Make certain VCC is to iii.3V.
![mpu_arduino](https://dashboardproject.files.wordpress.com/2016/03/mpu_arduino1.png?w=616)
To test if the sensor is working / the validity of your connections, a quick way is to open up the Arduino IDE and upload the sketch "MPU6050_DMP6" and open the series monitor.
![sketch_test](https://dashboardproject.files.wordpress.com/2016/03/sketch_test.png?w=616)
Configuring in Simulink
Later verifying the connection, you tin starting time building the driver in MATLAB.
Method A: S-Office Architect
Ii things to do:
- Copy the required libraries to the same working binder equally your Simulink model.
- In MPU6050.cpp, expect for the methods that gets the accelerometer and gyro information.
![libraries.png](https://dashboardproject.files.wordpress.com/2016/03/libraries.png?w=616)
What goes on for the S-Function Builder?
Libraries Pane: Include all the .cpp files and the Arduino header file. Instantiate the MPU6050 object.
Discrete Update Pane: Write initialization lawmaking hither, like Wire.begin().
Outputs Pane: Phone call the methods that read the accelerometer and gyro values.
The methods:
- getAccelerationX()
- getAccelerationY()
- getAccelerationZ()
- getRotationX()
- getRotationY()
- getRotationZ()
Method B: Using I2C Read Blocks
There are I2C Read blocks in the Arduino Support Package Library. For each measurement type, insert an I2C Read block for information technology. For example, if you lot are measuring X-Axis, Y-Centrality and Z-Axis accelerometer data, you volition need iii I2C Read blocks.
In the I2C Read block, specify the slave address, which is 0x68 for the MPU-9150.
Tick the box that indicates "Read from I2C slave annals" and specify the register address for Ten-Axis, Y-Axis and Z-Axis read accelerometer data. For example, X-Axis accelerometer register address is 0x3B.
Refer to MPU6050.h for the full list of annals addresses.
Comparison of Methods
Here'due south my take on the comparison of the two methods discussed above.
Aspect | Due south Function Builder | I2C Block |
Coding | Needs more coding effort in C/C++ | No code to write |
Addresses | The C++ header files have all the addresses defined | Demand to refer to the datasheet register pin map or MPU6050.h header file for the annals address and plug in manually |
Corporeality of blocks | Few: But ane Southward Function builder block | Many I2C Read blocks |
Dependency files | Many .cpp and .h files | Zippo |
Conclusion | If your sensor is a simple one like the temperature sensor, then the I2C cake would be a straightforward winner, for its simplicity. However, if we are talking about a more complicated sensor that has many parameters (similar the MPU9150 which has Acceleration X,Y,Z, gyro, temperature etc), then the lines get blurred. Information technology would depend on the programmer's preference. |
Full Model
Here is a screenshot of my Simulink model and Telescopic information, when running in External Mode.
And of course, the side by side stride would be to filter the readings and perform calculations to excerpt meaningful data like yaw, pitch and gyre angles.
Update: 14 July 2016
Due to requests received, I have uploaded the driver for the MPU9150 which can be downloaded here.
0 Response to "Matlab Support Package for Arduino Hardware Installation"
Post a Comment