Sending data between two ardunio's

Hi!

So I have two Ardunio's, One UNO and one MEGA2650. I'm looking for an organised way of getting the two devices to communicate. Effectively what I am trying to do is getting the UNO to package sensor data, send it to the MEGA2650 over serial. Let the MEGA2650 process it with its own data, then return a set of instructions to the UNO. The UNO is operating as a motor driver running PID control and managing a set of 5 IR Range sensors. So I will be transmitting two encoder counts, Two Values from the PID control and 5 IR Range signals.

However I want to know what the most efficient/effective way is to package, send and un-package all this data?

Thanks!

How far apart are they?

EasyTransfer

They are operating within the same enclosure and the serial links are made using standard Jumper wire.

Chagrin:
EasyTransfer

That looks to be exactly what I need, So in effect the library is making shared variables between both micro controllers?

Pack it up into an array, send the array. Put a simple start character or two (0xAA 0x55, something that is not likely to occur in your data) so the receiving side stays in sync.

Receive the array, use the data directly.

How many bytes are you sending in each direction?

Quote me if i am wrong, but im assuming:

7 integers = 14 Bytes
2 long's = 8 Bytes

Totaling 22 Bytes?

jonsmith9847:
Quote me if i am wrong, but im assuming:

7 integers = 14 Bytes
2 long's = 8 Bytes

Totaling 22 Bytes?

jon,

Check out this thread: Sending Arrays between Arduino's

chuck.

You may find some useful ideas in Serial Input Basics

...R

jonsmith9847:
That looks to be exactly what I need, So in effect the library is making shared variables between both micro controllers?

Yup. With a sync byte like Crossroads describes as well as a CRC check (to catch transmission errors).

jonsmith9847:
They are operating within the same enclosure

Wouldn't it be simpler to get the Mega to do the whole job?

Have you tried simple serial code like below?

//zoomkat 3-5-12 simple delimited ',' string tx/rx 
//from serial port input (via serial monitor)
//and print result out serial port
//Connect the sending arduino tx pin to the receiving arduino rx pin. 
//Connect the arduino grounds together. 
//What is sent to the tx arduino is received on the rx arduino.
//Open serial monitor on both arduinos to test
//A diode between the slave tx and master rx is suggested 
//for isolation, with diode band attached to slave tx side. 
//

String readString;

void setup() {
  Serial.begin(9600);
  Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}

void loop() {

  //expect a string like wer,qwe rty,123 456,hyre kjhg,
  //or like hello world,who are you?,bye!,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >0) {
        Serial.print(readString); //prints string to serial port out
        Serial.println(','); //prints delimiting ","
        //do stuff with the captured readString 
        readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

Nick_Pyner:
Wouldn't it be simpler to get the Mega to do the whole job?

Yes it would, however the UNO is embedded in the romeo control board witch includes the motor drivers. Furthermore I need to distribute load between the two voltage regulators (System is running on 12v).