0

I know UART and serial communication model and data frame. But I want to ask about something else, when I searched in internet just found examples of one Arduino as (receiver) and another Arduino as (transmitter). So my question is how can I implement two Arduino and both of arduinos can communicate each other when after transferring data from one to another (example A->B). If the interpretation of the received data has to be forwarded to the first sender again(B->A).

4
  • UART is full duplex. It has 2 lines, one for sending, 1 for receiving. So this is automatically implemented
    – chrisl
    Commented Aug 14, 2019 at 21:53
  • So can you give me an code sample, in one Arduino acting differently in transmitting or receiving moments? Commented Aug 14, 2019 at 21:57
  • 1
    If you know how to make A talk to B then you already know how to make B talk to A - it's exactly the same.
    – Majenko
    Commented Aug 14, 2019 at 22:09
  • But how should call transmit and receive function in main function? Just separate with delay? Or after transmit data should switch my position as receiver until the data come in? Commented Aug 14, 2019 at 22:12

1 Answer 1

0

You sure now Serial.write() and Serial.read(). That's already what you want. A hint to make it clear to you: When using the common Serial.print() function only the RxD line is in charge an thus only "half" of the serial interface is used. If you connect TxD of arduino A to RxD of another arduino B and RxD to TxD respectively you have full-duplex communication which is what you're asking.

5
  • Oh gotcha. So I just should use write and read functions for full duplex. Print is for half duplex. You saved my day man. Thank you Commented Aug 14, 2019 at 22:15
  • I recommend looking for a simple example to see how the reading actually has to be implemented. This tutorial might help you: robotic-controls.com/learn/arduino/…
    – Sim Son
    Commented Aug 14, 2019 at 22:18
  • No, print is not only for half duplex. The whole connection is always duplex, and you can send and receive at any time. print and write are doing nothing else but putting the data into the buffer. The transmitting is done in the background by the Serial library and the hardware. And all read commands are just reading data, that was already received, from the buffer. If you want one arduino to react to the other, just read the data from the first Arduino on the second, and let it send corresponding data back directly (you don't need a delay there)
    – chrisl
    Commented Aug 14, 2019 at 22:31
  • @chrisl hmm, was your comment meant to be a reply to the OP's comment in the question? Otherwise, what exactly of what I wrote is incorrect? You can Serial.print() without RxD connected. I'm aware of the routine executed in hardware, but I think that info doesn't help the OP very much at this point.
    – Sim Son
    Commented Aug 15, 2019 at 2:44
  • Your answer isn't wrong. I wanted to answer to ghe OPs comme t above, since it seemed to me, that he thinks, he cannot use print if he wants to communicate in both directions. I wanted to prevent a misunderstanding. And it is always good to know, what the called functions really do. That helps in understanding. If this is too complex for a comment, I can also write an answer, to explain it better, than in my comment
    – chrisl
    Commented Aug 15, 2019 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.