Go Down

Topic: two stepper motors control problem (Read 97 times) previous topic - next topic

Rtma

Jul 02, 2016, 03:44 pm Last Edit: Jul 02, 2016, 03:52 pm by Rtma
Hello

I'm trying to control two 28BYJ-48 stepper motor with Arduino Uno. Controll code is listing below  .When I upload the code into Uno. Only one motor can rotate. And it rotates slowly. But When I remove the the code of previously moving motor. The other motor can rotate fastly. I guess there are something wrong in the code. Can anyone help me to fix it?  

Code: [Select]

//first motor
int A = 8;
int B = 9;
int C = 10;
int D = 11;

//second motor
int E = 4;
int F = 5;
int G = 6;
int H = 7;

int del=2; //delay time

void setup() {
   
 pinMode(A,OUTPUT);
 pinMode(B,OUTPUT);  
 pinMode(C,OUTPUT);
 pinMode(D,OUTPUT);

 
 pinMode(E,OUTPUT);
 pinMode(F,OUTPUT);  
 pinMode(G,OUTPUT);
 pinMode(H,OUTPUT);
 
}

//steps of the first motor
void step1()
{
 //S1
 digitalWrite(A,HIGH);
 digitalWrite(B,LOW);
 digitalWrite(C,LOW);
 digitalWrite(D,LOW);
 delay(del);
}

void step2()
{
 //S2
 digitalWrite(A,LOW);
 digitalWrite(B,HIGH);
 digitalWrite(C,LOW);
 digitalWrite(D,LOW);
 delay(del);
}

void step3()
{
  //S3
 digitalWrite(A,LOW);
 digitalWrite(B,LOW);
 digitalWrite(C,HIGH);
 digitalWrite(D,LOW);
 delay(del);  
}

void step4()
{
  //S4
 digitalWrite(A,LOW);
 digitalWrite(B,LOW);
 digitalWrite(C,LOW);
 digitalWrite(D,HIGH);
 delay(del);
}


//steps of the second motor
void step5()
{
  //S1
 digitalWrite(E,HIGH);
 digitalWrite(F,LOW);
 digitalWrite(G,LOW);
 digitalWrite(H,LOW);
 delay(del);  
}

void step6()
{
 digitalWrite(E,LOW);
 digitalWrite(F,HIGH);
 digitalWrite(G,LOW);
 digitalWrite(H,LOW);
 delay(del);
}

void step7()
{
 digitalWrite(E,LOW);
 digitalWrite(F,LOW);
 digitalWrite(G,HIGH);
 digitalWrite(H,LOW);
 delay(del);
}

void step8()
{
 digitalWrite(E,LOW);
 digitalWrite(F,LOW);
 digitalWrite(G,LOW);
 digitalWrite(H,HIGH);
 delay(del);  
}


void loop() {
 // put your main code here, to run repeatedly:
 
 //first motor rotate
 step4();
 step3();
 step2();
 step1();
 
 
 //second motor rotate
 step5();
 step6();
 step7();
 step8();  
 
}

MarkT

Use the AccelStepper library?   You can run several motors in pseudo-parallel very easily,
you just call run() method for each motor in loop () and don't ever delay().
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

rpt007

The motor as such is pretty slow as it comes with a 1:64 gear (reduction).
Means: you send 64x64 steps = 4096 steps to get ONE rev.

As the max steps/sec of Accelstepper library are 4000 - you won't get lucky with this library. You have to look for another lib or write your own code - still I think, you won't get too much speed due to the internal gear.

If you need higher speed  - there is no other way as to go with another stepper motor and no gear reduction!
Before you ask:
Did you really read and understand "How to use this forum"  -> http://forum.arduino.cc/index.php?topic=148996.0
AND:
Do you have already some solution or is a part of the problem sitting in front of the screen?  :)

MarkT

Its 4096 half-steps, and its only approximately 4096, not exactly.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy