Now, first of all, i don't know if this even i posible..
But i have this stepper motor, that im trying to run with an L298N driver.
I have connected it this way on the L298N:
OUT1 -> Stepper wire 1
VS -> 24v +
ENA -> 5v (arduino)
GND -> 24v -
CSA -> Arduino GND
OUT2 -> Stepper wire 2
IN1 -> Digital pin 2
IN2 -> Digital pin 3
VLS -> 5v (arduino)
ENB -> 5v (arduino)
OUT3 -> Stepper wire 3
CSB -> Arduino GND
IN3 -> Digital pin 4
IN4 -> Digital pin 5
OUT4 -> Stepper wire 4
And here is the code:
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 200
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 2, 3, 4, 5);
void setup()
{
stepper.setSpeed(300);
}
void loop()
{
stepper.step(50);
delay(500);
stepper.step(-50);
delay(500);
stepper.step(200);
delay(500);
stepper.step(-200);
delay(500);
}
Now I just can't see what i'm doing wrong.
Maybe some of you can..
Without knowing anything about the motor, we probably can't begin to know whether you have things hooked up right; but I can see a few possible issues based on the L298N datasheet:
OUT1 -> Stepper wire 1
VS -> 24v + I am not certain - but I think this needs to be tied to 5V - not 24!
ENA -> 5v (arduino)
GND -> 24v - Should this -24 volts? I believe it should be tied to ground (and tied with the Arduino's ground)
CSA -> Arduino GND Not sure if this pin (and CSB) shouldn't be tied to ground via a resistor, and not direct (not sure what direct to ground would do) - see the datasheet
OUT2 -> Stepper wire 2
IN1 -> Digital pin 2
IN2 -> Digital pin 3
VLS -> 5v (arduino) I think this needs to be tied to 24V, not 5V
ENB -> 5v (arduino)
OUT3 -> Stepper wire 3
CSB -> Arduino GND
IN3 -> Digital pin 4
IN4 -> Digital pin 5
OUT4 -> Stepper wire 4
It is difficult to tell from the breakout image you supplied how and what actual pins on the device is connected to the header, because of the dual-sided PCB used - but it appears you may have things wired really wrong (and if you haven't blown the 298, you will soon!); this doesn't even get into the connections to the motor (you didn't say what type, etc motor you used - we need to know the exact coil connections, specs on the motor - something).
I would refer to the specsheet and verify that the connections you have made to the header match that of the specsheet for the pins on the device (pin 1 on the device looks like it is at the "top" of your picture - left side of the device).
Also, I believe that an L298N needs to be protected with a diode bridge from the back-EMF generated by (any) motor. That is also detailed in the datasheet on page 7/13
Without them, you run the risk of blowing the chip up when the motor turns.
VS -> 24v + I am not certain - but I think this needs to be tied to 5V - not 24!
VLS -> 5v (arduino) I think this needs to be tied to 24V, not 5V
I read the datasheet as saying
Vs Power Supply 50 V (max)
Vss Logic Supply Voltage 7 V (max)
I suspect that they use VLS for "V Logic Supply", in which case it would be correct. BUT it isn't clear.
But what im not sure of, can L298N be used on at Stepper motor?
L298N's are okay for steppers (the datasheet explicitly says this), and a friend uses L298's for steppers on his robots.
It looks okay for this motor too, but would have been nice to see the stall current, but there is so much headroom (extra current carrying capacity) in the L298N, that it should be okay. Also it protects itself from most situations (except missing back-EMF protection).
GB
[edit]Doh - just saw "Coil DC resistance = 50 ohm" on the motor data sheet, you should be fine [/edit]
Ok - looking at things again (comparing to SparkFun's schematic); those two lines appear connected OK (but I am still wondering what you mean by "-24 volts" on the GND line - are you referring to the negative/ground supply rail for the stepper, or an actual negative voltage? If it is a ground rail, it would need to be tied to the ground of the Arduino).
Which stepper are you using (something from SparkFun?)...?
Okay, so with the changes (i.e. GND to Arduino ground) can you drive some LEDs?
Looking at the datasheet, I think you could wire it up all up to 5V to make an experiment easier (but don't connect the motor)
You should be able to put a LED on each of the L298N's 4 outputs (with current limiting resistors) and flash them. The stepper library should drive this, and if you drive it slowly, you'll see the step pattern in the LEDs.
Once you have that right, the things left are:
disconnect the LEDs from the output (or increase the current limiting resistors)
add the back-EMF diodes,
add noise filtering capacitor (0.1uF-ish) across each motor coil,
I think I know what you mean by, tire the GND to the GND on the arduino. But i'm not sure how to do that. I thought it was connected to the VLS, however (if i read the block diagram correctly) I can see that it not.
Is it safe to just put the GND from the 24v and the Arduino in the same row on my breadbard?
Is it safe to just put the GND from the 24v and the Arduino in the same row on my breadbard?
Yes, you can connect the ground of the 24V supply to the Arduino ground.
BUT you must not connect the 24V of the power supply to the Arduino (but I think you knew that already).
To connect the power supply ground to the Arduino ground, yes you can connect them to the same row in the breadboard, or just use a wire from the 24V power supply ground to one of the Arduino's ground headers.
I'm just suggesting doing it in a couple of steps to make things smoother and easier.
I love LEDs for debugging because I can revert to using them when something puzzles me.
Using the LEDs first, instead of the motor, is a useful debugging approach, and it is almost impossible to break anything at 5V.
So less need to worry and fun arrives quicker
Now I have the LEDs blinking in the right order, and noted it all.. Just in case i forget..
So the next step is to hook it up to my motor.. But I don't think I will do it tonight though, just want to sit and watch the LEDs blinking
Honest answer is it depends how the stepper is wired up.
It doesn't look right.
I would expect something like this:
x--- step 1
-x-- step 2
--x- step 3
---x step 4
This is a pretty good article describing the patterns you could use Stepping Motor Types
A rule of thumb I've been given is, the diodes should have the same current rating as the motor current, so a 1A diode should be fine for a 1A supply; it should only be conducting for a small part of the time so this should be safe.