comunicating between Arduinos

Hi
Please can someone suggest the best way to connect and send data between two arduinos, at the moment I have them connected via and I2c link( directly wired) and tried using the wire library to send data between them but not with much success.

I would like to send int values greater than 255 between the two boards to indicate what each board is doing. along with actual sensor data like the distance to an object returned from a ultrasonic sensor as an int

e.g send the int value 2034
might represent a sensor reading of 34
the 2 indicating its a sensor reading and the following 3 digits being available for the reading itself.

many thanks

Hi Richard
thanks for the reply
I have been able to send bytes across form one to the other using the wire examples supplied with the arduino.
I am strugling with how to send an int value from one to the other and decode it to an int the other side. when experimenting i carnt get passed the value 255 with the current code.

if you could tell me how to send the data and decoded it the other end that would be great. i was figuring on some basic maths to get at the data i need from the protocol.

thanks again

hi
the code i was changing was that supplied in the arduino wire example and is as follows

on the receiving end

#include <Wire.h>

void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}

void loop()
{
delay(100);
}

void receiveEvent(int howMany)
{

int x = Wire.receive(); // receive byte as an integer
Serial.println(x); // print the integer

}

and on the transmitting end

#include <Wire.h>

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
}
byte x=0;

void loop()
{
Wire.beginTransmission(4);
Wire.send(x);
Wire.endTransmission();
x++;
delay(500);
}

I have supplied pretty much the example code i have only took a while loop out for reading in some txt on the reciving end
as I am unsure how to modify this to convert int to bytes to send.
and how to reconstruct them on the receiving end.

Is the wire the best command for doing this or should i be looking else where. sorry if this seams trival

many thanks

Thanks for your reply
i was hoping it was going to be a bit easier than this
i figured on fixed lenght packets of ints just not sure how to transmit and reassemble them
if you could suggest the best commands for formating it would be a great help and i will go off and starting looking again and trying to get it to working
many thanks

Hi

  1. many thanks for your time.
  2. sorry i realized i had posted this question in the wrong section just after posting it but its the first time i have used this forum.
  3. the link / discussion you pointed to has fixed the problem so if anybody is looking for a solution to this problem check th link supplied by Richard

thanks again