kestrel117:
I have followed multiple guides on how to hook power these motors through this board and have so far been unable to get to motor to do more than vibrate. These are my components and I am using the default stepper motor examples.
I too am using an L298N for driving steppers. I have no problems with L298N at all for my purposes. I apply pulse width modulation on the ENA and ENB inputs for setting a suitable motor voltage. The L298N provides adequate current to my motor. My own setup doesn't cause my L298N to get hot.
At the moment, I'm applying approximately 20% duty cycle for the PWM, with 490 Hz PWM frequency (or there-abouts).
I got some links to diode protection that I am using in my circuits, mentioned in:
http://forum.arduino.cc/index.php?topic=379829.msg2660107#msg2660107
The diode protection circuits shown in:
I made a video of the L298N driving the NEMA17 at:
The code I used for just making the stepper spin around 3 times in either direction with the MEGA 2560 (I modified Scott Fitzgerald's code) is shown below. Arduino MEGA Pin 9 controls In1 of the L298N, while In2 is an inverted version of Pin 9 (obtained via a logic inverter gate. Pin 10 drives In3, while an inverted version of Pin 10 (through an inverter gate) drivers In4. In1 and In2 relate to coil 1, while In3 and In4 related to coil 2. The logic inverter gates are inside the DIL-chip on the bread-board (shown in the video).
int analog_pin_2 = 2;
int analog_pin_3 = 3;
unsigned long timestart = 0;
unsigned long delta_t = 0;
unsigned long now = 0;
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pins 9 and 10 as an outputs.
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
int myEraser = 7; // this is 111 in binary and is used as an eraser
TCCR3B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR3B to 0; the '3' is associated with timer #3
int myPrescaler = 3; // this could be a number in [1 , 6]. In this case, 3 corresponds in binary to 011.
TCCR3B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR3B with our new value 010, prescaler = 2, giving 4 kHz PWM frequency.
pinMode(analog_pin_2, OUTPUT);
pinMode(analog_pin_3, OUTPUT);
analogWrite(analog_pin_2, 50);
analogWrite(analog_pin_3, 50);
digitalWrite(9, HIGH); //initialisation
digitalWrite(10, HIGH);
delay(1000);
}
// the loop function runs over and over again forever
void loop() {
ccw(4, 150);
delay(1000);
cw(4, 150);
delay(1000);
}
void ccw(int period_ms, int rev_num_by50) {
while (rev_num_by50 > 0) {
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
delay(period_ms);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(period_ms);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
delay(period_ms);
digitalWrite(9, HIGH); //anti-clockwise sequence
digitalWrite(10, HIGH);
delay(period_ms);
rev_num_by50 -= 1;
}
}
void cw(int period_ms, int rev_num_by50) {
while (rev_num_by50 > 0){
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
delay(period_ms);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(period_ms);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
delay(period_ms);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
delay(period_ms);
//digitalWrite(9, HIGH);
//digitalWrite(10, HIGH);
//delay(period_ms);
rev_num_by50 -= 1;
}
}
}