archlinux with arduino and 3 step motors

Hallo
First of all I am useing archlinux and the mablab support package from http://www.mathworks.se/matlabcentral/fileexchange/32374 So for our university project we have to make a robotic arm which has to move en the 2D plane and rotate about it’s own axis - We are confined to by the university to do this with an arduino and step motors and they prefer we program it all in MATLAB - I am using a bipolar steppermotor controllor to control the stepmotors, individually it is working fine, but I can’t get them to run simultaneously and at this time I haven’t been able to figure out the code to use - the code i am useing now is:

 a=arduino('/dev/ttyACM0');
 a.pinMode(13,'output');%sted
 a.pinMode(12,'output');%Dir
 a.pinMode(8,'output');%step
 a.pinMode(7,'output');%Dir
step=1800; %1800 steps

for i=1:step

a.digitalWrite(13,1);

pause(0.001)%Pause is neassesary not to stall step motor

a.digitalWrite(13,0);

pause(0.001)

end

What I was thinking might work is

tic

while toc/30<1 %run for 30 seconds

step=1800; %1800 steps

for i=1:step

a.digitalWrite(13,1);

pause(0.001)%Pause is neassesary not to stall step motor

a.digitalWrite(13,0);

pause(0.001)

end

end

while toc/60<1 %run for 30 seconds

step=1800;

for i=1:step

a.digitalWrite(8,1);

pause(0.001)

a.digitalWrite(8,0);

pause(0.001)

end

end

But this is not working like I had hoped. Hope anyone has an idea that can help me :slight_smile:

tproulund:
this is not working like I had hoped.

I do not know what you had hoped for. I do not know what actually happened. Perhaps you can provide a little more description....

Now I can GUESS that the pin 13 you toggle up/down is the "step" pin to the controller. And another pin (12?) sets the direction. Your comment on the pause is partially correct - there is a maximum speed of the stepper, and the pause sends them slow enough.

Your 2nd program code does first a number of steps to one motor. Then another large number of steps to the other. Could you send a step pulse to both motors in the same loop, perhaps? (Well yes I know the answer, but you try it :slight_smile: ) And I presume (I still have to GUESS as you haven't described anything) that the first motor just keeps turning. When or where does "toc" change, which is what controls the duration of the first loop?

Oh yes, and please go back and edit the post to use code tags - it really helps.

Msquare:
do not know what you had hoped for. I do not know what actually happened. Perhaps you can provide a little more description....

Sorry not sure much more to write, I am an absolute newbie at arduino, the problem pretty much is that matlab steps on one motor and then the next and I want them to run simultaneously so that our robotic arm and do it's 3 axis movement in one run and not first move one arm, then the next and then rotate about it's own axis

Msquare:
Your 2nd program code does first a number of steps to one motor. Then another large number of steps to the other. Could you send a step pulse to both motors in the same loop, perhaps? (Well yes I know the answer, but you try it :slight_smile: ) And I presume (I still have to GUESS as you haven't described anything) that the first motor just keeps turning. When or where does "toc" change, which is what controls the duration of the first loop?

Okey yea so i played alittle more with it yesterday, and like you said, I made a code that pulses on the motors

a=arduino('/dev/ttyACM0');
 a.pinMode(2,'output'); %Dir motor 1
 a.pinMode(4,'output'); %Step motor 1
 a.pinMode(7,'output'); %Dir motor 2
 a.pinMode(8,'output'); %Step motor 2
 a.pinMode(13,'output'); % Step motor 3
 a.pinMode(12,'output'); %Step motor 3
step=1000; %number of steps
for i=1:step;
    if i>0;
        a.digitalWrite(4,1);
pause(0.001)%Pause is neassesary not to stall step motor
a.digitalWrite(4,0);
pause(0.001)
    end
    if i>0;
        a.digitalWrite(8,1);
pause(0.001)%Pause is neassesary not to stall step motor
a.digitalWrite(8,0);
pause(0.001)
    end
   if i>0;
        a.digitalWrite(13,1);
pause(0.001)%Pause is neassesary not to stall step motor
a.digitalWrite(13,0);
pause(0.001)
    end
end
end

This script sends a pulse to each motor, not simultaneously but one pulse to one motor and then the next and the next - which is fine since you cant "see" this unless you really slow down the pulses - but now I have problems with the motors stalling or driving really slow even with the 1 mili second pause, any way to avoid this? (hope my description is better this time)

So the script actually works great, the problem was finding the right amoungh of power on the breadboard with the motor controllers !

Good! What problems are left?