Help with sketch needed please

I am trying to build something similar to this Wifi Robot - JBProjects.net but with a tank chassis and replacing the wrt54g with a Sheevaplug running ubuntu and using an arduino duemilanove with a motorshield from here

www.robotbits.co.uk/arduino/arduino-motor-shield-built-/prod_32.html

I seem to have the vb front end talking to the sheeva ok via wifi and trying to pass the commands on to the arduino but my problem is getting the right code on the arduino. I have a basic sketch which demo's the motor shield and I have a sketch for the arduino to speak to the sheeva from jbprojects.net but I have no idea where to start converting the jbprojects sketch to work with the motor shield. Any help would be most appreciated.

sketches follow in next posts

// simple_motor_sketch   version 1.0   J.Luke (RobotBits.co.uk)
//
// A simple sketch to help you get started with the Arduino Motor Shield
// in robotics applications
//
// This example has been written for any mobile robotics platform that uses
// two bi-directional motors controlled by an Arduino and a Motor Shield
//
// This sketch includes a series of functions that perform the different  
// types of movement for your robot including:
//
// forward, reverse, stop, rotate clock-wise, rotate counter clock-wise, 
// turn_left and turn_right 
//
// To program the movement of your robot simply call the functions as needed
// from the main loop
//
// This example loop below moves your robot in a "square" figure or eight
//
// For support, please contact support@robotbits.co.uk


// define the pins used by the motor shield
int speedA = 10;          // pin 10 sets the speed of motor A (this is a PWM output)
int speedB = 11;          // pin 11 sets the speed of motor B (this is a PWM output) 
int dirA = 12;            // pin 12 sets the direction of motor A
int dirB = 13;            // pin 13 sets the direction of motor B

// define the direction of motor rotation - this allows you change the  direction without effecting the hardware
int fwdA  =  LOW;         // this sketch assumes that motor A is the right-hand motor of your robot (looking from the back of your robot)
int revA  =  HIGH;        // (note this should ALWAYS be opposite the fwdA)
int fwdB  =  LOW;         //
int revB  =  HIGH;        // (note this should ALWAYS be opposite the fwdB)

// define variables used
int dist;
int angle;
int vel;

void setup() {                             // sets up the pinModes for the pins we are using
              pinMode (dirA, OUTPUT);         
              pinMode (dirB, OUTPUT); 
              pinMode (speedA, OUTPUT); 
              pinMode (speedB, OUTPUT); 
             }

void stop() {                              // stop: force both motor speeds to 0 (low)
              digitalWrite (speedA, LOW); 
              digitalWrite (speedB, LOW);
             }
             
