ArduinoGeneral

DFRduino L298p Shield Reverse Problems

userHead jakfourie 2013-05-19 04:08:19 5847 Views4 Replies
Hi,

I'm having trouble getting the motors to reverse. I tried different motors and reversing the polarity works.

Any help would be highly appreciated.
2013-05-23 08:01:38 Thanks Jose,

It didn't work initially but after I decided to stack the boards, instead of using  jumper wires, it worked.

I'm guessing it must have been a floating ground.
userHeadPic jakfourie
2013-05-23 00:12:34 Hey Jakfourie,

I think the backward function is not right, try this:

    //Backward
    digitalWrite(M1,LOW); 
    digitalWrite(M2, LOW);     
    analogWrite(E1, 100);  //PWM Speed Control
    analogWrite(E2, 100);  //PWM Speed Control
    delay(2000);  //2 seconds

You can also increase turn speed, by applying the same formula:

Basically the HIGH and LOW sets the direction of the motor, and the number (E2, 100) will set the speed.
You can go up to 255, so you can play with different speeds for getting different results. I tend to preffer lower speeds since make other things easier, but for some tasks speedy turns are nice.
You set one motor forward and the other one backward, this will let you turn in place without moving from the spot

Best,
Jose
userHeadPic Jose
2013-05-21 07:00:12 Hi Jose,

The code below is what I'm using with this shield on its own.
[url=https://www.dfrobot.com/wiki/index.php?title=Arduino_Motor_Shield_%28L298N%29_%28SKU:DRI0009%29]https://www.dfrobot.com/wiki/index.php?title=Arduino_Motor_Shield_%28L298N%29_%28SKU:DRI0009%29[/url]

[code]//Arduino PWM Speed Control?
int E1 = 6; 
int M1 = 7;
int E2 = 5;                       
int M2 = 4;                         

void setup()
{
    pinMode(M1, OUTPUT); 
    pinMode(M2, OUTPUT);
    pinMode(E1, OUTPUT); 
    pinMode(E2, OUTPUT);
}

void loop()
{
    //Forward
    digitalWrite(M1,HIGH); 
    digitalWrite(M2, HIGH);     
    analogWrite(E1, 100);  //PWM Speed Control
    analogWrite(E2, 100);  //PWM Speed Control
    delay(2000);  //2 seconds
   
    //Backward
    digitalWrite(M1,HIGH); 
    digitalWrite(M2, HIGH;     
    digitalWrite(E1, HIGH);  //PWM Speed Control
    digitalWrite(E2, HIGH);  //PWM Speed Control
    delay(2000);  //2 seconds
   
   
    //Left Turn
    digitalWrite(M1,HIGH); 
    digitalWrite(M2, HIGH);     
    analogWrite(E1, 100);  //PWM Speed Control
    analogWrite(E2, 0);  //PWM Speed Control
    delay(2000);  //2 seconds
   
    //Right Turn
    digitalWrite(M1,HIGH); 
    digitalWrite(M2, HIGH);     
    analogWrite(E1, 0);  //PWM Speed Control
    analogWrite(E2, 100);  //PWM Speed Control
    delay(2000);  //2 seconds
 
    //Wait
    digitalWrite(M1,LOW); 
    digitalWrite(M2, LOW);     
    analogWrite(E1, 0);  //PWM Speed Control
    analogWrite(E2, 0);  //PWM Speed Control
    delay(2000);  //2 seconds
 
 
}
[/code]

Everything works fine except the backwards portion.

Thank you in advance
userHeadPic jakfourie
2013-05-20 20:50:30 Hi,

Can you send your code and a picture of your hardware setup?
What motor driver are you using? and what other modules are you using if any?

Best,
Jose
userHeadPic Jose