3
\$\begingroup\$

I'm making a basic rig for timelapse photography using arduino. It is a panning system for a DSLR camera, so I went with the motor shield from Arduino with the L298 chip and a 12V, 1.7A stepper motor. Before I could power the motor shield externally I noticed that the motor was running fine off of the 5V USB supplied to the Arduino board. It was able to fully move the DSLR around at different speeds and hold it in place.

The problem arose when it was asked to do a single step at a time (I assume setting up any speed here will do). I noticed that not all steps are equal. Sometimes, there would 2 small steps followed by a larger step or even the other way around. From my understanding, stepper motors have fixed step size, and either it will fully do it (provided with enough power), or it will fail, is that correct? I thought it will fully overcome the inertia, and not get stuck half way, and then work fine other times.

So is the motor/5v power or my code is at fault here? Providing external power would require me to cut a trace on the shield so I'm holding out on that till I'm sure. (also having a single power supply would be nice!)

Here is the generic code I'm using:

#include <Stepper.h>

 const int stepsPerRevolution = 1024;
 Stepper myStepper(stepsPerRevolution, 12,13);     

// give the motor control pins names:
 const int pwmA = 3;
 const int pwmB = 11;
 const int brakeA = 9;
 const int brakeB = 8;
 const int dirA = 12;
 const int dirB = 13;

 int times = 120;//420
void setup() {
 Serial.begin(9600);
 // set the PWM and brake pins so that the direction pins  // can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);

// initialize the serial port:
Serial.begin(9600);
// set the motor speed (for multiple steps only):
myStepper.setSpeed(2);
}

void loop() {
  while(times>0){
    myStepper.step(1);
    Serial.println(times);
    times--;
    delay(12000);
   }

  }
\$\endgroup\$
2
\$\begingroup\$

If the motor is rated for 12V and 1.7A, then supply it with this. USB can supply 5V at a maximum of 500mA, so instead of a maximum of 12V * 1.7A = 20.4W you have a maximum of 5V * 500mA = 2.5W. That's big difference.
My guess is that due to the DSLR's inertia and the weak stepper coil drive, it it slipping occasionally (or something similar)
Also, from a previous question I recall the Arduino motor shield is not the best design - the L298 drops a volt or two through both it's source and sink drive transistors so you will end up with even less power available, maybe around a watt (see source/sink saturation voltage in the datasheet spec table)

The basic code looks okay, but it's impossible to say for certain as all the real functionality is tucked away in the stepper library. I'll assume this is probably okay if it's a commonly used library that's been around for some time.

So, yes, supply the motor with the 12V and at least 1.7A. If you have to cut the trace then do this, it easy to solder it back later if you need to (make sure there is no jumper on the motor board first though, I have a feeling I remember a jumper for the purpose of an external supply on one of these shields)

\$\endgroup\$
1
\$\begingroup\$

Have you tried varying the PWM values? Also, I recommend the Rugged Motor Shield. I'm using a stepper motor to rotate a shaft to test throttle position sensors and noticed behavior like yours when at the ends of the TPS travel ... or when the PWM is too low and the stepper cannot make that step, it bounces around a bit.

The Rugged Motor Shield allows for external supply to the shield, so the Arduino and shield can be separately powered. If anything, going to that site might help you better understand how to play with steppers.

For my situation, I found that for the Arduino to measure the sensor voltage on A2 (or any pin), the TPS input shaft couldn't be in motion, so my sketch moves the shaft one step, takes measurement, repeat. For my situation, my stepper has 7.5° steps and an 18 tooth gear. I used 3D printer to make a 54T gear so I get 3:1 reduction, making my stepper motor more power and precision.

\$\endgroup\$
  • \$\begingroup\$ You should not be using open-loop PWM with a stepper motor, you should be using a chopping current regulator which adjusts the PWM duty cycle to maintain the current as close as possible to the chosen value. \$\endgroup\$ – Chris Stratton Mar 18 '13 at 21:40
  • \$\begingroup\$ @ChrisStratton I'm using the sketch from ruggedcircuits.com I'm not sure how it is implemented. :P Got any examples? \$\endgroup\$ – Chris K Mar 30 '13 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.