I made something out, but without the accelstepper library (I tried but witout success), I used the Arduino Stepper.h integrated library:
#include <Stepper.h>
const int stepsPerRevolutionM1 = 200; // change this to fit the number of steps per revolution for your motor
const int stepsPerRevolutionM2 = 200; // change this to fit the number of steps per revolution for your motor
//Direction pins
int inpDirM1 = 12; // motor 1 direction pin is D12
int inpDirM2 = 13; // motor 2 direction pin is D13
int valDirM1 = 0;
int valDirM2 = 0;
// initialize the stepper library on pins 4 through 7:
Stepper myStepperM1(stepsPerRevolutionM1, 4,5,6,7,1);//motor 1
// initialize the stepper library on pins 8 through 11:
Stepper myStepperM2(stepsPerRevolutionM2, 8,9,10,11,1);//motor 2
void setup() {
pinMode(inpDirM1, INPUT);
pinMode(inpDirM2, INPUT);
//Step pins
attachInterrupt(0, doStepM1, RISING);//motor 1 step pin is D2 (Must be an Interrupt pin)
attachInterrupt(1, doStepM2, RISING);//motor 2 step pin is D3 (Must be an Interrupt pin)
}
void loop(){
valDirM1 = digitalRead(inpDirM1);
valDirM2 = digitalRead(inpDirM2);
}
void doStepM1()
{
if(valDirM1==0){
myStepperM1.step(-1);
}else{
myStepperM1.step(1);
}
}
void doStepM2()
{
if(valDirM2==0){
myStepperM2.step(-1);
}else{
myStepperM2.step(1);
}
}
As you can see, I used interrupt pins.
I'm actually using a modded stepper.h library, I searched on google and I found the same library modified for half step.
It's seems to be working good with one motor (I have not tried two motors simultaneously yet).
With another arduino I can control it with the accelstepper library, obviously this time with only Dir and Step pins, example:
#include <AccelStepper.h>
AccelStepper motorTest(1, 3, 2); // pin 3 = step, pin 6 = direction
void setup() {
motorTest.setMaxSpeed(400);
motorTest.setSpeed(10);
}
void loop() {
motorTest.runSpeed();
}
I have not "benchmarked" it, so I do not know if It's working good (without loosing steps or other related things). But It's the best I could do with my experience.
If you think it's a bad code, any suggestions will be appreciated!