Have questions about how to go about this

What kind of limits will i run into when trying to get two megas to communicate sensor data between one another to then activate an led?

Im trying to read sensor data then set pins to high at specified intervals.

Not sure what method is best, ive read about icsp and i2c. Not sure which to go with.

Does it work as if i have doubled my pin count by using the serial connection? Or do i have the concept incorrect?

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

UART/Serial is RX and TX communication.
for example
see this link

http://www.martyncurrey.com/arduino-serial-part-3-getting-started-with-serial-communication/
https://iot-guider.com/arduino/serial-communication-between-two-arduino-boards/

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.

SPI is Serial Peripheral Interface and is a Master Slave communication.

I2C is Integrated Circuit to Integrated Circuit communication. Also a Master Slave system.

I2C and SPI are pretty short range, about a meter, maximum. Serial is good for several meters.

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.

Thank you guys, that info is really helpful in deciding. Sounds like UART is the way to go for me since i will be getting logging data from sensors.

SPI is a close second but since this is my first project like this the less complicated method may help preserve some resources.

Having spent a long time focusing on Serial for communication between Arduinos I recently figured out that I2C can actually be easier.

Have a look at this Arduino to Arduino I2C Tutorial.

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)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

...R

Hi,
How far apart are the two controllers?
What link distance do you need?

Thanks.. Tom.. :slight_smile:

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. :grinning: