Arduino Uno with L298N

Hi, I am having some issues with the programming for my Robot. As of now I have the Arduino Uno plugged into my laptop for power with PWM pins 3 5 6 9 going to the driver connections IN1 IN2 IN3 IN4 respectively. (check below for the link to the driver board). Also I am supplying the driver with 5V from the Arduino and have 6 AA batteries connected to power the driver itself.

On the driver board I have left the jumpers between ENA-5V , 5V-ENB in and have ran the following code to control the movement of my robot with my laptop.

// Controlling dc motors


char val;         // variable to receive data from the serial port
byte M1F = 3;   // PWM M1 forward
byte M1R = 5;   // PWM M1 reverse
byte M2F = 6;   // PWM M2 forward
byte M2R = 9;   // PWM M2 reverse

void setup()
{
  pinMode(M1F, OUTPUT);     // initialize output pins                           
  pinMode(M1R, OUTPUT);
  pinMode(M2F, OUTPUT);                                
  pinMode(M2R, OUTPUT);
  Serial.begin(9600);       // start serial communication at 9600bps

}

void loop() {
  if( Serial.available() )       // if data is available to read
  { 
    val = Serial.read();
    
    if( val == 'W' || val == 'w' )  //forwards               
    {
      Serial.println("Moving Forwards");  
      digitalWrite(M1F, HIGH); 
      digitalWrite(M1R, LOW);
      digitalWrite(M2F, HIGH); 
      digitalWrite(M2R, LOW);                 
    }
    else if( val == 'S' || val == 's' )  //backwards              
    {
      Serial.println("Moving Backwards");
      digitalWrite(M1F, LOW);  
      digitalWrite(M1R, HIGH); 
      digitalWrite(M2F, LOW); 
      digitalWrite(M2R, HIGH);                   
    }
    else if( val == 'A' || val == 'a' )  //Left         
    {
      Serial.println("LEFT");
      digitalWrite(M1F, LOW);  
      digitalWrite(M1R, HIGH); 
      digitalWrite(M2F, HIGH);    
      digitalWrite(M2R, LOW);              
    }
   else if( val == 'D' || val == 'd' )   //Right            
    {
      Serial.println("RIGHT");
      digitalWrite(M1F, HIGH); 
      digitalWrite(M1R, LOW);  
      digitalWrite(M2F, LOW); 
      digitalWrite(M2R, HIGH);                 
    }    
    else {                 //full stop
      digitalWrite(M1L, LOW); 
      digitalWrite(M1R, LOW); 
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);  
    } 
  }

}

So in the serial monitor I press : 'w' enter, it goes forward; 's' enter, it goes reverse; 'a' enter it goes left; 'd' enter it goes right and if I press any other letter and enter both motors will stop. However there have been some glitches where the Serial monitor freezes and I need to cut power to the Arduino and the motors. I was thinking that maybe it is freezing because there is no delays between the signals. Should I add a delay before each motor movement for example: if both motors are going forward, when I press 'a'(left) there is a one second delay so the motors can stop going forward and then go 'left'.

I was thinking about doing the above, but then I realized that I dont want to have to have to press enter to send signals, I want the motors to go forward when I hold 'w', reverse when I hold 's', left when I hold 'a' and right when I hold 'd' and I want the motors to stop when nothing is pressed. How would I go about doing this?

Also, is it possible to power the Arduino Uno with the L298N driver board so that I can eliminate the need for separate power supplies?

Any help is greatly appreciated, Thanks.

Sainsmart L298N driver

http://www.sainsmart.com/media/catalog/product/cache/1/image/265x265/9df78eab33525d08d6e5fb8d27136e95/1/_/1_11_30.jpg

How would I go about doing this?

Don't use the Serial Monitor. You could write your own application that monitored key events (press and release) and sent serial data only once for each event (send 'W' when the w is pressed, and send 'w' when the w is released). Then, make the Arduino start an action when the upper case letter arrives, and stop that action when the lower case letter arrives.

Thanks for the quick response, any idea where I can find some information on how to write my own applications?

any idea where I can find some information on how to write my own applications?

Gee, I don't know. The internet, maybe? Or, your local library or bookstore is bound to have some information.

LOL, thanks captain obvious, I guess my question wasn’t clear enough.

Does anybody have any links to where I can find information on how to write my own applications?

Does anybody have any links to where I can find information on how to write my own applications?

What programming language(s) do you know? Which do you want to use? On what operating system?

A link to how to write a program using X-Motif and Fortran won't be too useful if you only know C# and Windows.

This is a school project, we have only been taught a minimal amount of C# on Windows. I wrote the code that I have now through researching different codes and examples.until I figured out how to write the code for my project..

Writing my own application seems like it might be way out of my league..

You can use some other kind of terminal emulator like Hyperterminal or perhaps Putty that doesn't require you to press Enter after each character.

As for the freezes, did you connect the grounds of everything together? Do you have filter capacitors near the motors?