L293D And Stepper

I cannot for the life of me figure out how to use a L293D with a Stepper Motor from ( http://www.adafruit.com/products/324 ) I have it wired as shown in the photo. I don’t even know if the the code I’m using even works but whatever. All I know is nothing happens when I try anything.

Firstly you apparently haven't connected the motor supply to the L293D! The two power strips on each side of the breadboard aren't linked. (Also you may need to check that they don't have a break in the middle, many do).

Secondly what is the motor power supply (not 2 AA batteries as in the picture I hope).

There are plenty of example circuits using the L293D dotted around these forums and the internet to compare against.

[ also I've just noticed you haven't connected either enable input - I think that's necessary (they certainly need to be HIGH for any output current) ]

check your wiring. It looks like you have the motor connected to the 293 inputs and the arduino outputs connected to where the motor would connect.

Ok so I thought I had the power going to both sides but where would I hook up on the other side. And no I’m not using two AA as my power I’m using 12V. And I think I connected the enable pins and this is the code I’m using but I don’t think it’s correct at all.

Code

#include <Stepper.h>

int E1 = 2;
int E2 = 3;
int in1Pin = 12;
int in2Pin = 11;
int in3Pin = 10;
int in4Pin = 9;

Stepper motor(200, in1Pin, in2Pin, in3Pin, in4Pin);

void setup()
{
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
digitalWrite(E1, LOW);
digitalWrite(E2, LOW);

// this line is for Leonardo’s, it delays the serial interface
// until the terminal window is opened
while (!Serial);

Serial.begin(9600);
motor.setSpeed(20);
}

void loop()
{
if (Serial.available())
digitalWrite(E1, LOW);
digitalWrite(E2, LOW);
{
int steps = Serial.parseInt();
motor.step(steps);
}
}

Code

Life would be so much easier (both connections and programming) if you used a "proper" stepper motor driver board such the Pololu A4988. The L293 is primarily intended for regular DC motors.

...R

Well I have the L293D and the interwebs said I could use it so if somebody would give me some helpful information like markT and groundfungus did that would be greatly appreciated.

void loop()
{
  if (Serial.available())
  digitalWrite(E1, LOW);  
  digitalWrite(E2, LOW);
  {
    int steps = Serial.parseInt();
    motor.step(steps);
  }
}

As MarkT pointed out. the enables must be HIGH for the outputs to function.

Ok so I made some changes. I changed the enables to HIGH I can’t believed I missed that. I also switched the Output and Input pins and supposedly supplied power to both sides. Yet still nothing happens.

Code

#include <Stepper.h>

int E1 = 2;
int E2 = 3;
int in1Pin = 12;
int in2Pin = 11;
int in3Pin = 10;
int in4Pin = 9;

Stepper motor(200, in1Pin, in2Pin, in3Pin, in4Pin);

void setup()
{
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
digitalWrite(E1, LOW);
digitalWrite(E2, LOW);

// this line is for Leonardo’s, it delays the serial interface
// until the terminal window is opened
while (!Serial);

Serial.begin(9600);
motor.setSpeed(20);
}

void loop()
{
if (Serial.available())
digitalWrite(E1, HIGH);
digitalWrite(E2, HIGH);
{
int steps = Serial.parseInt();
motor.step(steps);
}
}
Code

In the Fritzing I see no connection from pin 16 to the 5V logic supply. I would also suggest that you take out the serial part and try hard coding the steps variable. Get one thing working at a time.

groundfungus: In the Fritzing I see no connection from pin 16 to the 5V logic supply. I would also suggest that you take out the serial part and try hard coding the steps variable. Get one thing working at a time.

pin 20, not pin 16, this has already been pointed out.

Pin 20 on a 16 pin dip?

Quote from: groundfungus on Today at 05:52:04 pm In the Fritzing I see no connection from pin 16 to the 5V logic supply. I would also suggest that you take out the serial part and try hard coding the steps variable. Get one thing working at a time.

pin 20, not pin 16, this has already been pointed out.

As groundfungus said . Also do not hook up the motor supply to pin 16.

Ok so what are the pin numbers that the stepper power supply goto? 8 and 16? And they're both positive right? Cuz the stepper power ground just goes to ground on the chip yes?

Pin 8 is for the power supply to the motor (12 volts in your case) and pin 16 is for the logic (system)supply voltage(the 5V pin on the due).

Your fritzing shows a due which is a 3.3V logic system where an UNO is 5V.

The L293D has a minimum of about 4.5V for its logic supply voltage. So it needs the 5V from the due. It should be able to see the output from the due (3.3V) as a high.

So in your first fritzing it looks like you had the power hooked up correctly but not the others.

I would first use a known program to test the stepper. Go with the example programs for steppers found in the example area of the file tab.

Kameechewa: Ok so what are the pin numbers that the stepper power supply goto? 8 and 16?

No. Stepper power goes to 8, logic power goes to 16.

Have a look at this thread where I ran a stepper from first principles with no library.

Thanks for all the help everyone. I finally have it turning but I can't get it to like spin it just goes a little of the way and then grinds like its going too fast or too slow. So i don't know whats wrong with my code but owell.

Ok so now I have this code and after i send like 24+ or 500+ it like turns half a ittybittymicroscopicnano millimeter and then it just twitches. What am I doing wrong?

Code

#include <Stepper.h>
#define STEPS 200
Stepper stepper(STEPS, 4, 5, 6, 7);
int steps = 0;

void setup(){
stepper.setSpeed(30);
Serial.begin(9600);
}

void loop(){
if (Serial.available()){
char ch = Serial.read();

if(isDigit(ch)){
steps = steps * 10 + ch - ‘0’;
}
else if(ch == ‘+’){
stepper.step(steps);
steps = 0;
}
else if(ch == ‘-’){
stepper.step(steps * -1);
steps = 0;
}
}
}

Code

I think it was suggested earlier that you try it without the serial stuff, just to see if it works. Good idea to do that anyway, eliminate one possible source of any problem.

Have a look at the pic on the thread I linked, check the connections. Perhaps try the code I posted, which doesn't use a library, just to test. Eliminate another potential source.