void forward(int dist, int vel) {          // forward: both motors set to forward direction
              digitalWrite (dirA, fwdA); 
              digitalWrite (dirB, fwdB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (dist);                // wait for a while (dist in mSeconds)
             }
             
void reverse(int dist, int vel) {          // reverse: both motors set to reverse direction
              digitalWrite (dirA, revA); 
              digitalWrite (dirB, revB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (dist);                // wait for a while (dist in mSeconds)              
             }    

void rot_cw (int angle, int vel) {         // rotate clock-wise: right-hand motor reversed, left-hand motor forward
              digitalWrite (dirA, revA); 
              digitalWrite (dirB, fwdB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (angle);               // wait for a while (angle in mSeconds)              
             }
             
void rot_ccw (int angle, int vel) {        // rotate counter-clock-wise: right-hand motor forward, left-hand motor reversed
              digitalWrite (dirA, fwdA); 
              digitalWrite (dirB, revB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (angle);               // wait for a while (angle in mSeconds)              
             }
             
void turn_right (int angle, int vel) {     // turn right: right-hand motor stopped, left-hand motor forward
              digitalWrite (dirA, revA); 
              digitalWrite (dirB, fwdB);
              digitalWrite (speedA, LOW);  // right-hand motor speed set to zero
              analogWrite (speedB, vel); 
              delay (angle);               // wait for a while (angle in mSeconds)              
             }
             
void turn_left (int angle, int vel) {      // turn left: left-hand motor stopped, right-hand motor forward
              digitalWrite (dirA, fwdA); 
              digitalWrite (dirB, revB);
              analogWrite (speedA, vel);
              digitalWrite (speedB, LOW);  // left-hand motor speed set to zero
              delay (angle);               // wait for a while (angle in mSeconds)              
             }
             
void loop() { 
              
              forward (2000, 100);    // move forward for two seconds (2000 mS) at speed 100 (100/255ths of full speed)
              
              rot_cw (325, 100);      // rotate clock-wise for 325 mS (about 90 deg) at speed 100
              
              forward (2000, 100);    // move forward for 2000 mS at speed 100

              rot_cw (325, 100);      // rotate clock-wise for 325 mS at speed 100
              
              forward (2000, 100);    // move forward for 2000 mS at speed 100

              rot_cw (325, 100);      // rotate clock-wise for 325 mS at speed 100
                            
              forward (2000, 100);    // move forward for 2000 mS at speed 100
              
              rot_cw (325, 100);      // rotate clock-wise for 325 mS at speed 100
              
              forward (2000, 100);    // move forward for 2000 mS at speed 100

              rot_ccw (325, 100);     // rotate counter clock-wise for 325 mS at speed 100
  
              forward (2000, 100);    // move forward for 2000 mS at speed 100

              rot_ccw (325, 100);     // rotate counter clock-wise for 325 mS at speed 100
              
              forward (2000, 100);    // move forward for 2000 mS at speed 100

              rot_ccw (325, 100);     // rotate counter clock-wise for 325 mS at speed 100

              forward (2000, 100);    // move forward for 2000 mS at speed 100

              rot_ccw (325, 100);     // rotate counter clock-wise for 325 mS at speed 100              
              
              stop();                 // stop the robot

              delay(1000);            // wait one second (1000 mS) before restarting
            }
*******************************************************************
; Function:  Wifi Robot Arduino Firmware
; Filename:  car_arduino.c
; Author:    Jon Bennett
; Website:   www.jbprojects.net/projects/wifirobot
;*******************************************************************/

#define DEBUG 0
#define WAIT_FOR_START 1

unsigned char incomingByte = 0;
unsigned long loop_count = 0;
unsigned char horn = 32;
unsigned char redLED = 64;
unsigned char greenLED = 128;

unsigned char forward = 1;
unsigned char backward = 2;
unsigned char left = 4;
unsigned char right = 8;

unsigned char PORTB_val;
unsigned char PORTD_val;

unsigned char in_char = 0;

void setup() 
{
//PORTD = digital IO 0-7
//horn, redLED, greenLED

  pinMode(5, OUTPUT);      // sets the digital pin as output
  pinMode(6, OUTPUT);      // sets the digital pin as output
  pinMode(7, OUTPUT);      // sets the digital pin as output

//PORTB = digital IO 8 - 13  
//right, left, backwards, forward

  pinMode(8, OUTPUT);      // sets the digital pin as output
  pinMode(9, OUTPUT);      // sets the digital pin as output
  pinMode(10, OUTPUT);     // sets the digital pin as output
  pinMode(11, OUTPUT);     // sets the digital pin as output
  
  Serial.begin(9600);      // set up Serial library at 9600 bps
  Serial.println("Hello World!");
  PORTD = redLED;               // turn on the red LED
  
  #if DEBUG
      flash_led(3,500);
  #endif
  
  wait_for_start();  //Waits for startup message from router serial port
                               //continues after receiving it.
}


void flash_led(unsigned int count, unsigned int rate)
{
// debug routine that flashes an LED

 int n_count = 0;

 while (n_count < count)
 {
   n_count++;
   digitalWrite(13, HIGH);       // sets the LED on
   delay(rate);                  // waits for a bit
   digitalWrite(13, LOW);        // sets the LED off
   delay(rate);                  // waits for a bit
 }
}

char get_char()
{
//Function that waits for a character from the serial port
//If none are received, it returns 0.
//The timeout is so that if the router stops sending data to the microcontroller,
//the micrcontroller will stop driving the car, rather than just going forever with
//the last command.  Timeout is around 250mS.

  while (loop_count < 30000)
  {
    loop_count++;

    if (Serial.available() > 0)
    {
      incomingByte = Serial.read();
      loop_count = 0;
      return incomingByte; 
    }
  }  
  
  loop_count = 0;
  
  #if DEBUG
        Serial.print('X', BYTE);
  #endif
  
  return 0; 
}

unsigned char wait_for_start()
{
//Waits for startup message from router serial port
#if WAIT_FOR_START

  #if DEBUG
    Serial.println("Waiting...");
  #endif

  while(1)
  {
    if (get_char() == 'j' && get_char() == 'b' && get_char() == 'p' && get_char() == 'r' && get_char() == 'o') 
  { 
    
  #if DEBUG
      Serial.print("Passcode Accepted");
  #endif

      return 0; 
    }
  }
#endif
}

void loop()                       
{  
//Function that processes input from serial port and drives the car based
//on that input.

  in_char = get_char();
  
  //Split byte received in to upper and lower halves.
  PORTB_val = in_char & 0x0F;
  PORTD_val = in_char & 0xF0;
  
  //Make sure the greenLED is turned on now.
  if ((PORTD_val & greenLED) == 0)
  {
    PORTD_val = PORTD_val + greenLED;          
  }
  
  //The following IF statements are sanity checks to make sure that FORWARD and BACKWARD cannot be on at the same time
  //and that LEFT and RIGHT can't be on at the same time.
  if ((PORTB_val & (left + right)) == (left + right))
  {    
    PORTB_val = PORTB_val - right;    
  }
  
  if ((PORTB_val & (forward + backward)) == (forward + backward))
  {
    PORTB_val = PORTB_val - backward; 
  }

  //Write the processed values to the ports.
  PORTD = PORTD_val;
  PORTB = PORTB_val;

  #if DEBUG
    Serial.print(PORTD, HEX);
    Serial.print(PORTB, HEX);
  #endif

}

First off please use the # icon key when posting code.

Next you have to make sure there is no overlap of pins. Your two programs both use pins 10 & 11, so you can't combine them directly. Best bet is if you reassign pins 10 & 11 in the motor sketch to pins 2 & 3.

Then put both setup routines into one, rename the two loop() functions loop1() and loop2(), then have you own loop() that continually calls the other two functions loop1() and loop2().

"First off please use the # icon key when posting code."
My appologies I didnt notice that.

I have just started with the arduino and I realy have no idea where to start. I know that I want to to modify the car_arduino.c file so that it uses the pins stated in the simple motor sketch file and also the different way of controling the motors

I started again from scratch with the arduino sketch for this and I have made some progress in that I seem to be getting comunication through to the arduino now.
However I dont seem to be getting the correct data through to it as when I start everything up and connect I get a series of random movement and then it just stops. Key presses seem to have no effect and I have no way to check what data is getting to the arduino as my serial port is used for the connection to the sheeva.
I am going to post all three scripts and hopefully someone can see an obvios error.

First the vb

Option Explicit
Public direction As String
Public ttime As Integer
Public address As String
Public upstatus, downstatus, leftstatus, rightstatus, hornstatus As Integer
Public output As Integer


Private Sub call_timer_Timer()
    Call motion("manual", upstatus + downstatus + rightstatus + leftstatus + hornstatus)
    'Calls motion module.  Lets it know manual driving and what value to output to the
    'parallel port
End Sub

Private Sub Command1_Click()
  If sock.State = sckClosed Then ' if the socket is closed
    sock.RemoteHost = lbladdress.Text ' set server adress
    sock.RemotePort = "1500" ' set server port
    Label5.Caption = "Connected"
    sock.Connect ' start connection attempt
  Else ' if the socket is open
    sock.Close ' close it
    Label5.Caption = "Not Connected"
  End If
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'Detects if control keys are pressed
    If KeyCode = vbKeyEscape Then End 'Exits
    If KeyCode = vbKeyT Then Call Command1_Click
    If KeyCode = vbKeyUp Or KeyCode = vbKeyW Then: cmd_up.BackColor = &HFF0000: cmd_up.Picture = cmd_up.DownPicture: upstatus = 1
    'If up arrow is pressed or W then change pictures (make it blue) and change upstatus.
    If KeyCode = vbKeyDown Or KeyCode = vbKeyS Then cmd_down.BackColor = &HFF0000: cmd_down.Picture = cmd_down.DownPicture: downstatus = 2
    'If down arrow is pressed or S then change pictures (make it blue) and change downstatus.
    If KeyCode = vbKeyLeft Or KeyCode = vbKeyA Then cmd_left.BackColor = &HFF0000: cmd_left.Picture = cmd_left.DownPicture: rightstatus = 4
    'If left arrow is pressed or A then change pictures (make it blue) and change rightstatus.
    If KeyCode = vbKeyRight Or KeyCode = vbKeyD Then cmd_right.BackColor = &HFF0000: cmd_right.Picture = cmd_right.DownPicture: leftstatus = 8
    'If right arrow is pressed or D then change pictures (make it blue) and change leftstatus.
    If KeyCode = vbKeyH Then hornstatus = 32
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    'Stops output to that direction when key is lifted.
    'Changes pictures back to unactivated (none-blue).
    If KeyCode = vbKeyUp Or KeyCode = vbKeyW Then cmd_up.BackColor = &HFFFFFF: cmd_up.Picture = cmd_up.DisabledPicture: upstatus = 0
    If KeyCode = vbKeyDown Or KeyCode = vbKeyS Then cmd_down.BackColor = &HFFFFFF: cmd_down.Picture = cmd_down.DisabledPicture: downstatus = 0
    If KeyCode = vbKeyLeft Or KeyCode = vbKeyA Then cmd_left.BackColor = &HFFFFFF: cmd_left.Picture = cmd_left.DisabledPicture: rightstatus = 0
    If KeyCode = vbKeyRight Or KeyCode = vbKeyD Then cmd_right.BackColor = &HFFFFFF: cmd_right.Picture = cmd_right.DisabledPicture: leftstatus = 0
    If KeyCode = vbKeyH Then hornstatus = 0
End Sub

Private Sub Form_Load()
    Dim line As String
    'Stores {Arrow with white} pic in .DisabledPicture for each button
    cmd_up.DisabledPicture = cmd_up.Picture
    cmd_down.DisabledPicture = cmd_down.Picture
    cmd_left.DisabledPicture = cmd_left.Picture
    cmd_right.DisabledPicture = cmd_right.Picture
    'Following Opens Config.txt and collect Parallel Port Address and Refresh Rate
    Open CurDir & "\config.txt" For Input As #1
    Line Input #1, line
    Line Input #1, line
    address = line 'Sets parallel port address
    lbladdress.Text = address 'displays address
    call_timer.Interval = 5
    
End Sub
Private Sub sock_Close()
    sock.Close ' has to be
End Sub
  
Private Sub sock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    MsgBox "Socket Error " & Number & ": " & Description
    sock.Close ' close the erraneous connection
End Sub

'Motion Executor
Sub motion(direction As String, ttime As Integer)
    address = Form1.address
    Select Case direction
    Case 1 To 10
    Case "manual"
    'If manual driving, parallel port output required for direction has already
    'been calculated, so output value passed to ttime
    output = ttime
    Case "FF"
        output = 1
    Case "BB"
        output = 2
    Case "RR"
        output = 8
    Case "LL"
        output = 4
    Case "FR"
        output = 9
    Case "FL"
        output = 5
    Case "BR"
        output = 10
    Case "BL"
        output = 6
    Case "SS"
        output = 0
    End Select
    Rem vbOut address, output
    'sock.SendData output & Chr(0)
    If sock.State = sckConnected Then
     If output = &HC Or output = &H1C Then output = output - 8
     If output = &H3 Or output = &H13 Then output = output - 2
     sock.SendData Chr(output + 1) & Chr(0)
      Label5.Caption = Chr(output + 1) & Chr(0)
    Else
        Label5.Caption = "NOT sending data"
    End If
End Sub

Not enough space so next post

C code from sheeva

/*******************************************************************
; Function:  Wifi Robot Server Software
; Filename:  car_server.c
; Author:    Jon Bennett
; Website:   www.jbprojects.net/projects/wifirobot
; Credit:    Based on TCP Server Test Example
;            http://pont.net/socket/index.html
;*******************************************************************/

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* close */
#include <fcntl.h>
#include <string.h>

#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>

#define SUCCESS 0
#define ERROR   1

#define DEBUG 1

#define END_LINE 0x0
#define SERVER_PORT 1500
#define MAX_MSG 100

/* function readline */
int read_line();

int main (int argc, char *argv[]) {
  int fd;
  int sd, newSd, cliLen;
  int result1;

  struct sockaddr_in cliAddr, servAddr;
  char line[MAX_MSG];

        fd = open("/dev/ttyUSB1", O_WRONLY);
      if (fd < 0) 
      { 
            printf("Could not open port.\n"); 
      }

  result1 = write(fd, "jbpro", 5);

  /* create socket */
  sd = socket(AF_INET, SOCK_STREAM, 0);
   if(sd<0) {
    perror("cannot open socket ");
    return ERROR;
  }
  
  /* bind server port */
  servAddr.sin_family = AF_INET;
  servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servAddr.sin_port = htons(SERVER_PORT);
  
  if(bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr))<0) {
    perror("cannot bind port ");
    return ERROR;
  }

  listen(sd,5);
  int count;
      count = 0;
  while(1) {
#if DEBUG
    printf("%s: waiting for data on port TCP %u\n",argv[0],SERVER_PORT);
#endif
    cliLen = sizeof(cliAddr);
    newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen);
    if(newSd<0) {
      perror("cannot accept connection ");
      return ERROR;
    }
    
    /* init line */
    memset(line,0x0,MAX_MSG);
    unsigned char toWrite = 0;
    /* receive segments */
    while(read_line(newSd,line)!=ERROR) {
      count++;      
#if DEBUG
      printf("%d:  %s: received from %s:TCP%d : %s\n", count, argv[0], 
           inet_ntoa(cliAddr.sin_addr),
           ntohs(cliAddr.sin_port), line);
#endif
      char *buf="0";
        //toWrite = line[0];
      toWrite = line[0] - 1; 

      result1 = write(fd, &toWrite, 1); 

      if (result1 != 1)
      {
            printf("Error writing to serial port.\n");
      }

      /* init line */
      memset(line,0x0,MAX_MSG);
      
    } /* while(read_line) */
    
  } /* while (1) */

}


/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING       */
/* this function is experimental.. I don't know yet if it works  */
/* correctly or not. Use Steven's readline() function to have    */
/* something robust.                                             */
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING       */

/* rcv_line is my function readline(). Data is read from the socket when */
/* needed, but not byte after bytes. All the received data is read.      */
/* This means only one call to recv(), instead of one call for           */
/* each received byte.                                                   */
/* You can set END_CHAR to whatever means endofline for you. (0x0A is \n)*/
/* read_lin returns the number of bytes returned in line_to_return       */
int read_line(int newSd, char *line_to_return) {
  
  static int rcv_ptr=0;
  static char rcv_msg[MAX_MSG];
  static int n;
  int offset;

  offset=0;

  while(1) {
    if(rcv_ptr==0) {
      /* read data from socket */
      memset(rcv_msg,0x0,MAX_MSG); /* init buffer */

      n = recv(newSd, rcv_msg, MAX_MSG, 0); /* wait for data */
      if (n<0) {
      perror(" cannot receive data ");
      return ERROR;
      } else if (n==0) {
      printf(" connection closed by client\n");
      close(newSd);
      return ERROR;
      }
    }
  
    /* if new data read on socket */
    /* OR */
    /* if another line is still in buffer */

    /* copy line into 'line_to_return' */
    while(*(rcv_msg+rcv_ptr)!=END_LINE && rcv_ptr<n) {
      memcpy(line_to_return+offset,rcv_msg+rcv_ptr,1);
      offset++;
      rcv_ptr++;
    }
    
    /* end of line + end of buffer => return line */
    if(rcv_ptr==n-1) { 
      /* set last byte to END_LINE */
      *(line_to_return+offset)=END_LINE;
      rcv_ptr=0;
      return ++offset;
    } 
    
    /* end of line but still some data in buffer => return line */
    if(rcv_ptr <n-1) {
      /* set last byte to END_LINE */
      *(line_to_return+offset)=END_LINE;
      rcv_ptr++;
      return ++offset;
    }

    /* end of buffer but line is not ended => */
    /*  wait for more data to arrive on socket */
    if(rcv_ptr == n) {
      rcv_ptr = 0;
    } 
    
  } /* while */
}

Arduino Sketch

int incomingByte =0;  //for incoming data
// define the pins used by the motor shield
int speedA = 10;          // pin 10 sets the speed of motor A (this is a PWM output)
int speedB = 11;          // pin 11 sets the speed of motor B (this is a PWM output) 
int dirA = 12;            // pin 12 sets the direction of motor A
int dirB = 13;            // pin 13 sets the direction of motor B

// define the direction of motor rotation - this allows you change the  direction without effecting the hardware
int fwdA  =  LOW;         // this sketch assumes that motor A is the right-hand motor of your robot (looking from the back of your robot)
int revA  =  HIGH;        // (note this should ALWAYS be opposite the fwdA)
int fwdB  =  LOW;         //
int revB  =  HIGH;        // (note this should ALWAYS be opposite the fwdB)
int dist;
int angle;
int vel;


void setup(){
    Serial.begin(9600);    //opens the serial port, sets data rate to 9600bps
    digitalWrite(6, HIGH);  
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode (dirA, OUTPUT);         
    pinMode (dirB, OUTPUT); 
    pinMode (speedA, OUTPUT); 
    pinMode (speedB, OUTPUT); 
}

void stop() {                              // stop: force both motor speeds to 0 (low)
              digitalWrite (speedA, LOW); 
              digitalWrite (speedB, LOW);
             }
             
void forward(int dist, int vel) {          // forward: both motors set to forward direction
              digitalWrite (dirA, fwdA); 
              digitalWrite (dirB, fwdB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (dist);                // wait for a while (dist in mSeconds)
             }
             
void reverse(int dist, int vel) {          // reverse: both motors set to reverse direction
              digitalWrite (dirA, revA); 
              digitalWrite (dirB, revB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (dist);                // wait for a while (dist in mSeconds)              
             }    

void rot_cw (int angle, int vel) {         // rotate clock-wise: right-hand motor reversed, left-hand motor forward
              digitalWrite (dirA, revA); 
              digitalWrite (dirB, fwdB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (angle);               // wait for a while (angle in mSeconds)              
             }
             
void rot_ccw (int angle, int vel) {        // rotate counter-clock-wise: right-hand motor forward, left-hand motor reversed
              digitalWrite (dirA, fwdA); 
              digitalWrite (dirB, revB);
              analogWrite (speedA, vel);   // both motors set to same speed
              analogWrite (speedB, vel); 
              delay (angle);               // wait for a while (angle in mSeconds)              
             }
             
void turn_right (int angle, int vel) {     // turn right: right-hand motor stopped, left-hand motor forward
              digitalWrite (dirA, revA); 
              digitalWrite (dirB, fwdB);
              digitalWrite (speedA, LOW);  // right-hand motor speed set to zero
              analogWrite (speedB, vel); 
              delay (angle);               // wait for a while (angle in mSeconds)              
             }
             
void turn_left (int angle, int vel) {      // turn left: left-hand motor stopped, right-hand motor forward
              digitalWrite (dirA, fwdA); 
              digitalWrite (dirB, revB);
              analogWrite (speedA, vel);
              digitalWrite (speedB, LOW);  // left-hand motor speed set to zero
              delay (angle);               // wait for a while (angle in mSeconds)              
             }


void loop(){
    //send data only when you recieve it:
    if (Serial.available() >0) {
      //read the incoming byte:
      incomingByte =Serial.read();
      incomingByte = incomingByte - 48;
      
      //say what you got:
     Serial.print("I recieved ");
     Serial.println(incomingByte, DEC);
     
    }
    
    switch (incomingByte) {
      case 1 :
        rot_ccw(100, 100);
        break;
      
      case 2 :
        rot_cw(100, 100);
        break;
      case 3 :
        forward (100, 100);
        break;
      case 4 : 
        reverse (100, 100);
      break;
      case 5 :
        turn_right (100, 100);
      break;
      case 6 :
        turn_left (100, 100);
      break;
      case 7 : 
        forward (100, 255);
        break;
      case 8 :
        reverse (100, 255);
      break;
      case 9 :
        stop();
      break;
    }
    
        
}

I have no way to check what data is getting to the arduino as my serial port is used for the connection to the sheeva.

Serial communication is two way. Why can't you have the Arduino echo the data that it received? At least then you might know what data was getting to the Arduino.

It appears that you do have Serial.print() statements in the Arduino sketch. Aren't you getting anything back?

I guess I can answer that question. You open the serial connection to the Arduino write-only. Is there some reason for that?

There are statements in the VB app that show something was sent, but you didn't share any of that data with us.

There are statements in the C code that echo data. You didn't share any of that data with us, either.

I changed the vb app so it now shows both what character is being selected and what is being sent and these seem to be ok. This is the output from the c prog while cycling through a couple of keys.

410:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
411:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
412:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
413:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
414:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
415:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
416:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
417:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
418:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
419:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
420:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
421:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
422:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
423:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
424:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
425:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
426:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
427:  ./carserver: received from 192.168.1.107:TCP1071 : ^C
428:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
429:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
430:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
431:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
432:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
433:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
434:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
435:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
436:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
437:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
438:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
439:  ./carserver: received from 192.168.1.107:TCP1071 : ^A
440:  ./carserver: received from 192.168.1.107:TCP1071 : ^A

The final character e.g the ^A doesnt show in the terminal for some reason but does when I redirect the output to a file.

Does not seem right to me that I am sending out a integer from the vb prog and getting a ^A back from the arduino sketch to the c prog

"You open the serial connection to the Arduino write-only" I am a newbie to this how would I change it to read/write.

If there is anything else you need to know then just let me know.

Oh and i noticed that if I connect the arduino direct to my laptop I can send the corresponding numbers from the arduino sketch to it via the serial monitor and the motors will do as they are supposed to that way.

Thanks a lot for your help

Does not seem right to me that I am sending out a integer from the vb prog and getting a ^A back from the arduino sketch to the c prog

     sock.SendData Chr(output + 1) & Chr(0)

You are NOT sending an integer. You are converting the integer to a character and sending the character, followed by a NULL. That makes it a string.

This is the code to open the connection write-only.

fd = open("/dev/ttyUSB1", O_WRONLY);

Change the 2nd argument to _O_RDWR to open the stream for reading, too.

Oh and i noticed that if I connect the arduino direct to my laptop I can send the corresponding numbers from the arduino sketch to it via the serial monitor and the motors will do as they are supposed to that way.

What your application is doing is saying "Send the nth position in the ASCII collating sequence", where n is output + 1. What the serial monitor is saying is "Find the position in the ASCII collating sequence that corresponds to the the value n and send that position".

Quite a bit different values get sent. Suppose that output is 3. You are sending a 4. The serial monitor is sending a '4' (or 52).

On the receiver, you subtract 48 from the read in value. When the value comes from the serial monitor, 52 - 48 = 4. When the value comes from your program, 4 - 48 = -44.

Since you don't have a case for -44, nothing happens.

Yeeha all seems to be working now. Got about a three second delay from when I press a button to when the command is executed but im sure that can be ractified some how.

Thanks for all your help. You made me a happy bunny :smiley:

Got about a three second delay from when I press a button to when the command is executed but im sure that can be ractified some how.

On the Arduino, each of your motion functions (forward(), reverse(), etc.) contains a delay() call. During that delay, no serial reading occurs. That will make your robot jerky and slow to respond.

There are two ways around the problem. One is to use millis() to see what "time" it is, record when things were last done, and determine if it is time to do something else. There is a Blink Without Delay example that illustrates this point.

The other way is to just get rid of the delay() calls. When the robot is directed, via serial input, to begin moving in a specific direction, keep doing that until directed otherwise. This might not work so well for turns, but forward, reverse, and stop should not be specific duration events.