BerryIMU and Matlab

Forums Technical Support for BerryIMU BerryIMU and Matlab

This topic contains 16 replies, has 2 voices, and was last updated by  nightpoison 1 week, 2 days ago.

Viewing 2 posts - 16 through 17 (of 17 total)
  • Author
  • #6171


    so that section of my code has changed. as you mentioned before I would be getting 1 byte of information from the high low, then when combined its a 2 byte signed. so what I ended up doing is first the OR operation, then converted into a signed 16 bit , then did the shifting.

    acc_combined = bitor(acc_low, acc_high);
    acc_combined = int16(acc_combined);
    acc_combined = bitshift(acc_combined, 8);

    what your saying is I need to do this in one line? I’m not sure if I can do that. I wasn’t able to shift by 8 bits before as matlab defaults to unsigned 8 bit precision. When I shifted by 8 it would just zero out the value. I can’t find any information on casting to signed 16. Ill need to look into that.

    It looks like, from this:

    gyr_combined = bitor(gyr_low, bitshift(gyr_high, 8));

    I’m only shifting the high value by 8 bits, is that correct?




    Thanks for the spread sheet, so based on the spread sheet I am not getting all the correct data results for each of the processes.

    here is the solution I’m using.

    function [ acc_combined ] = readACCx(a)

    acc_low = readRegister(a, hex2dec(’28’));
    acc_high = readRegister(a, hex2dec(’29’));

    acc_low = int16(acc_low);
    acc_high = int16(acc_high);

    acc_combined = bitor(acc_low, bitshift(acc_high, 8));

    fprintf(‘ACCx low: %8.2f high: %8.2f pre-combined: %8.2f post-combined: ‘, acc_low, acc_high, acc_combined);

    if acc_combined >= 32768
    acc_combined = acc_combined – 65536;



    once again thank you for your help. I’m now going to run the entire script and verify that I’m getting the correct pitch and roll. As that’s ultimately the data I need for my project. Thank you again!!

Viewing 2 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic.

Blip, blop, bloop…