Sensors, Electronics and Prototyping

Matlab Communication

Welcome to Redshift Labs Forums UM7 Product Support Matlab Communication

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
  • #758


    I want to read data from the UM7 from Matlab. I used the example code and just tried to run the init.m, this is what i get in Matlab2014:

    Undefined function or variable “got_temperature_data”.

    Error in DUT_callback (line 73)
    if got_temperature_data && got_gyro_data

    Error in instrcb (line 36)
    feval(val{1}, obj, eventStruct, val{2:end});

    Warning: The BytesAvailableFcn is being disabled. To enable the callback property
    either connect to the hardware with FOPEN or set the BytesAvailableFcn property.

    What can I do to make it work? Unfortunately I don’t have any experience in serial communication with Matlab yet. Thanks in advance!

    Manish Mittal

    I also have exactly the same query. Please reply as it is very necessary for my thesis work that I am doing.


    The Matlab script that can be downloaded from the site is a snippet designed to illustrate how to use serial port callbacks to read and parse data for the UM7, from within Matlab. You can delete the references to got_temperature_data and got_gyro_data.

    Basically, the serial callback function reads bytes in from the serial port and parses them. When a packet is received, you can check the packet type and address bytes to see if it is the data that you are interested in. If it is, you can log it, or set a flag (like got_temperature_data), or whatever you want to do with it.

    Manish Mittal

    Can you please write an example code to get the euler angel from the orientation sensor? It would be really helpful.

    Manish Mittal

    I got to communicate with UM6 using MATLAB. Can you please tell me the address for the Euler angle data packet?


    Sure, the Euler Angle data begins in register 112 (0x70). You can find that information in the datasheet, here:

    Manish Mittal

    Hi Caleb,

    I was able to get the Euler Angle Data from the sensor using the MATLAB example code written by you. Now I want to store it in a variable matrix so that I can use it for further calculations. I used the Userdata attribute of the callback. function object to store the data. I did something like:

    gyro_x = typecast( flipud(uint8(, ‘int16’ )/100;
    gyro_y = typecast( flipud(uint8(, ‘int16’ )/100;
    gyro_z = typecast( flipud(uint8(, ‘int16’ )/100;

    h1 = [gyro_x, gyro_y, gyro_z];
    h = [h; h1; h1]
    obj.Userdata = h;

    I thought that it would return an ever-increasing (number of rows will continuously increase storing the real time data) matrix with the gyro_x, gyro_y, gyro_z values. But the Userdata matrix has just one row which contains the latest values of the three variables. Its like its just updating the last row after each loop run. I am not sure if I am doing anything wrong. Can you please tell me know if there is anything wrong or if there is any other way to store the real time data from the callback function in the base workspace for later usage.

    Manish Mittal

    Actually it is just

    h = [h; h1]; (and not h = [h; h1; h1];)

    Please suggest.

    Daniel Piedrahita

    Hi Manish,

    You mentioned that you were able to get the Euler Angle Data from the sensor into Matlab. Would you mind sharing your code? I am working on a similar problem now. Any help would be much appreciated.


    Mehedi Hasan

    Hi Manish,
    can you please share the code??
    Here is my email-

    Petr Tecilla
    Participant my case the issue is there is no data being read so it gets stuck in the while loop while verifying. My arduino code successfully prints to the serial monitor so I think it’s fine.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘UM7 Product Support’ is closed to new topics and replies.