Best Method to Connect two or more Arduino's?

I have Arduino Duemilanove, Uno and Mega.
Each Arduino has one or more shields and will be running a sketch perfoming it's own task. I like to be able to share data such as variables.
I have one Arduino that has a motor shield with very few pins availble for sensors, GPS etc...

Any suggestions on the best method to connect two or more Arduinos so I can pass data between them?

Thanks

I2C, look it up in the playground, there is an Arduino Master Slave sketch in the examples.

I like to be able to share data such as variables

Not possible unless you do it explicitly.

You need to portion out which device does what, and what data it needs to perform that task.
If the data is sourced on the other device, then decide how often you need that data to be updated.
It is not a trivial problem, and simple C is no the language to express it in.

And what about using SoftwareSerial to share variables & data

Interesting...so you are suggesting to use the TX & RX pins. I wonder how I would do three mics.

My motor controller takes most of my pins. I though about adding additional Arduinos for wireless, microSD, sendors, GPS ...

My motor controller takes most of my pins.

What kind of motor controller is it? Typically, a motor controller only takes 4 pins to control two motors.

SoftwareSerial can use any digital pin, not just the 0 and 1, I do not know if the SoftwareSerial read is a locking operation.

Anyways, maybe you can chain the 3 mics with a unidirectional network:
---> rx arduino1 tx ---> rx arduino2 tx ---> rx arduino3 tx --->

And depending of you requeriments, the serial messages can contain the destination, for example

0x00 0x00 destination_byte value_byte1  value_byte2  value_byte3 ...

:stuck_out_tongue: and if I am not the destination, just echo the message to the next arduino. For a small group of arduinos the overhead is very small. This way you just require 2 pins probably unused pins.

There must be a 1000 ways to do this.

One thing to do is partition your application so that not much needs to be shared if that's possible, that will reduce the bandwidth required and the complexity.

eried's method is good, you can even feed the last Tx back to the controlling uC and get data returned as well as send commands.

Another method is some form of multidrop with or without a master controller (more complicated though).

Other things to consider are the distance between the Arduinos and the rate at which you need to send commands and/or get data. This will dertermine the type of physical layer you use, for example I2C will not be good if they are 100m apart, but OK for a short distance, whereas RS-485 is good for 1000s of feet.

So you need to define the project a bit more.


Rob

Thanks everyone for the respones. I see I have a number of options. The motor controls 4 motors and 2 servos which I think I picked up at the RobotShop. I think only one digital pin all 5 analog pins are left.
Actually it works well in my initial testing.

I'm trying to make a lawnmower, a fun project to try so I have many input and output devices to add. Start small and build as I go along.

I will try the options in the new year and write back my results.
Interesting to hear from anyone that has worked on project like this.

Definitely don't want to buy an existing robot lawnmower. Fun is building it myself.

if you just trying to be right next to each other you need to try to do it over basic serial if you can if not you will have to dedicate a few pins for data. if you just want to make it easy just get some XBee wirless stuff and make a mesh network.But if you just that good with visual basic for windows you can make your own data swapign network ill look in to the usb shield form that.