[Complete script] Using matlab to control Makergear

General discussion topics
hanming
Posts: 9
Joined: Fri Jun 16, 2017 4:28 pm
Location: Philadelphia, PA

Re: Using matlab to control Makergear

Post by hanming » Fri Jul 21, 2017 3:06 pm

Ah, problem solved! Thanks to Josh's explanation of the gcode line number and checksum value, which can be omitted in all together. It seems that matlab has several ways of sending new line command, and this is the matlab code that worked.

Code: Select all

clear all
clc

arduino=serial('COM3','BaudRate',115200); % create serial communication object on port COM4
arduino.Terminator = {10, 13};
fopen(arduino); % initiate arduino communication
pause(5);
count = 0;
while arduino.BytesAvailable > 0
    echo = fscanf(arduino);
    disp(echo);
    count = count + 1;
end
fprintf(arduino,'G28..');
disp('home');
pause(5);
fprintf(arduino, 'G01 X100 Y100');
disp('move');
pause(5);
fclose(arduino); % end communication with arduino

User avatar
Tim
Posts: 1205
Joined: Thu Apr 10, 2014 2:19 pm
Location: Poolesville, Maryland
Contact:

Re: Using matlab to control Makergear

Post by Tim » Mon Jul 24, 2017 3:09 am

Hmm. I was trying various things using just straight-up fopen, fread, and fwrite, and just adding "\n\r" (characters 10 and 13) at the end of the string. I was using octave, not Matlab, and octave doesn't implement serial() except through the instrument-control package. According to what worked for you, that should have done something. But I didn't get a response to "G28". But what is the ".." in your "G28.." line?

hanming
Posts: 9
Joined: Fri Jun 16, 2017 4:28 pm
Location: Philadelphia, PA

Re: [Complete script] Using matlab to control Makergear

Post by hanming » Wed Jul 26, 2017 9:10 pm

I don't think the .. means anything. I get that from my serial spy, when repetier send each command. But everything works without it. I have my code updated in my first post.

Post Reply