Go Down

Topic: l298p shield & serial control (Read 836 times) previous topic - next topic


Hi all,

I am pretty new to C and the arduino. I am looking to control two channels via the l298p motor shield on top of an arduino uno with atmega 328.

The chassis I'm using has four DC motors and I have the left two motors wired together, and the right respectively. I'm looking to code basic forward, backward, left or right functions.

Essentially, left or right would run the sided in opposite directions to turn my robot. forward and reverse would just be all ahead fordward or reverse.

So far I have forward, but how would I handle the other directions? Should I nest them in the same loop?

//Arduino PWM Speed Control?
int E1 = 6;
int M1 = 7;
int E2 = 5;
int M2 = 4;
void setup()
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
while (! Serial);
Serial.println("Enter the Direction")
void loop()
if (serial.available()))
int forward = Serial.parseInt();
if (forward = F)
digitalWrite(M2, HIGH);
analogWrite(E1, 100); //PWM Speed Control
analogWrite(E2, 100); //PWM Speed Control

Thanks in advance!



Search my recent posts, I did just what you are looking for for someone else.
Needed a little tweaking to compile right, but it was very close.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up