Notifications
Clear all

controlling stepper motors with shift registers & Arduino

103 Posts
5 Users
20 Likes
12.1 K Views
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@dryden

It really feels awesome to be able to talk about these things to someone, I don't know anybody that is interested in these things.

And I have never had anyone else I know interested in electronics at the hobby level.  I am entirely self taught from books and now from the internet.

 


   
Dryden reacted
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@will 

That's ok, I appreciate the help!

 


   
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@robotbuilder 

Thank you for that, I will give it a try!

I just tried running an example sketch to make sure my 2 dc motors were still working right and found that I am energizing the stepper drivers every time the motors move... I either have a wiring problem or maybe feed back because the wires are so close? I'm going to disconnect those motors while I try your code just to make sure I don't fry something. 

Just as a laughable side note, those dc motors barely had enough power to move the robot... The battery is pretty heavy lol but this is kind of an experiment, once I have the controls down I can upgrade to bigger motors and steppers fairly easy. 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@dryden

If you wire it correctly my software should work for you as you said I am using the same stepper motor and controller as you.

Probably worth drawing a proper circuit showing the components and connections and the problem might become clear with regards interference between the drive motors and the stepper motors.

Do your drive motors have their own power pack?

Although because you have a 3D printer you might like to print your robot base I would suggest a cheaper solution like a plastic box would do the job and in fact look better as you can put the lid on it and hide all that spaghetti wiring 🙂  Robots always look better with a shell and the innards are safe from children playing with them or something hooking up on the wires or struts.

The control of a robotic arm can become complex. There are simpler arrangements. Your 3d printer is essentially a 3 axis robotic arm.

 


   
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@robotbuilder 

 I have movement thanks to your code! although its jittery right now, I definitely have a wiring issue as my steppers are getting rather warm rather quick.

Im using a small bread board for power distribution. Right now I am powering the uno off the usb and the shiftsR are being powered from the 5v and grd from the uno, the steppers I have their power coming from the Small breadboard, the small breadboard is being powered from my benchtop power supply.... I powered it all off the batteries earlier with everything plugged in but was running into this same issue with things getting warm, so I detached everything and re-wired it to how it is now. 

The motors were connected to the small breadboard along with the steppers, the power comes from the battery (normally) goes through the buck boost converter and out to the small breadboard

I'm tired, my brain is mushy, I'm going to maybe take a day away from this project and clear my mind. 


   
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@robotbuilder 

just a quick question on that code, what does the stepper value change? is that steps? time? I'm trying to figure out how to set maximum amount of steps as its 1024 full steps for 180 deg sweep. 


   
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@robotbuilder 

Ok I figured out those values have something to do with what pins go high, now I need to figure out the math that gets the values I want for each.... I guess case.

 

 


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

@dryden 

You say that 180 degrees = 1024 steps

So 1 degree = 1024/180 steps app 5.6889 steps

So, to get an angle A (in degrees) in steps x

#steps x = 5.6889 * A;

To get angle A (in degrees) from #steps x

A = x/5.6889

But remember that @robotbuilders code doesn't yet store the current position (in either steps nor angle) of the stepper after the arm is moved. Also, note that there is no homing function yet which could reliably restore the steppers to a known location after startup.

So the formulae above will only calculate the #steps or angle for the current move, not the resulting step count or angle of the final position of the move.

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


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 
Posted by: @dryden

@robotbuilder 

Ok I figured out those values have something to do with what pins go high, now I need to figure out the math that gets the values I want for each.... I guess case.

You guessed right.  Instead of using the decimal notation you could use the binary notation to see the value of each bit.  I can explain binary numbers if you like or you might google them.

Binary notation in C++ is,

stepper2val = 0B100000000 // turn on pin 7  this is decimal 128

stepper2val = 0B110000000 // turn on pin 6 and pin 7 this is decimal 128 + 64

Each bit has a weight for conversion to decimal notation.

The code uses one function, moveStepper(int stepCount,int Direction), that allows you to move stepper motor, if wired up the same way I wired it up, a fixed number of steps left or right at a fixed speed.  To illustrate the use of that function the loop simply selects a random number of steps and a random direction (left/right) and moves the stepper motor accordingly at a fixed speed.

I don't use degrees it is still ok to divide the circumference of a circle into 1024 steps.

I was trying to keep the code simple but it is important you make the effort to really understand how it works to the extent you could program it yourself and modify it.  Robotics ultimately is about software which determines the behavior of the machine.

 


   
Dryden reacted
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@will 

Thank you, @robotbuilder made this code fairly easy for me to understand and now that I've played around with the code a little bit more I understand it better. 

With the OpenCV (from what I understand) what you do is put borders on each side of the frame of the video, then have your recognition output the location of the object that it recognizes, and if that object enters a border it can send a signal saying that the object entered that border, from there I want to take that output and call a command (top border = move up, bottom border = move down, left border = and so on) There is going to be more to it than that obviously, but that is how I understand it anyway. 

I just basically want to be able to tell it you can move a maximum number of steps in this direction and that direction, ells move DC motors. I do need to figure out homing still and I've thought about hall sensors, I also have 3 gyro/accel sensors I would like to figure them out to put in.. for now I'm just going to have to make sure my steppers are in a pre-set homed position every time it starts up and just count steps taken and have it do the math to figure out how many steps it is allowed to take before it reaches the end of its sweep. 

I feel like I can explain what I want to do, but I'm struggling to right it in code, I feel like I should go back to my Python tutorials just to learn the basics again. 

The one thing I am really struggling with are figuring out these stepper values... I tried a few experiments to figure them out but I don't quite understand them. 


   
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@robotbuilder 

Thank you again, Yes I am getting the hang of it! 

Ok, I kind of understand

Posted by: @robotbuilder

stepper2val = 0B100000000 // turn on pin 7  this is decimal 128

stepper2val = 0B110000000 // turn on pin 6 and pin 7 this is decimal 128 + 64

that is going Most Significant Bit First, if I go Lsbf, then the 1 would be on the far end to control pin 7?

So going Msbf the pin 7 is 128, pin 6 is 64, pin 5 is 32, 4 is 16, 3 is 8, 2 is 4, 1 is 2, and 0 is 1?

am I understanding that correctly?


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@dryden 

That is correct.  

For the other motor p16 (bit 0) is 1 if on,  pin1 is 2,  pin2 is 4 and pin 3 is decimal 8.

It depends how you wire it for you want to deliver the bit patterns required for IN1, IN2, IN3 and IN4 of the controller from the 74HC985 and I wired them in reverse so I didn't have to cross the physical wiring.

Ideally pin6 would have been connect to IN1 not IN4  and so on however it doesn't really matter as long as you understand what you are doing.

I can write code for moving two motors separately but can't test it myself as I only have one stepper motor.  I will get back to the vision part later.

 


   
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@robotbuilder 

I think I got it, so when I move to shift register #2, pin 1 should be 256? pin 2 on sh.R #2 would be 256 x 2 and so on? 


   
ReplyQuote
Dryden
(@dryden)
Member
Joined: 3 years ago
Posts: 77
Topic starter  

@robotbuilder 

That's working great on that sh.R, I think I got the hang of it! I have both steppers going, moving smooth like butter!


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@dryden 

Really? Because what you wrote didn't seem right to me.

Give me an hour and I will illustrate it better.

 


   
ReplyQuote
Page 3 / 7