Notifications
Clear all

controlling stepper motors with shift registers & Arduino

Page 1 / 7

Dryden
(@dryden)
Trusted Member
Joined: 4 weeks ago
Posts: 82
Topic starter  

I'm trying to control 6 28BYJ-48 stepper motors with drivers with an Arduino Uno... 

I can control 2 steppers with the Arduino using the Stepper library, that's pretty easy.

I can also use the ShiftRegister75HC595 library and turn on and off all the pins for LEDs. 

What I don't know how to do is convert the stepper library over for the shift register pins.

any advice or a better library would help!

 


Quote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@dryden

I don't expect you'll find any joy in using shift registers to control the steppers, I think that they'll be way too slow.

If you use the AccelStepper library then you get a number of benefits, not the least of which will be using (a bare minimum) only 2 Arduino pins per stepper driver. I've never used them with BYJ's though. What stepper controllers are you using ?


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 
Posted by: @will

@dryden

I don't expect you'll find any joy in using shift registers to control the steppers, I think that they'll be way too slow.

It appears that somebody has actually done that ... wow !

http://projectsfromtech.blogspot.com/2014/03/arduino-shift-register-stepper-motor.html


Dryden liked
ReplyQuote
Dryden
(@dryden)
Trusted Member
Joined: 4 weeks ago
Posts: 82
Topic starter  

@will 

That is exactly what I need! Thank you! I googled it a few times but couldn't find much on it. 


ReplyQuote
Dryden
(@dryden)
Trusted Member
Joined: 4 weeks ago
Posts: 82
Topic starter  

@will 

Although sadly, this post you shared was written in 2014 and I cant get it to work, so I am back to square one. 🙁


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@dryden 

Did you get error messages or was it just non-functioning ? It seems unlikely that any of the components would have changed in that time frame.

What stepper driver (if any) re you using ?


ReplyQuote
Dryden
(@dryden)
Trusted Member
Joined: 4 weeks ago
Posts: 82
Topic starter  

@will 

Non-functioning, I don't know enough about the code to know why it wasn't working.

 

I'm using the ULN-2003's that come with the steppers, although I never thought to look for Libraries on it... 

The firing order on these steppers is 1, 3 ,2, 4. So I'm starting to think if I was to shift out, 1, 0, 0, 0, then 0, 0, 1, 0. then 0, 1, 0, 0, then 0, 0, 0, 1. and then how do I write the code to have that loop over and over until asked to stop? although this will be monotonously long writing it out for 24 bits for every step in theory it should work.... I think....


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 
Posted by: @dryden

@will 

Non-functioning, I don't know enough about the code to know why it wasn't working.

 

I'm using the ULN-2003's that come with the steppers, although I never thought to look for Libraries on it... 

The firing order on these steppers is 1, 3 ,2, 4. So I'm starting to think if I was to shift out, 1, 0, 0, 0, then 0, 0, 1, 0. then 0, 1, 0, 0, then 0, 0, 0, 1. and then how do I write the code to have that loop over and over until asked to stop? although this will be monotonously long writing it out for 24 bits for every step in theory it should work.... I think....

I didn't read the article (just scanned it briefly)  but it seems to me that the author was using the bare ULN2003 chip, whereas I think you would have been using the driver, so the wiring may change and the code may change as well (to support the bare chip). Note - I didn't even look at the code.

Enacting any long, boring, repetitive series of actions is why we're using micro controllers and not keyboards. I think you'll have to pass along the series of pulses as you go. I don't know that a library would help you because you would need to interrupt them from sending out a long, boring ... to intercept and pass out the "step commands" to the SRs.

What you might do is isolate the stepping commands to a subroutine which might, for example take the stepper ID (i'e' which stepper is supposed to move), the direction (CW or CCW) and have that module keep track of which step cycle that particular stepper is currently at (e.g. a global uint8 array with each stepper represented at a particular index in the array).

When you called this module, it would check for a valid stepper ID and then check what cycle of the step that stepper is at and then advance (or backup) the current step (as per direction sent) and then cycle out the relevant bits for that stepper. These cycle bits could be stored and extracted as needed or be directly passed as code in the sketch.

This was only an example based on having no information about the rest of your sketch or requirements.

