Need help- High School project

Hello All. I have been working with Arduino and another micro-controller called the uVGA-II made my 4D-Systems as part of an Independent Study project at my high school. I seem to have hit a wall and my instructor lacks the knowledge to give me the aide I need so I have come to these forums! What I am attempting to do is to read a number from the serial monitor and store the number on my Arduino Mega. I did some reading and believe I am retrieving the numbers correctly from the serial monitor. I then want to send this int over a serial connection to the second micro-controller. To do this I was trying to use bit shift operators to send the least significant byte then the most significant byte (I may have those confused. This is where I am stumped). I then attempt to receive those numbers on the uVGA-II and turn them back into an int by reversing what I did with the bit shift earlier. Once I have the int on the uVGA-II I print it to a VGA monitor.

This is the code I have on the Arduino Mega

int toPrint;

void setup()
{
  Serial.begin(19200);

  Serial3.begin(19200);
  Serial3.flush();       
  delay(1200);      // wait for uVGA to power up
}

void loop()
{
  if(Serial.available() > 0)
  {
    toPrint = serReadInt();
  }

  Serial.println(toPrint);

  send16(toPrint);
}

int serReadInt()
{
  int i, serAva;                           // i is a counter, serAva hold number of serial available
  char inputBytes [7];                 // Array hold input bytes
  char * inputBytesPtr = &inputBytes[0];  // Pointer to the first element of the array

  if (Serial.available()>0)            // Check to see if there are any serial input
  {
    delay(5);                              // Delay for terminal to finish transmitted
    // 5mS work great for 9600 baud (increase this number for slower baud)
    serAva = Serial.available();  // Read number of input bytes
    for (i=0; i<serAva; i++)       // Load input bytes into array
    {
      inputBytes[i] = Serial.read();
    }
    inputBytes[i] =  '\0';             // Put NULL character at the end
    return atoi(inputBytesPtr);    // Call atoi function and return result
  }
  else
    return -1;                           // Return -1 if there is no input
}

void send16(word value)
{    
  Serial.print(value);
  Serial.print(" ");
  Serial.println(value >> 8);

}

And this is the code on the uVGA-II. It is written in a language called 4DGL.

#platform "uVGA-II_GFX2"

#constant PORT COM0
#constant BAUD_RATE 19200/10
#constant BUF_SIZE 200

func main()

    var toPrint;
    var private combuf;

repeat
    if(!combuf)
        com_SetBaud(PORT, BAUD_RATE);                                                                   // set port and baud rate
        combuf := mem_Alloc(BUF_SIZE);                                                                  // allocate memory for com buffer
        #IF PORT == COM0
            com_Init(combuf, BUF_SIZE, 0);                                                              // set up the buffered comms
        #ELSE
            com1_Init(combuf, BUF_SIZE, 0);                                                        // set up the buffered comms
        #ENDIF
    endif

    if(com_Count >= 2)
        toPrint := getWord();
    endif

    print(toPrint);
forever

endfunc

func getWord()
    var a, w;

    gosub getByte;
    a := w;
    gosub getByte;
    w := a | w<<8;

getByte:
    while((w:=serin()) < 0);
    endsub;

    return w;

endfunc

I have really hit a wall here. The issue I'm having is that I can receive the input from the serial monitor, it stores as an int and then I attempt to send it as two bytes. When I attempt to display it all I get is 0's which I'm assuming means the signal isn't being sent properly. I currently have TX3 (pin 14) attached to the RX pin on the uVGA and I have RX3 (pin 15) attached to the TX pin on the uVGA. I won't be able to stay much longer tonight so I will answer any questions about clarification tomorrow morning. I just wanted to get this up because I haven't made much progress in the past week dealing with this issue. Thank's to everyone who helps out ahead of time. If my project turns out the way I hope it will I might come back and put up some sort of follow up. Thanks!

  Serial.print(value);
  Serial.print(" ");
  Serial.println(value >> 8);

The print methods convert the integer to a string to send. You want to be using Serial.write().

Oh I had forgotten to change that. I had been printing to the serial monitor to debug and i was using that. I deleted the wrong part. It should have said:

Serial3.write(value);
Serial3.write(value >>8);

Thanks for pointing that out.

You can get rid of the pointer by just doing this:

    return atoi(inputBytes);    // Call atoi function and return result

However I don't particularly like the loop and the delay inside the loop. Rather than tweaking the delay it is better to make a loop that always works.

PaulS usually has examples of that sort of thing, and I have suggestions here:

I really don't like the serReadInt() function. It will not reliably read anything. There may be between 1 and 32 bytes in the buffer when the function is called, yet it assumes that there is exactly the right number of bytes in the buffer. If I want to write 2 bytes to it, but the function happens to run when there is 1 byte in the buffer, it will do the wrong thing.

I would decide on either a specific length for messages, or a terminating character for messages, and read into a buffer until I have what's known to be a full message, then look at that message.
Another option is to send a length byte first, and then read exactly that many bytes before you decide you have a message.

See this for sending and receiving numbers:

http://arduino.cc/forum/index.php/topic,99225.0.html