-1

I am trying to figure out how to get 2 Arduinos to talk back and forth from one another using cheap simple RF modules. I have a total of 4 RF modules (2 receiver and 2 transmitter) and 2 Arduinos. I need Arduino A to send about 3 variables to Arduino B, and I need Arduino B to send 1 variable back to Arduino A.

When I attempted 2 way communication, I programmed Arduino A to broadcast constantly, while having Arduino B trade off between receiving once, then sending once on every other loop. This resulted in Arduino B also only broadcasting, and was not receiving any signal from Arduino A.

My other attempt was to have Arduino B send for about 250 ms, then receive for 250 ms, and repeat. This worked as long as Arduino A was only broadcasting, but as soon as I had Arduino A doing the same thing, the clock on each seemed to be slightly off and there would be periods where both Arduinos were sending, or where both were trying to receive, so it was also very unreliable.

Is there a reliable way to do two way communication with this kind of hardware, or would I need transceivers to do this kind of project?

Sean
  • 107
  • 1
  • What bit rate are you using? And what is the message size? I would start by increasing the receive period and add a listen-before-send logic. – Mikael Patel Dec 08 '15 at 11:58
  • You should synchronize communication, instead of relying on just time. E.g. send 250ms after a message was received. – Gerben Dec 08 '15 at 13:18
  • @MikaelPatel 2000 bps and a 4 byte message size. I tried increasing the receive period when I had it trading off with my first attempt. I wound up having it send once for every ~2000-4000 times it would read. That was the minimum it took for me to actually get it to receive anything, but that doesn't work well because when I have the other arduino do that same thing, they don't send frequently enough to reliably receive messages. – Sean Dec 08 '15 at 22:44

2 Answers2

1

If the RF Modules you are mentioning are the ones I am thinking of they do seem to be very special bits of kit. I have tried Bluetooth you can get cheap HM05 modules (Might be the wrong number you want the one that can be the master or slave). These were a bit better but don't have the range.
My personal fav at the moment would be a ESP8266, no I have never hooked one up to an Arduino, but it can be done fairly easily. You should get 100m range (in ideal circumstances) and you can get aerials to boost that. You can also set one up as a repeater between two wifi segments.

Whatever you decide you might want to change your code slightly so that one Arduino sends a time signal and the other doesn't send its data until its turn. Or give them GPS receivers and pull the time from there.

Code Gorilla
  • 5,637
  • 1
  • 15
  • 31
0

With VirtualWire, an Arduino can only send, or only receive. It can't do both at once. It is basically like software serial, but with Manchester encoding of the message.

Write your code for the sender to send once, and then listen for a response. If no response after some interval, try sending again, and then go back to listening. Perhaps try one more time.

Write your code for the receiver to always be listening, and not reply until a message is received. Add some code to indicate when a good message is received as an aid to debugging.

You should be able to connect Tx to Rx and Rx to Tx (and Gnds) between the two Arduinos and get the sequence to work back and forth, and then connect the RF modules and have them work as well.

I think the encoding done by Virtual wire adds 37 bytes to the message, which the library takes care of, so the end result is only the data that was sent.

You might also try the RadioHead library, of which VirtualWire is one part now.

CrossRoads
  • 2,415
  • 6
  • 9