I'll check my junk drawers and see if I can find a BYJ and ULN driver. If I can find the stuff, I'll try to recreate the project with a driver instead of a bare chip. I'm warning you though, I won't be fast about it, even assuming I can find all the parts 🙂

 


Dryden liked
ReplyQuote
robotBuilder
(@robotbuilder)
Prominent Member
Joined: 2 years ago
Posts: 883
 

@dryden

Non-functioning, I don't know enough about the code to know why it wasn't working.

Have you viewed Bill's tutorial on shift registers?
https://dronebotworkshop.com/shift-registers/

On the old PC I used shift registers to pump data out of a Centronics port to create a many bit output.

I could probably solve your problem of controlling multiple stepper motors easily however I only have one simple stepper motor and controller which I bought to test code for someone else's project.  I would have to order say another seven stepper motors.  Usually I do this through a local store which is now in lock down due to a resurgence of the covid virus.

I don't use libraries unless I have to,  instead I prefer to code it all myself.

This is the stepper and controller I used.

2816 stepperAndController

With a robot arm you will want to move the end effector through a path in 3d space which means adjusting the speed of each stepper motor over time.

Then there is the issue of the mathematics of reverse kinematics....

 

 

This post was modified 4 weeks ago by robotBuilder

ReplyQuote
Dryden
(@dryden)
Trusted Member
Joined: 4 weeks ago
Posts: 82
Topic starter  

@will 

That would amazing if you do have the time to do that for me, because I kinda understand what you are saying, and it sounds like what I am trying to explain, but I don't know where to start in coding it that way.  I follow along in coding tutorials, and check out the examples in the libraries, but I'm struggling to understand how it all works still.


ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@robotbuilder 

I can't speak for @dryden, but I'd love to see a working example for even a single BYJ with shift registers. I always thought that the combination would be far too slow to make a practical system.

I haven't used BYJs for years because they took up too many Arduino pins, so I switched over to A4988 drivers and used the AccelStepper library so I could drive them with only two pins.


ReplyQuote
Dryden
(@dryden)
Trusted Member
Joined: 4 weeks ago
Posts: 82
Topic starter  

@robotbuilder 

Yes I watched that tutorial, I was also wondering if I could use the tutorials on XOD to help me out with this or if it will make any difference at all? 

That is the same stepper motors and board I am using, I really wouldn't feel right about you putting money out to help me with this. 

I don't have enough knowledge in coding but I agree I would like to code it all myself instead of using libraries. although what I dont understand with using the libraries is in the stepper library it asks you to set up which pins you are using, and in the ShiftRegister74HC595 library it tells you how to set single pins high use this command

for(int i = 0; i < 8, i++) {

sr.set(i, HIGH):

}

So how or could I code sr.set(0, 2, 1, 3) as my stepper pins? 


ReplyQuote
robotBuilder
(@robotbuilder)
Prominent Member
Joined: 2 years ago
Posts: 883
 

@will 

I haven't used BYJs for years because they took up too many Arduino pins, so I switched over to A4988 drivers and used the AccelStepper library so I could drive them with only two pins.

If I was building a robotic arm using steppers I would certainly use the A4988 drivers!

This tutorial explains acceleration and how to run 6 stepper motors.

 

 


Dryden liked
ReplyQuote
robotBuilder
(@robotbuilder)
Prominent Member
Joined: 2 years ago
Posts: 883
 

@dryden

Looked at Bill's tutorial on XOD and didn't like it. I am old school.
Libraries are ok in that they are usually professional implementations but it is nice to be able to understand it at a lower level.  No idea if the library would work if you are pumping data out using a shift register. Essentially each driver needs 4 bits (or 2 bits with the A4988 drivers). You would be extending the pin count of the Uno (I use the Mega) and would have to write your own bit patterns to transfer and latch per unit of time.

 

 

This post was modified 4 weeks ago by robotBuilder

ReplyQuote
Will
 Will
(@will)
Reputable Member
Joined: 3 months ago
Posts: 368
 

@robotbuilder 

Yes, using the MultiStepper library allows acceleration and synchronization of several motors as well.

I decided to design and make plotters of various types to force myself to learn about electronics, controls, reading SD cards, steppers and mechanical drive systems which I knew nothing about (I'm a mathematician by training). I've been using Accel- and MultiStepper ever since I discovered them 🙂


ReplyQuote
Page 1 / 7