AccelStepper: Read pin values

Hello community

I wish to control 6 mini stepper motors (12V 28BYJ-48) independently with the Arduino uno over motor driver breakouts (ULN2003A). Already, I wired one breakout and stepper motor and it worked really well for my purpose. For the controls I used the AccelStepper library because I need acceleration.

Because there are at least 4 digital pins per motor drivers needed on the Arduino, I researched for a solution but couldn't get any - at least for my specific setup.

Now I thought of controlling the motor drivers via a shift register (sn74hc595). That way it should be possible to control 6 motor drivers over only 3 digital pins. But for now, I just want to control 1 motor drivers as a first test.

The problem is that the AccelStepper library just sends data to the pins directly when stepper.runSpeed() is executed. This data should now go to the shift register instead to the pins. But I couldn't find out how to intercept the data that is sent from the AccelLibrary. Is there a way?

I haven't much useful code for now because I'm really stuck at getting the informations I need from the AccelLibrary.

#include <AccelStepper.h>

#include <ShiftRegister74HC595.h> // Maybe it's not a good idea to use this library? 

// Motor pin definitions:
#define motorPin1  2 
#define motorPin2  2 
#define motorPin3  2 
#define motorPin4  2  // I set this all to 2 because it's the data channel of the shift register. Maybe it's possible to set variables here instead of pins?

// 4 wire motor
#define MotorInterfaceType 8

// 2 is the data channel
ShiftRegister74HC595<1> sr(2, 3, 4);

AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);


void setup() {
  Serial.begin(9600);
  stepper.setMaxSpeed(1000);
}

void loop() {
  stepper.setSpeed(500);
  sr.setAllHigh(); // Maybe it's possible to set all pins high and then send rundSpeed()? 
  stepper.runSpeed(); // Or get the data of the single (4) pins and run it through the shift register afterwards? 
}

(motor is connected of 5V of Arduino for testing purpose) Wiring on the picture should fit my idea but maybe you even have any better idea to control 6 motors via 1 or 6 motor drivers?

Cheers and best regards, Tesla4

Welcome to the forums. +1 karma for using code tags on your first post.

First off, it is not the AccelLibrary, it is the AccelStepper library (that threw me off a bit). You will have to actually modify the library if you want to use the shift register. You could also get an IO expansion chip to simply have more IO pins but that would require modifications to the library as well.

How about stepping up to a Mega? It has 54 pins?

Also, you do NOT want to connect all your motors up to the 5V on the arduino. It can not supply enough current to run all 6 motors. It is probably okay for 1 motor for testing/exploring, but definitely not a final solution.

I agree. Using a Mega would make life a great deal simpler.

...R

Thanks for your answers. I already guessed that the library probably needs modification. And yes: It's the AccelStepper library, sorry for that.

I did some research again and I think the best thing to do is to use a Mega, as you suggested too, as it's the easiest solution.

5V from Arduino is just for testing. While attaching more than one motor I will use a 12V power supply.

tesla4:
5V from Arduino is just for testing. While attaching more than one motor I will use a 12V power supply.

Make sure your stepper motors are intended for 12v use. Many are designed for 5v.

...R

Thank you for the information. I made first tests with a 5V 28BYJ-48 (because 5V is the only version of this motor I could buy in my country).

With 5V it had quite low power and because I read that it could be powered with 12V (but not recommended over a long time), I then connected a 12V power supply. That way it works flawlessly for my purpose (lifts between 100g to 500g for 1 minute and then stops for at least 15 minutes). Nevertheless it did get a bit hot after a few tasks in row (without the 15 min pauses).

Now I ordered the same model explicitly for 12V.