Notifications
Clear all

CNCshield with A2988 drive and modified 28BYJ-48 motors

3 Posts
2 Users
1 Likes
512 Views
(@watho60)
Member
Joined: 1 year ago
Posts: 5
Topic starter  

Hi Guys

First post so please be gentle no electronic wizard here

I'm having a play with these components and had 2 of the 3 motors working then added a third to the mix and still 2 out of 3 ? thinking I may have over headed things I left it for the day, I have now been playing again today and have nothing code seems to be loading but all I have is a pulse on the motor.

I have modified the motors and adjusted the pot on the A2988's to .78v and using a power supply for 5.14volts to the shield.

This is the code I'm running, I did have a 3rd motor coded but removed it to try and fault find.

I did copy the code from a few places as I couldn't find exactly what I wanted but it was working 

 

#include <Stepper.h>

const int dirXPin = 5;  // Direction
const int turnXPin = 2;
const int dirYPin = 6;  // Direction
const int dragYPin = 3;

// Motor steps per rotation
const int STEPS_PER_REV = 2048;
 
void setup() {
  
  // Setup the pins as Outputs
  pinMode(turnXPin,OUTPUT); 
  pinMode(dirXPin,OUTPUT);
  pinMode(dirYPin,OUTPUT);
  pinMode(dragYPin,OUTPUT);
  }
void loop() {
  
  // Set motor direction clockwise
  digitalWrite(dirXPin,HIGH); 
  digitalWrite(dirYPin,HIGH);
  
  // Spin motor one rotation slowly
  for(int x = 0; x < STEPS_PER_REV; x++) {
    
    digitalWrite(turnXPin,HIGH); 
    delayMicroseconds(1300); 
    digitalWrite(turnXPin,LOW); 
    delayMicroseconds(1300);

    for(int x = 0; x < STEPS_PER_REV; x++);{
  }
    digitalWrite(dragYPin,HIGH); 
    delayMicroseconds(2); 
    digitalWrite(dragYPin,LOW); 
    delayMicroseconds(2);
  
  delay(1000);
  } 
  // Set motor direction counterclockwise
  digitalWrite(dirXPin,LOW);
  digitalWrite(dirYPin,LOW);
  
  // Spin motor two rotations quickly
  for(int x = 0; x < (STEPS_PER_REV * 2); x++) {
    digitalWrite(turnXPin,HIGH);
    delayMicroseconds(1000);
    digitalWrite(turnXPin,LOW);
    delayMicroseconds(1000);
     
    digitalWrite(dragYPin,HIGH); 
    delayMicroseconds(1000); 
    digitalWrite(dragYPin,LOW); 
    delayMicroseconds(1000);
  }
  // Pause for one second
  delay(1000);
}

Thanks for any help you can give and please keep it simple if you can

Cheers Mark


   
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2531
 

@watho60

I couldn't find anything on A2988 drivers, did you maybe mean A4988 ?

If you're going to be using multiple steppers, I'd suggest that you use the AccelStepper library for your motor controls and use the MultiStepper library associated with it. MultiStepper will allow you to create several stepper objects and then control them such that you give it an array of step counts and MultiStepper will move all 3 in proportionate speed so that they all end up at their target locations at the same time.

Note that your stepper motors are more often used with something like a ULN2003 stepper driver.

Be sure that each of your stepper drivers has one of its GND connections back to the Arduino's GND.

Anything seems possible when you don't know what you're talking about.


   
WATHO60 reacted
ReplyQuote
(@watho60)
Member
Joined: 1 year ago
Posts: 5
Topic starter  

Hi Will

Thank you so much for the advice, sorry you are right about the No on the driver ( there are so many No's LOL) 

I will give that a go tomorrow and try to write a program for the Accelstepper libary,

the reason I went with the A4988 I could have 3 motors runing at the same time

As I thought I could only run 2 drivers( using the ULN2003) with the UNO and had problems trying to get 2 motors to turn at once using the stepper.h libary ( can it be done ? )

I was wondering if I had stuffed the shield or a driver when everything stopped as I have no way of testing the components

Anyway still a lot to learn thanks again for your advice

Cheers Mark  


   
ReplyQuote