Hi all,
I am new to Arduino. For my project, I am using an Arduino UNO controller as the Co-processor and an Atmel ATmega 32 micro-controller as the main processor.
I wish to establish serial communication between the Arduino UNO board and the ATmega 32 micro-controller.
Is serial communication between the two boards possible??
If so, can you suggest me how to proceed??
Thanks in advance,
Sravan
Find out the Rx/Tx pins on each board, connect them crossed-over.
Find example code how to configure the serial ports for the same baudrate.
If so, can you suggest me how to proceed??
I've used the below code to communicate between two arduinos.
edit, changed //Connect the sending arduino tx pin to the receiving arduino rx pin.
//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 tx 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
//A diode between the slave tx and master rx is suggested
//for isolation, with diode band attached to slave tx side.
//
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
}
}
}
Four devices on a serial connection is quite strange. Who should send, who receive?
zoomkat:
I've used the below code to communicate between two arduinos.
//Connect the sending arduino rx pin to the receiving arduino rx pin.
Do you mean
//Connect the sending arduino TX pin to the receiving arduino rx pin.
?
Do you mean
Yes, as best as I remember the flow path is from the master serial monitor to the master arduino rx, the master arduino then echos the data out its tx to the slave rx, then the slave arduino echos the data out its tx to the slave serial monitor.
Then you should not connect the slave Tx to the master Rx, to prevent endless echoes.
DrDiettrich:
Then you should not connect the slave Tx to the master Rx, to prevent endless echoes.
I don't remember issues with endless echos. It has been a while and if I get time I'll wire the arduinos back up and do some testing, and correct the header info as needed. I may have had the slave tx connected to the master tx to echo the slave data output back to the master serial monitor instead of the master arduino rx. I did need a diode between the master and slave tx to do the experimenting. I added the write up in the code some time later based on what i remembered from the experiment. The below wiring should provide for code sent from the master serial monitor to be received by the master arduino and resent to the slave arduino, with the data being displayed on both the slave and master serial monitors. The slave arduino sends the received data out its tx, and the data is displayed on both the slave and master serial monitors. Data sent from the slave serial monitor to the slave arduino is echoed out the slave tx, which causes the data to be displayed on both the slave and master serial monitors. below is probably the wiring setup I used.
master tx > slave rx
master tx > diode|band| > slave tx
master gnd <> slave gnd