UARTs are probably the easiest method to use to communicate between two Megas. With a common GND connection between them I can't see any obvious problems but you haven't provided much detail with which to work up an opinion.
I apologize blackfin. Im trying to communicate sensor data to determine setting some led pins to high at certain intervals. Not sure yet but im thinking i mihht need to have an RTC running to collect the data and then set cobditions in the code that would tell when the pins will be set to high. Im still fiddling around with the code so i havent even gotten far enough to post it.
Could you please briefly explain UART vs ICSP in your own words as far as differences.
I2c from what i understand is best used with registers and have a limit of the type of data they can transmit. The limit being simply either on/off.
Icsp is more robust in that it can send "bytes"
Uart i cannot remember reading anything on.
I suppose it might be worth noting that i would like to add logging, not sure if this helps determine the comms method
The simplest for a new user is serial. The mega has 4 hardware serial ports. One is used to upload code and communicate with the serial monitor for program output and debugging. That leaves 3 for other uses.
The serial input basics tutorial is a start at learning serial communication. Hardware serial can be very fast, over 500000 baud.
ICSP is In Circuit Serial Programming. ICSP is not for communication.
s1lv3r0n3:
I apologize blackfin. Im trying to communicate sensor data to determine setting some led pins to high at certain intervals. Not sure yet but im thinking i mihht need to have an RTC running to collect the data and then set cobditions in the code that would tell when the pins will be set to high. Im still fiddling around with the code so i havent even gotten far enough to post it.
Could you please briefly explain UART vs ICSP in your own words as far as differences.
ICSP is in-circuit serial programming and is not what you want.
UART, I2C and SPI are the common Arduino interface protocols. There are others (e.g. CAN) but I wouldn't worry about them atm.
I2C is pretty good (the "I2" means Inter-Integrated Circuit communications) but imo it carries an unnecessary overhead when communicating between two microcontrollers. It's more useful for a microcontroller talking to, say, a display or a temperature sensor. It's relatively slow (100kbps typ, 400kbps in some application) and is a master/slave relationship. Communication is half-duplex only, if you want to think about it that way; a master issues address and command info and continues clocking to RX data from the slave.
UART is asynchronous meaning you only need a single-line for one way communications or two lines for full-duplex (simultaneous RX and TX.) The Mega has multiple serial ports. You can connect Serial1 TX of Mega 'A' to the Serial1 RX of Mega 'B' and vice-versa ('A' RX to 'B' TX) and have a Mbps serial interface. Best of all the API is super-simple for serial.
SPI is a master/slave protocol as well and can be bidirectional. It can also be super-fast. Given the options, I would say that UART or SPI would be the ones from which to choose, heavily favoring UART for it's simplicity unless you have compelling reasons to not use it.
I2c from what i understand is best used with registers and have a limit of the type of data they can transmit. The limit being simply either on/off.
I2C transfers bytes of any kind (e.g. an LCD might use such an interface to receive image information) but the software layer is more complex than simply doing Serial1.write(...) and Serial1.available() checks.
If you want to use Serial have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
TomGeorge:
How far apart are the two controllers?
What link distance do you need?
To me, the more germane question is - why do you want to make matters more difficult for yourself by introducing a second microcontroller and having to figure out communications between them?
If one needs more inputs, port expanders are the way to go and frequently mean you need only a Nano (with a more convenient form factor) rather than a Mega 2560.
If you wish to perform some action at a distance, you need to define carefully what the required action is, as it may not require any actual processing power at all and simpler logic may be perfectly adequate.