Arduino + Accelstepper as Stepper Motor Controller

1,836 views
Skip to first unread message

simfender

unread,
Dec 4, 2014, 9:56:43 AM12/4/14
to accels...@googlegroups.com
Hi all,

I searched a lot (but maybe not enough) about what I'm going to say.

I need to have a complete stepper motor controller with Direction and Step inputs.

I bought a L298N Dual H-Bridge for Arduino, I know, it is not a controller but a driver, and to do what I need I have to use L297 too.

The question could seem stupid:  can I use an Arduino + Accelstepper + L298N as a Step/Direction controller without L297?

Easier: can I "emulate" an L297 with Arduino + Accelstepper?

if so I'll start to learn/understand how to do it, otherwise I'll do what I need with the L297.


I'm noob in the arduino world and any answer will be appreciated.

simfender

unread,
Dec 9, 2014, 2:44:14 AM12/9/14
to accels...@googlegroups.com
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!

Mike McCauley

unread,
Dec 30, 2014, 12:06:17 AM12/30/14
to accels...@googlegroups.com
Hello,

On Thursday, December 04, 2014 06:56:43 AM simfender wrote:
> Hi all,
>
> I searched a lot (but maybe not enough) about what I'm going to say.
>
> I need to have a complete stepper motor controller with Direction and Step
> inputs.
>
> I bought a <http://www.bristolwatch.com/L298N/L298N_arduino.htm>L298N Dual
> H-Bridge for Arduino, I know, it is not a controller but a driver, and to
> do what I need I have to use L297 too.
>
> The question could seem stupid: can I use an Arduino + Accelstepper +
> L298N as a Step/Direction controller without L297?
>
> Easier: can I "emulate" an L297 with Arduino + Accelstepper?

Not without modifying the library code substantially.
Its not a use case we currently suport.

>
> if so I'll start to learn/understand how to do it, otherwise I'll do what I
> need with the L297.
>
>
> I'm noob in the arduino world and any answer will be appreciated.

--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com
Phone +61 7 5598-7474

Reply all
Reply to author
Forward
0 new messages