Hello . I started a personal project and i need to connect 2 Arduino Mega boards together.
One should be the "brain" with the display and the other should be the "hands" that directly interact with sensors , relay, outputs ... etc and sends the sensor readings to the first one to take the decisions , so basically the first should be a type of remote for the second.
I was thinking to make it over serial port but i do not know how. I can also use a wireless type of connection between the two arduino but i prefer for the beginning a wired solution.
Any help / example would be highly appreciated.
Thank you in advance.
SSerpente:
but this way both boards will be able to send and receive ?
TX is transmit.
RX is receive.
Serial data is 1 bit at a time on 1 wire for 1 direction, transmit or receive.
Mega has 3 extra serial ports (first one is to the USB chip) so RX1/TX1, RX2/TX2, RX3/TX3 labeled right on the board.
The more you know about the machine, the less mystery you will have about making it work.
Whatever you don't know, start from the start and learn enough through examples to have no questions.
The hard way is to have software with multiple unknowns while trying to learn basics at the same time.
SSerpente:
but this way both boards will be able to send and receive ?
Yes. But the program on each board will have to be properly designed to avoid the confusion that you get in a pub where everyone is talking at the same time. It would probably be easiest if one of the boards (call it boardA) was "in charge" of communication and would request data from the other. Then, in the normal course boardB would be waiting for a message from boardA. However that does NOT mean that boardB could do nothing except listen.
The examples in serial input basics listen without blocking other activities. I suggest you use the system of the 3rd example. You can use the same code on both devices.
Robin2:
The examples in serial input basics listen without blocking other activities. I suggest you use the system of the 3rd example. You can use the same code on both devices.
...R
SSerpente:
No i didn't ... but it works without the common ground
Perhaps you've been lucky that the GNDs are commoned some other way. Perhaps you're powering them both from the same supply?
If the two boards were getting their power from completely isolated sources (say from two different wall warts) it's unlikely to work UNLESS you connect those grounds.
SSerpente:
are both using the same wall wart but different power supply.
Huh?
Same wall wart is same power supply. Is there other power supply(s) as well?
If both are connected to the wall wart power and ground then both have a common path to ground.
GoForSmoke:
Huh?
Same wall wart is same power supply. Is there other power supply(s) as well?
If both are connected to the wall wart power and ground then both have a common path to ground.
by extension of what you say connecting 2 different power supply (AC/DC converter ) in 2 different wall warts (anywhere in the house ) in the end they have the same ground (because all the electric network of a house/city in the end have a single starting point from where thy split) ?
I am a complete noob ... but i was thinking every single AC/DC converter has his own + and - (+ and ground ) and i understood that i have to connect the 2 - poles of the power supply (or i got it wrong ?).
SSerpente:
by extension of what you say connecting 2 different power supply (AC/DC converter ) in 2 different wall warts (anywhere in the house ) in the end they have the same ground (because all the electric network of a house/city in the end have a single starting point from where thy split) ?
I am a complete noob ... but i was thinking every single AC/DC converter has his own + and - (+ and ground ) and i understood that i have to connect the 2 - poles of the power supply (or i got it wrong ?).
No. Your words before are not clear. If both boards connect to the same wall wart then they would share ground.
Yes, each power supply has + and - but only to itself. Unless the grounds are connected, the - of one may be + relative to the - of the other. Voltage is relative, not absolute. You may be lucky and they match or by some design they match perhaps if both are on the same house circuit and nothing strong happens between. What works by luck may fail by luck as well.
If you want to electrically isolate the boards then there are opto-isolators that can be put between the boards. The chip has per channel, a led and a detector with no electric connection. If you use those, you do not connect the grounds. But otherwise connect the grounds so all your circuits are on the same base.
I've used the below simple test setup to use serial communications between two arduinos. Note that i used a diode between the master rx and slave tx to get bidirectional communication.
//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 rx 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
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
}
}
}