Jooseppi Luna
unread,Aug 20, 2015, 9:09:07 AM8/20/15You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hi everyone! I'm having some strange issues using MATLAB to send gcode to an Arduino to control a stepper motor. This is my code. I have comments in there to explain it.
%Open serial port to send commands to the Arduino
s = serial('COM12');
set(s,'BaudRate',115200);
fopen(s);
%Wait for grbl to initialize
pause(2)
%Output GCode.
for i = 1:20
fprintf(s,'G01 X%d F1000\n',40 * i);
fprintf(s,'G4 P2\n');
pause(5); %This makes things work?
end
fclose(s);
delete(s);
clear s;
The main issue with the code is that, if I loop without the pause(5) in the loop, the motor will loop at most 7 times before stopping. I have put a print statement that prints the value of i into the loop, and it does print the numbers 1-20, so the loop is not an issue. The weird thing is that, if I throw in a pause() command, the loop will run for longer depending how long a time I specify for the pause. Pause(5) is enough for me to run all twenty runs.
Any idea what is going on here?