Stepper Trouble

Alright, I’ve been messing with this bipolar stepper motor (http://www.sparkfun.com/commerce/product_info.php?products_id=9238) for two days now and have had little / no luck. To run it I built a double H-bridge on a breadboard (which I am relatively sure is correct). I have tried several codes with it (see attached). When using the Stepper library it does nothing and when I use my own basic code it rotates VERY slowly and often gets stuck and begins to vibrate about one position. Any help with this would be greatly appreciated. For reference I am powering it with a 9V battery and the switches in the H-bridges are just basic BJT transistors from RadioShack.

Code using Stepper Library

#include <Stepper.h>

#define motorSteps 200
#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11

Stepper TestStepper(motorSteps,motorPin1,motorPin2,motorPin3,motorPin4);

void setup()  {
  
  TestStepper.setSpeed(60);
  
}

void loop()  {
  
  TestStepper.step(100);
  delay(1000);
  TestStepper.step(-100);
  delay(1000);
  
}

My own basic code

#define pin1 8
#define pin2 9
#define pin3 10
#define pin4 11


void setup()  {
  
  pinMode(pin1,OUTPUT);
  pinMode(pin2,OUTPUT);
  pinMode(pin3,OUTPUT);
  pinMode(pin4,OUTPUT);
  
  digitalWrite(pin1,HIGH);
  digitalWrite(pin2,LOW);
  digitalWrite(pin3,HIGH);
  digitalWrite(pin4,LOW);
  
}

void loop()  {
  
  digitalWrite(pin1,LOW);
  delay(100);
  digitalWrite(pin2,HIGH);
  delay(100);
  digitalWrite(pin3,LOW);
  delay(100);
  digitalWrite(pin4,HIGH);
  delay(100);
  digitalWrite(pin2,LOW);
  delay(100);
  digitalWrite(pin1,HIGH);
  delay(100);
  digitalWrite(pin4,LOW);
  delay(100);
  digitalWrite(pin3,HIGH);
  delay(100);
  
}

I use my own basic code it rotates VERY slowly

It will as you have 0.8 seconds worth of delay in the loop. Baring in mind that a typical motor moves 1.8 degrees per step it is going to be slow at that rate.

I am powering it with a 9V battery

What sort of battery? If it is a small rectangular one then they can't provide much current. Try measuring the voltage of it while it is trying to drive the motor.

I tried taking the delays out and it would get stuck at a point much more often. Sounds like if I place another battery or batteries in parallel it should take care of my problem?

No taking the delays out make it go too fast for the motor.

Putting batteries in parallel is not a good idea. What ends up happening is that one battery charges the other and might explode.
You still haven't said what sort of battery and what sort of current drain the motors are demanding.

Sounds like your motor is out of sync

It may also be worth playing with the motorSteps and setSpeed variables
and try smaller steps in your code

A similar motor I am currently using to yours I have set at 100 steps and 10 speed

Steppers are picky things :slight_smile:

I think I have worked it out, you are getting the sequence of switching wrong. On a H bridge when the two inputs are the same there is no current through the coil. For fill steps there must always be current through the coil therefore you must change two pins at once and then delay. Have a look at this page for full details of the coil sequence:-
http://www.thebox.myzen.co.uk/Workshop/Motors_4.html

Here's the new code:

#define pin1 8
#define pin2 9
#define pin3 10
#define pin4 11


void setup()  {
  
  pinMode(pin1,OUTPUT);
  pinMode(pin2,OUTPUT);
  pinMode(pin3,OUTPUT);
  pinMode(pin4,OUTPUT);
  
}

void loop()  {
  
  digitalWrite(pin1,LOW);
  digitalWrite(pin2,HIGH);
  delay(100);
  digitalWrite(pin4,LOW);
  digitalWrite(pin3,HIGH);
  delay(100);
  digitalWrite(pin2,LOW);
  digitalWrite(pin1,HIGH);
  delay(100);
  digitalWrite(pin3,LOW);
  digitalWrite(pin4,HIGH);
  delay(100);
  
}

I copied the steps from your link for "two phase on" drive. The motor still just wiggles back and forth.

The battery is a cheap rectangular 9V, its probably the problem. So ... if I get a better power source I should be able to use the Stepper library again, right?

The battery is a cheap rectangular 9V, its probably the problem

It is defiantly a problem. The other thing you can try is to swap over one of the coils. That is reverse one coil.

Reversing the coils was one of the first things I tried, what kind of power source do you suggest?

You need to know the current your motor is taking. This could be measured directly or you can measure the DC resistance of the coils with a meter and then work it out using ohms law. Without doing this you are only guessing. My guess is that you need a 500mA power supply.