Go Down

Topic: NEMA 17 Stepper + L298N H Bridge + AccelStepper Library (Read 4421 times) previous topic - next topic

revel

Hello all-

I have wired up and am successfully controlling a NEMA17 bipolar stepper, suncor SC42STH38-1304AF
http://www.suncormotor.com/Products/1468325853.html
with this motor shield: http://www.seeedstudio.com/wiki/Motor_Shield_V1.0 using the rudimentary code contained in aforementioned wiki.

Whereas it does do 1 revolution forward and back as per the code, I am not sure its perfectly tuned, because when I run the following code:

Code: [Select]

/*
 Stepper Motor Control - one step at a time
 
 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.
 
 The motor will step one step at a time, very slowly.  You can use this to
 test that you've got the four wires of your stepper wired to the correct
 pins. If wired correctly, all steps should be in the same direction.
 
 Use this also to count the number of steps per revolution of your motor,
 if you don't know it.  Then plug that number into the oneRevolution
 example to see if you got it right.
 
 Created 30 Nov. 2009
 by Tom Igoe
 
 */

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                                     // for your motor

// initialize the stepper library on pins 8 through 11:
//i change the above to 8, 11,12,13
Stepper myStepper(stepsPerRevolution, 8,11,12,13);           

int stepCount = 0;         // number of steps the motor has taken

void setup() {
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one step:
  myStepper.step(1);
    Serial.begin(9600);
//i added the following 4 lines, I think it energized all 4 outputs?
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  Serial.print("steps:" );
  Serial.println(stepCount);
  stepCount++;
  delay(500);
}



Which I had to modify to get any motion at all, I do get sequential steps in the same direction, but two are 'stronger' and two are weaker, with a subtle buzzing sound for the weaker ones/

I would like to use the AccelStepper library to produce a slow oscillation but can't get any of the example code to work.  I think it may have something to do with the fact that this library seems to work with the Adafruit motor shield library, AFmotor.h, which is based around the adafruit motor shield v1, which itself seems to be based around the L298N chip, like the one I am using.  But maybe the pin assignments are different?

In the following code, the stepper definition defaults to pins 2,3,4,5.  how do I change those pin assignments, if indeed that is my issue?
*edit- I figured this out, I think, see code at end of post*

Code: [Select]

// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()

  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}



Here is the modified code where I assigned pins and energized outputs, note that for a 4 wire motor there are 5 numbers assigned to AccelStepper stepper, the first one being (4,  8, 11, 12, 13):

Code: [Select]

// Bounce.pde
// -*- mode: C++ -*-
//
// Make a single stepper bounce from one limit to another
//
// Copyright (C) 2012 Mike McCauley
// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define a stepper's # of conductors,  and the pins it will use.
AccelStepper stepper(4,  8,11,12,13); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()

//energize 2 outputs channels, i.e. all four pins
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  // Change these to suit your stepper if you want
  stepper.setMaxSpeed(100);
  stepper.setAcceleration(20);
  stepper.moveTo(500);
}

void loop()
{
    // If at the end of travel go to the other end
    if (stepper.distanceToGo() == 0)
      stepper.moveTo(-stepper.currentPosition());

    stepper.run();
}



btw, I also have a pololu a4988 driver if that would be easier to work with.

Thanks!

-R

Robin2

The A4988 would be miles better - assuming your motor requires about 1.5 amps or less.

However I don't see your motor listed in the link you gave so I don't know how much current it requires.

...R
Stepper Motor Basics
Simple Stepper Code

Two or three hours spent thinking and reading documentation solves most programming problems.

revel

Ah yes, that is true isn't it... Is there a way to figure this out with a multi meter?

I do know that both the a4988 and this stepper are commonly used in 3D printer construction, so I assume they are a good pair.  Can you explain why the a4988 is better than the H Bridge?

Robin2

Ah yes, that is true isn't it... Is there a way to figure this out with a multi meter?
Measure the coil resistance and report back

Quote
Can you explain why the a4988 is better than the H Bridge?
I think I covered that in the link I gave you.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

revel

Ok, yes, I had read that, there actually, but hadn't retained it, now I will! current limiting- sweet.  Will test coil resistance tomorrow.

revel


Robin2

None of the motors in your list has exactly that resistance - the nearest is 3 ohms and that motor requires 1.68 amps which would probably be a struggle for an A4988.

I would set the A4988 current limit to 1.2 amps (like the motors with 3.3 ohms in the list) and see what happens. But don't blame me if the smoke escapes from your motor :)

It is normal for stepper motors to run hot - uncomfortable to touch. But if you think it is too hot you should reduce the current limit.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up