How can I run 2 stepper motors simultaneously connected to an arduino Uno using Matlab?
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Rolfe Dlugy-Hegwer
le 12 Fév 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 commentaires
John
le 11 Nov 2014
Hello
I have an Arduino Uno and the Motor Shield V2 I'm able to control the two steppers with the speed and the rotation angle i want but not at the same time.The code i write at the MATLAB's M-File is this one:
% a=arduino('COM3');
a.stepperSpeed(1,10);
a.stepperSpeed(2,20);
a.stepperStep(1,'forward','single',48);
a.stepperStep(2,'forward','single',48);
The pde file that i upload the Arduino is the motor_V2.pde .
I tried to upload different pde but nothing happend.
Also I tried for Simulinks Support Package i read in another post, but the package is for MATLAB 2012 and I don't want run the motors from simulink.
Is there anyway way for run the motors simultaneously?
Thank you.
Mohamed Ammar
le 8 Avr 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
Communautés
Plus de réponses dans Power Electronics Control
Voir également
Catégories
En savoir plus sur Arduino Hardware dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!