MATLAB Answers

How can I run 2 stepper motors simultaneously connected to an arduino Uno using Matlab?

56 views (last 30 days)
Emmin
Emmin on 18 Dec 2012
Commented: Mohamed Ammar on 8 Apr 2019
Hi all,
I am using a motor shield with the arduino Uno.
I want to be able to run 2 stepper motors simultaneously.
This is a code that runs the 2 motors, but not simultaneously, as in, for motor 2 to start, it has to wait for motor 1 to stop.
I have tried to use 'parfor' loops instead of 'for' loops, that didn't do the trick.
I have tried uploading an edited version of the srv.pde to integrate the I2C and AccelStepper libraries, but I'm not getting a simultaneous movement either...
I added to the srv.pde:
#include <Wire.h>
#include <AccelStepper.h>
and to the void loop (), I added:
Wire.beginTransmission (100);
and uploaded that as to the master arduino.
and uploaded to the slave arduino:
#include <Wire.h>
void setup()
{
Wire.begin(100);
Wire.onReceive(receiveEvent);
}
void loop()
{}
void receiveEvent( int howMany)
{
while (Wire.available())
{}}
I need help modifying the srv.pde so that when I upload it, I would be able to run the stepper motors simultaneously. Or another way, without having to modify the srv.pde file, to be able to run the motors simultaneously...
Thank you.
[Merged information from duplicate Question]
Hi, I have 2 arduinos, 2 motor shields, and 2 stepper motors. I want the 2 motors to run simultaneously, when I connect the 2 steppers to one arduino, the motors do not run at the same time. For example, in a for loop like this, motor 1 will run, stop, then moto 2 will run, stop.
for k=1:3;
a.stepperStep(1,'forward','double',200);
a.stepperStep(2,'forward','double',200);
end
The same issue occurs if I have 2 arduinos connected. For example, the for loop would be like this:
for k=1:3;
a.stepperStep(1,'forward','double',200);
b.stepperStep(1,'forward','double',200);
end
with "b." representing a different arduino than the "a."
Is there a way to make the 2 motors run at the same time?
Thank you.
  3 Comments

Sign in to comment.

Answers (1)

Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer on 12 Feb 2013
If you install the Simulink Support Package for Arduino Hardware, check out the "Drive with PID Control" tutorial example with its arduinomega2560_drive_openloop.mdl model.
To add this capability, enter "targetinstaller" in the MATLAB Command Window. Then follow the instructions in Support Package Installer.
  2 Comments
Mohamed Ammar
Mohamed Ammar on 8 Apr 2019
im using two stepper motopr with a motor sheild l293 d, i couldnt able to run two stepper mpotor at the same time.. help me out

Sign in to comment.

Communities

More Answers in the  Power Electronics Control

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!