hello and good day to all the experts and visitors of matlab,
i am a mechanical student and now im facing problem trying to interface matlab and arduino..
my project is to connect and run a two-link robot arm..by attaching a potentiometer at each of the motor shaft, i am required to obtain the data from the potentiometer to know the rotation of my motor shaft..but i need to use arduino to get the data then transfer the data to matlab and plot the graph..
now i have successfully acquire the data from arduino to matlab by manually rotating the potentiometer myself and not by the motor.. my stepper motors operate by using MATLAB GUI so since i have to operate my motor to move the potentiometer i cant open another file at the same time to acquire the data from potentiometer.. the problem is how do i acquire the data from arduino to matlab by operating my stepper motor at the same time?..i wish to acquire the real result of my potentiometer while attaching to my moving stepper motor simultaneously..how do i do that?..do i need to combine both the files together?? thanks again for your information^^
the code i put in my matlab is:
function data_pushbutton1_Callback(hObject, eventdata, handles)
try
s = serial('COM7');
set(s,'BaudRate', 9600);
set(s,'DataBits', 8);
set(s,'StopBits', 1);
fopen(s);
s.ReadAsyncMode = 'continuous';
numberOfDatas = 200;
data = zeros(1, numberOfDatas);
i = 1;
figure(1);
hold on;
title('Incomming Data from External Device');
xlabel('Data Number');
ylabel('Analog Voltage (0-1023)');
readasync(s);
while(i<=numberOfDatas)
data(i) = fscanf(s, '%d');
figure(1);
plot(i, data(i), 'm*');
if(i>10)
xlim([i-10 i]);
set(gca,'xtick',[i-10 i-9 i-8 i-7 i-6 i-5 i-4 i-3 i-2 i-1 i])
end
drawnow;
i=i+1;
end
pause(3);
return;
catch
stopasync(s);
fclose(s);
fprintf(1, 'Sorry, you"re going to have to close out of Matlab to close the serial port\n');
return
end
0 Comments
Sign in to comment.