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 the “Downloads” page…

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.


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


  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,

    • 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

      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.

      • Nick,

        Thank you so much for the input and help! I managed to get my problem solved about a week and a half ago. I have 5 BNO055 sensors I am reading, so formatting it in the proper loop structure in the IDE ended up being my issue. I really appreciate the response!

        Best Regards,

    • Hi Bjorn, sorry for the long delay! Didn’t realize I was getting comments on the wordpress site so this message went unseen until now. The github repo is very needed. Will make this a priority. Again sorry for the delay but very happy to hear there are others out there who would like to help.

  4. Hello Nick, I liked tou project very much and I want to build my own version, to monitor some waves here in Rio de Janeiro, but in order to do it I want to know wich eletronics architecture you sugest, since you’ve made lot of versions, and how you made to fix the buoy

    • Hi Pedro, are you still working on your wave buoy project, and if so how are things progressing? Sorry for the late reply. I did not know that comments were being sent to me in wordpress. Sorry for the delayed response. Please let me know how I can help.



Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s