Dear All
I have a problem using my IMU and I need any help.
Please, Does any body know how to convert the ASCII readings from " sparkfun Atiomic 6DOF IMU " to a " numbers " in matlab ?
Below is my matlab prgram, you can try it to give me your advise:
close all
clear all
clc
instrreset % closing any open port
delete(instrfindall); % closing any open port
prompt = 'Enter a choice: ';
IMUport = serial(‘COM1’,‘BAUD’,115200); % Create serial object (PORT Dependent) 115200
fopen(IMUport) % Open the serial port for r/w
%prompt = 'Enter a character (q to exit): ';
fprintf(IMUport, ‘%s’, ’ ') % Write two blanks
%fprintf(IMUport, ‘%s’, ’ ')
for i=1:6
fprintf(fscanf(IMUport)) % Read Data back from IMU
while (IMUport.BytesAvailable)
fprintf(fscanf(IMUport)) % Read Data back from IMU
%myChar = input(prompt, ‘s’); % Get user input
end
userChoice = input(prompt, ‘s’); % Get user input
fprintf(IMUport, ‘%s’, userChoice) % Write first char of user input to serial port
end
for j=1:1
buf=fscanf(IMUport); % Read Data back from IMU
j=max(size(buf)) ;
k=1 ;
a = fread(IMUport);
while(buf(k)~=‘A’)
if k==j break ;
end
k=k+1 ;
end
end
% m=1 ;
% for n=k:4:j-4
% data_array(m)=str2num([buf(n+2) buf(n+3) buf(n+4) buf(n+5)]);
% m=m+1 ;
% end
% count = data_array(1)
%
%
% get acceleration
% accx = data_array(2)
%
%
% accy = data_array(3)
%
% accz = data_array(4)
%
%
% %pitch
% pitch = data_array(5)
%
%
% %roll
% roll = data_array(6)
%
%
% %yaw
% yaw = data_array(7)
% ============================
% Divide the buff values on 16384 to have the real values between -1 and 1.
% yaw = buf(30:32)
% pitch = buf(26:28)
% roll = buf(22:24)
% z_acc = buf(18:20)
% y_acc = buf(14:16)
% x_acc = buf(10:12)
% ============================
% pause
fclose(IMUport); % Close the serial port
delete(IMUport); % Delete the serial object
delete(instrfind);
Appreciating any help.
Thanks in advance
Anas