Home › Forums › Forums › Technical Support for BerryIMU › BerryIMU and Matlab
- This topic has 17 replies, 3 voices, and was last updated 4 years, 11 months ago by Sylvain.
- March 17, 2017 at 12:44 am #6171nightpoisonParticipant
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?March 17, 2017 at 2:02 am #6172nightpoisonParticipant
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!!April 17, 2018 at 2:35 am #7224SylvainParticipant
Hi nightpoison, do you have a clean code to share ?
I am interested in using the i2c protocole with an Arduino and the BerryIMU (probably later using raspbery Pi. Though the main code should remain the same.
- You must be logged in to reply to this topic.