Controlling several stepper motors

Hello,

Thought I had better start a separate thread instead of having my old thread go off topic.

I have purchased some cheap stepper motors and drivers off ebay (28BYj-48 steppers and ULN2003 drivers) and would like 4 connected for a project. Each driver needs 4 pins, so that means 16 pins are needed alone for the drivers. In addition to this I need some pins for sensors and other components. This all means I won't have enough pins to controls everything from one ATMega328 as you only have 18 useable pins (13 digital and 5 analog; any of which I believe the drivers can use as it doesn't specifically need PWM/analog).

So the question I have is how to control more than 18 pins from an Arduino. Is my only option I2C where I will connect two ATMega328 chips and then spread the components/jobs amongst those two chips?

I've been looking into shift registers but they seem to become difficult to control when you involve stepper motors as you're only turning pins high/low instead of sending "step" or "speed" instructions.

I want to avoid "Arduino shields" if possible as the end goal will have the ATMega328 permanently connected to the final circuit board rather than permanently connecting up the Arduino UNO (which feels a waste as it's a development board rather than a "final" board). Modules and non-shield boards are fine though!

Anyone have any advice?

Thanks

You could use an EasyDriver stepper controller (one per motor).

Basically you connect the four leads of the motor to the stepper driver, and then you control the driver using a single pin (it's marked STEP on the board) and optionally DIR to control the direction. The board has integrated microstepping control. I've used such board myself and I have to say it's a great product. Unfortunately, it costs $15 at SparkFun.com (found here). So I recommend you get them from China for $3 each (Ebay link).

I think those are 5-wire steppers and can't be driven by an Easydriver - but not certain of this.

In any case, rather than buy 4 stepper motor drivers why not just buy a second cheap Arduino - or splash out and buy a Mega.

I've just got a Leonardo (similar price to an Uno) and it appears that its serial pins (0,1) can be used separately from the serial connection to the PC over the USB connection. That means it would be a convenient option for the "master" device as it could easily talk to the second Arduino as well as to the PC.

One disadvantage of not using stepper drivers is that the Arduino will need to do a lot of work to supply pulse sequences for all the coils on 4 stepper motors.

...R

artaex:
You could use an EasyDriver stepper controller (one per motor).

Basically you connect the four leads of the motor to the stepper driver, and then you control the driver using a single pin (it's marked STEP on the board) and optionally DIR to control the direction. The board has integrated microstepping control. I've used such board myself and I have to say it's a great product. Unfortunately, it costs $15 at SparkFun.com (found here). So I recommend you get them from China for $3 each (Ebay link).

I wasn't expecting a reply so soon, thanks a lot!

Having 1 pin taken instead of 4 pins per stepper certainly sounds much better (I only want them to move in one direction so from your description I shouldn't need to provide that, but even if I do, 2 pins is still better!).

For the 4 wire driver (ULN2003), I believe the code should look something like this (never used steppers and they haven't arrived yet so this code may not be completely correct):-

Stepper myStepper(64,8,9,10,11); //define 64 steps and pins 8-11 for use with the stepper/driver

void setup() {
myStepper.setSpeed(1); //Set speed to 1 rpm
stepper1.moveTo(0);  //Set position to 0 degrees
}

void loop() {
stepper1.moveTo(32);  //Move 180 degree position
delay(5000); //wait 5 seconds
}

With the easyDriver, how would you define "myStepper" as you're now only using 1 pin instead of 4? Or is it the case you need to just turn the pin "HIGH" for x microseconds and then set it "LOW" again to stop it moving?

I've also seen references on the web that the easyDriver gets pretty hot to the touch so some sort of cooling (heatsink) is needed, is that your experience? My project won't be driving the motors very hard nor will they be lifting significant loads (it's for a custom clock project).

Robin2:
I think those are 5-wire steppers and can't be driven by an Easydriver - but not certain of this.

In any case, rather than buy 4 stepper motor drivers why not just buy a second cheap Arduino - or splash out and buy a Mega.

I've just got a Leonardo (similar price to an Uno) and it appears that its serial pins (0,1) can be used separately from the serial connection to the PC over the USB connection. That means it would be a convenient option for the "master" device as it could easily talk to the second Arduino as well as to the PC.

One disadvantage of not using stepper drivers is that the Arduino will need to do a lot of work to supply pulse sequences for all the coils on 4 stepper motors.

...R

Thanks, I did think I2C was maybe a solution seeing as another ATMega328 chip costs around £2-£3 on ebay and then I double the amount of useable pins minus 2 for the clock/data lines. I was also thinking of somehow programming an ATMega32 as my chip instead of a ATMega328 as that provides a lot more pins to use.

I was trying to avoid having an Arduino board (like the UNO, Leonardo, Mega etc...) as a permanent control board in the project as it feels like a waste as they're more like development boards than boards you keep in a permanent/final project (I generally prefer to upload the program to another chip and then have that permanently in the final circuit). The boards also take up more room than if you were to move it over to a PCB for instance (as they contain a lot more than you sometimes may need in your project). However, with this project needing so many pins, I may have to re-think that and actually go for an Arduino Mega. EBay seems to have some for under £15 and it may be the simpler (and maybe even more affordable) way to go in the end.

I think the first step is to maybe hold off buying anything further, wait for the cheap stepper/driver bundle to arrive (which may be a while as they ship from Hong Kong), see how I get on with them and then move on to this. I'm starting to lean towards an Arduino Mega now I've seen the price on eBay :slight_smile:

Thanks a lot for your input!

One easy option would be to use something like a Mega2560, which has ample pins for what you need.

PeterH:
One easy option would be to use something like a Mega2560, which has ample pins for what you need.

Yep, that's the one I saw on eBay. For under £15 (even less if I get it from Hong Kong) I think this is looking to be the route I'll go down just because I need so many pins for this particular project.

On other future projects where I only need a few pins, I'll probably stick to my normal way where I remove the ATMega328 and permanently add it to the circuit. Then I just replace the chip for a few pounds. It saves money in the long run as you're only putting in £6 of components rather than a £15 board. It also allows me to make the form factor smaller as the Arduino boards contain lots of things I don't necessarily need in all projects.

Going with a motor driver is a better option since you can use an external power supply. This is highly recommended so you don't draw too much current directly from your Arduino.

For the code, you simply set a HIGH on the STEP pin for a really short time (few microseconds) and then LOW like so:

void loop() {
  digitalWrite(9, HIGH); // change 9 to your STEP pin
  delayMicroseconds(100);  // lowering this value will increase the speed and vise-versa. It's a bit trial and error
  digitalWrite(9, LOW); 
  delayMicroseconds(100);
}

I've done a bit of research and I'm pretty sure an Easydriver (or equivalent) can't drive a 5-wire unipolar stepper motor.
They can drive a 6-wire unipolar by ignoring the two center tap wires and treating it as a 4-wire bipolar stepper.

In a 5-wire unipolar stepper the centre taps from the two coils are joined together and appear as a single wire.

If you can modify a 5-wire stepper to break the connection between the two centre taps they could be used as bipolar steppers.

...R

Robin2:
I've done a bit of research and I'm pretty sure an Easydriver (or equivalent) can't drive a 5-wire unipolar stepper motor.
They can drive a 6-wire unipolar by ignoring the two center tap wires and treating it as a 4-wire bipolar stepper.

In a 5-wire unipolar stepper the centre taps from the two coils are joined together and appear as a single wire.

If you can modify a 5-wire stepper to break the connection between the two centre taps they could be used as bipolar steppers.

...R

Thanks for the follow up and of course to everyone else for their input too. I think I'll most likely have to go down the Arduino Mega route (Mega2560) or if I want to keep the physical size down, I2C with two ATMega328 chips (on a custom PCB). Most likely I'll go with the Mega2560 for making things simpler/quicker.

Either way I'll have the 4 cheap drivers (ULN2003) that ship with the stepper motors connected for each motor (so 16 pins in total being used).

Thanks again all!