Notifications
Clear all

controlling stepper motors with shift registers & Arduino

103 Posts
5 Users
20 Likes
12.2 K Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@robotbuilder 

it might be easier to implement your struct as a class. That way the code for various calculations can be embedded in the object, thereby simplifying the code for the rest of the project.

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


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

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

@robotbuilder 

I think I understand what you are saying in that code...

void moveSteppers(){
  currentMillis = micros();
  if (currentMillis - lastTime >=1000 then {
    for (int x = 0;x < 5; x++) {  // cycle through each stepper
        if (stepper[x].stepCount > 0) { // check if needs another pulse
            pulseStepper(x);
        end if
    }
    time = time + micros()-lastTime;
    lastTime = micros();
  }
}

So what we are doing is adding to 

moveStepper1(stepsCount,Direction);

so now it would be 

moveStepper1(steppernumber,stepsCount,Direction);


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 
Posted by: @dryden

@robotbuilder 

I think I understand what you are saying in that code...

void moveSteppers(){
  currentMillis = micros();
  if (currentMillis - lastTime >=1000 then {
    for (int x = 0;x < 5; x++) {  // cycle through each stepper
        if (stepper[x].stepCount > 0) { // check if needs another pulse
            pulseStepper(x);
        end if
    }
    time = time + micros()-lastTime;
    lastTime = micros();
  }
}

So what we are doing is adding to 

moveStepper1(stepsCount,Direction);

so now it would be 

moveStepper1(steppernumber,stepsCount,Direction);

In the for statement, that x<5 should be x<6 to catch the 6th stepper as well.

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


   
Dryden reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 

@dryden
What does the statement, stepper1val = 1,0,0; do?
It doesn't compile for me. How can you assign 3 values to a single variable?
I will work some more on it today and try and work it out exactly rather than having long winded exchanges on vague ideas.

I notice you have used different pin numbers.  That is not a problem but have you connected the stepper motor controller to the shift register the same way for that effects the stepper value numbers sent to pulse the steppers.

 

@will
In the for statement, that x<5 should be x<6 to catch the 6th stepper as well.

Of course 🙂

 

 


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

@robotbuilder

Posted by: @robotbuilder

What does the statement, stepper1val = 1,0,0; do?

Ya it gives me an error msg and wont compile for me either

Posted by: @robotbuilder

have you connected the stepper motor controller to the shift register the same way for that effects the stepper value numbers sent to pulse the steppers.

I am set up with

stepper 1

In1 to sh.r. pin 0

In2 to sh.r. pin 1

In3 to sh.r. pin 2

In4 to sh.r. pin 3,

stepper 2

In1 to sh.r. pin 4

In2 to sh.r. pin 5

In3 to sh.r. pin 6

In4 to sh.r. pin 7

I am getting beautifully smooth movements with this set up and that code. The power supply for the stepper boards is my benchtop power supply set at about 11.75 volts and so far I am just powering the uno from the usb to my computer.

I now have the other 3 shift registers wired in series with the same wiring going out to the next 4 stepper drivers.  

 


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

@dryden

But there is no pin 0 on the 74HC595 ?
Do you mean pin 16 to IN1 ?

 


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

@robotbuilder

15 or Qa to IN1 sorry.

image

 


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

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

@robotbuilder 

I think the sketch should convert from angles to steps immediately, so the calculations thereafter are always a binary choice: step or no step. It will also help eliminate any rounding errors if currentAngle and desiredAngle are floating.

I think you should make pulseStepper a byte function instead of a void sub. It would be the proper place to generate the byte command for each of the steppers. These should be generated as nybbles (i.e. only 4 bits) and can then be combined pairwise into bytes and sent off to the shift registers as pairs or as the entire set of 3 bytes for all 6 motors at the same time.

Generating them as nibbles, one for each stepper means that you'll only have one calculation for all 8 half-step phases which will help reduce the storage space that the sketch will require. That'll be important later when @Dryden wants to do anything with it 🙂

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


   
Dryden reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

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


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

@robotbuilder 

@will

I'm glad you guys know about this stuff, I'm confused as all heck lol

In my inexperience, Im just wondering about in other examples with 3 shift registers set up in series they have code that looks something like :

#include <ShiftRegister74HC595.h>

// create a global shift register object
// parameters: <number of shift registers> (data pin, clock pin, latch pin)
ShiftRegister74HC595<3> sr(3, 4, 5);

void setup() {
}

void loop() {

uint8_t pinValues[] = { B10101010, B10101010,  B10101010};
sr.setAll(pinValues);
delay(1000);

Can we not adapt @robotbuilder 's code to send the bites out like this? That being said I've tried this particular example and couldn't get any movement from my steppers, although I kinda blame my code writing skills and not the example code.

I like the ability to change the pin values or stepper values in @robotbuilder 's code, just so if I change to different stepper drivers and the values are different I can easily go in and change them. 

I'm still not sure why we need angles other than to maybe record the position of an event, I am happy just having the step count, if it saves space.

All I know is I've always like the old saying k.i.s.s. = Keep It Simple Stupid or Keep It Stupid Simple depending on what you prefer lol

I trust your opinions, and thank you both so much!

 

 

 


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

@will
Yes I had similar thoughts about how to go about it. Although I used the word "angle" I should have used the word "position" I wasn't using degrees.

Note that I dropped the timing stuff as it only seemed to apply when multiple step phases were done in the module.

You can only start the steppers moving at a minimum pulse rate otherwise the inertia stops them turning and the best minimum number is 1000 msec. Once the stepper is moving you can then decrease the time between the pulses (acceleration) and that is what the 6 servo demo code utube example was doing.

Working multiple stepper motors simultaneously is just a mental programming problem to solve for me as a self taught hobby programmer but an advanced programmer who understands all this to explain it with simple code would be the best response for dryden.  Ideally I would have six stepper motors to play with and come back in a months time with some kind of software solution which must exist out there for all  those robotic arms that use stepper motors.

 

 

 


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

@robotbuilder 

Yes I need this as basic and simple as possible lol!!! 

I should throw in here that when I ran the code with all 3 shift registers hooked up and all 6 stepper motors, it was trying to move all 6 steppers but only the first 4 were moving as I dont believe there was enough power for the last 2 steppers, so technically there is enough power to move 4 steppers at once but if it just moves one stepper at a time it would be simpler for me to understand for now. 


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

@dryden 

Unless you're going to manoeuvre your robot's arm by hand, you'll need to start thinking about how to get the "hand" from where it is now to where you want it to be. That means you'll have to calculate the angles of the shoulder, forearm, wrist angle, wrist rotation and grabber (finger) positions.

Those will be easier to state in angles than in steps.

Numerically speaking, it doesn't matter how we generate the bit sets for the steppers and the composite bytes for pairs of steppers or how we send them to the shift registers. There are several very simple ways of doing that AFTER we can get the software to embody the stepper's movement and get the bit sets.

That's why @robotBuilder and I are looking at doing that first. It's the hardest part of the work (so far, at least) and the sketch cannot progress until it's solved.

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


   
Dryden reacted
ReplyQuote
Page 5 / 7