Hi guys,
I'm trying to build a simple 2-wheel robot and trying to get my L298P motor driver to work properly.
However, the sketch only work partially, here's my setup and sketch.
int motorLE = 7;
int motorLI = 6;
int motorRE = 5;
int motorRI = 4;
void setup() {
pinMode(motorLI, OUTPUT);
pinMode(motorRI, OUTPUT);
}
void loop() {
int value;
for(value = 0 ; value <= 250; value+=5)
{
digitalWrite(motorRI,LOW);
analogWrite(motorRE, value);
digitalWrite(motorLI,LOW);
analogWrite(motorLE, value);
delay(100);
}
}
- Arduino Mega 2560, using a 12V power supply
- L298P motor controller board, using a 7.4V Lipo battery, connected to the VSS and Ground
- 2x tamiya motors
There is a Input and Enable for each motor, I connected them to my PWM ports on the 2560.
The motors wont move if I dont short the VMS=VSS pins together (can anyone tell me why?), so well then I connected them.
Now the motors are working, but only under certain conditions:
MotorA Input | MotorB Input | Result |
LOW | LOW | Motors move in the same direction |
HIGH | HIGH | Both Motors stopped moving, one of them shaking |
LOW | HIGH | Motors move in the opposition direction |
LOW | LOW | Both Motors stopped moving |
And if I run the sketch above, only one motor will change its speed according to the loop, the other just keep spinning at the same speed.
I tried different wiring and codes but still cant crack this, any clue?