Matlab + IMU example

Here is a quick youtube video to demonstrate the code that I have been using to stream accelerometer data to matlab. The basic structure of the code is all referenced from the MatlabArduino youtube videos. There are several videos that explain how it all works and is a great reference.

Note, I am using the Adafruit BNO055 IMU sensor to capture acceleration data, so you may need to adjust this accordingly for you setup. Also, the communication protocol is slightly different if you are using an Xbee or just the arduino for serial communication. Again, see the MatlabArduino videos for better instructions. My matlab and arduino code can be found at the below link.

Download source code from example here…

It is still a work in progress (no disclaimer about the quality or performance of the code) but just wanted to share in case anyone was interested. I’m wrapping up a Masters in mechanical engineering over the next month, so once that is done I will try to get this up onto Github sometime in the summer.

Advertisements

10 thoughts on “Matlab + IMU example

  1. Hey Nick ! I am using the same sensor to try to get orientation data, but your source code link is not working. Any way I can get redirected to it ?

  2. Hi Nick, I live in Africa and I’m really interested in finding cost effective (cheap) ways of giving our local mariners access to reliable information about wind, waves and sea temp. Have you made any progress on this project and would you be interested in working on it further to make something that will work in the 3rd world?

    • Hi Kevin,

      Yes, I’ve still been working on the buoy project. Made quite a bit of process over the last six months. Working on several posts that I would like to get onto the site soon. What part of Africa are you living in? Sounds like a great project – I’ll send you an email to follow up.

      Nick-

  3. Hi Nick,

    Wonderful work on your buoy project! I am currently working on a senior design project for my undergraduate ME degree that utilizes multiple BNO055 sensors and an arduino. I have run into some difficulty in setting up the communications between the sensor/arduino and MATLAB. I am trying to input sensor orientation data and have not had much luck with formatting it properly in the arduino IDE. I was just curious how you formatted the arduino code to allow the three separate accelerometer values to be recognized. I need to utilize them as float or double type variables because I then need to pass them through rotation/transformation matrices in MATLAB. Any advice and help is greatly appreciated!

    Best Regards,
    Ian

    • Hi Ian,

      Yes I had some difficulty with this step also. Are you using the Adafruit library to read the BNO055? There are a few things to consider depending on how fast you need to read the sensor and send data over serial. The most easy way to send data over serial is just Serial.print(#value). The most efficient way to send data over serial is to convert your BNO055 float values into byte format (8 bits to 1 byte) and transmit pairs of signed bytes over serial to Matlab, then in matlab read the pairs of signed bytes and convert those back to floats. Matlab has two command for reading serial data, one is for charecters the other is for bytes so make sure you use the correct function! fscan vs fread

      https://www.mathworks.com/help/matlab/ref/serial.fread.html
      https://www.mathworks.com/help/matlab/ref/serial.fscanf.html

      In Matlab you could compile two arrays of byte values and convert them to floats once you are done reading the sensor. For example, a situation might be the following: turn on the sensor, gather data for 5 minutes and stream over serial to Matlab, stop reading sensor data, and finally convert bytes to floats in matlab.

      This is the most efficient way ( I think!?) because if you want to send floats over serial, arduino must first convert the float values from the sensor into a string and send over ASCII characters one by one. So the value -120.00 would actually represent 7 bytes: -, 1, 2, 0, ., 0, 0. This will take more time to send over as compared to the two bytes I mentioned above. Hope that helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s