1
\$\begingroup\$

I have paired up L297 and L298 together to make a bipolar stepper driver. My schematics are : enter image description here

I have hooked up the step and direction pin number 4 and 5 respectively on Arduino. I am using a 5V power supply from a DC adaptor

The code I'm using is:

#define stepPin 4
#define dirPin 5

void setup() {
    Serial.begin(9600);
    Serial.println("Starting stepper exerciser.");

    pinMode(stepPin, OUTPUT);
    pinMode(dirPin, OUTPUT);

    digitalWrite(dirPin, HIGH);
    digitalWrite(stepPin, LOW);
}

void loop() {
    int i, j;

    for (i=1000; i>=200; i-=100) {
        Serial.print("Speed: ");
        Serial.println(i);

        for (j=0; j<2000; j++) {
            digitalWrite(stepPin, HIGH);
            delayMicroseconds(i);
            digitalWrite(stepPin, LOW);
            delayMicroseconds(i);
        }
        delay(500);
        digitalWrite(dirPin, !digitalRead(dirPin));

        for (j=0; j<2000; j++) {
          digitalWrite(stepPin, HIGH);
          delayMicroseconds(i);
          digitalWrite(stepPin, LOW);
          delayMicroseconds(i);
        }
        delay(1000);
        Serial.println("Switching directions."); 
        digitalWrite(dirPin, !digitalRead(dirPin));
    }
}

I am using NEMA17 bipolar 5V motors , the data sheet can be found here : datasheet

Motor specs are here

I have also tried L297 with L293d , but the things aren't working the way they should.

Most probably the issues are with the oscillator or the clock pin (may be the pulse is not generating ), before posting the question , I had a quick google search which showed me I was not the only onne facing this issue.

\$\endgroup\$
10
  • \$\begingroup\$ What is the power source for the motors? Is the current capacity enough? What is the current limit you have set for each coil? \$\endgroup\$
    – alexan_e
    Jan 4, 2014 at 10:56
  • \$\begingroup\$ Power source is 5V (already mentioned in question ) , I have used 22k resistors for current sense pins , I'm only a novice and made the circuit following a schematic on web , now it seems current sense pins determines the amount of current that can go into L298 . Also I tried vaarious combinations of resistor still no luck \$\endgroup\$
    – thebugger
    Jan 4, 2014 at 11:17
  • 1
    \$\begingroup\$ 22K is too large, you barely drive the motors with a few mA. Power source is 5V (already mentioned in question ) yes but you didn't specify if this was only for L297 and your schematic shows 36v supply for L298 so I can't make assumptions. So you drive L297/L298 with the same 5v that you use for the Arduino, what is the max current it can provide? Also what is the Vref applied in pin #15 of L297? \$\endgroup\$
    – alexan_e
    Jan 4, 2014 at 11:36
  • 1
    \$\begingroup\$ Surely one of the problems you have is the 22K sense resistors(RS, RS2). Depending on the current you want to use for the motor coils the supply current may or may not be enough. You can run them fine if you choose sense resistors for say 300mA/coil but not if you choose to drive the motor with 1A/coil or so. Also the datasheet lists several motors, what are the current specs for your specific one? You also didn't specify what is the Vref applied in pin #15 of L297. The actual schematic you have used would be helpful because currently the one you show is the generic one of the datasheet. \$\endgroup\$
    – alexan_e
    Jan 4, 2014 at 11:54
  • 1
    \$\begingroup\$ There is nothing wrong with the schematic, after all it is the reference design of the chip manufacturer. You need to find a tutorial about motor driving rather than doing random things in order to make it work. Tutorials like this. A 9v battery is not sufficient to provide the motor current for more than a few minutes. \$\endgroup\$
    – alexan_e
    Jan 4, 2014 at 13:43

1 Answer 1

2
\$\begingroup\$

Try this code, and change pin number to your like. if this code work, likely the problem is in the delayMicroseconds number, some Stepper motor only work on higher than 300 and some on more higher number. when delayMicroseconds number too low, it will stall and sometime only humming.

when powerup, motor will spin clockwise, and if you push button, it's will delay 1 second, and start spin counterclockwise.

int val = 0; // push value from buttons pin
int jalan = 0;//moving status
int ditekan = 0;//push status
void setup() 
{
  pinMode(12, OUTPUT); //Enable
  pinMode(11, OUTPUT); //Step
  pinMode(10, OUTPUT); //Direction
  pinMode(4, INPUT); //push button

  digitalWrite(12,LOW);

}

void loop() 
{
  val = digitalRead(4);// read the push button value
  if(val == HIGH){
    ditekan = 1-ditekan;
    delay(1000);
  }
jalan = val;
if(ditekan == HIGH) {

    digitalWrite(10,HIGH);
    digitalWrite(11,HIGH);
    delayMicroseconds(500);
    digitalWrite(11,LOW);
    delayMicroseconds(500);
    } else {
    digitalWrite(10,LOW);
    digitalWrite(11,HIGH);
    delayMicroseconds(500);
    digitalWrite(11,LOW);
    delayMicroseconds(500);
    }
    //delay(1);
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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