Send and Receive IR at the same time?
Moderators: adafruit_support_bill, adafruit

Send and Receive IR at the same time?

by JC Hammer on Tue Jul 16, 2013 3:54 am

Hello,

Arduino newbie here trying to follow the IR Sensor lesson on learn.adafruit.com. I can get each separate action to run (send/receive), but would it be possible to have the arduino both send and receive at the same time?

For example, I am trying to get two identical devices (both rigged up as IR emitters/receivers) exchanging one piece of data. Once activated by a push button, I would like both devices to broadcast and listen simultaneously. Would this be possible? Or do I have to broadcast for a defined interval, then listen?

Thanks,
Jon
JC Hammer
 
Posts: 2
Joined: Tue Jul 09, 2013 1:29 am

Re: Send and Receive IR at the same time?

by adafruit_support_rick on Tue Jul 16, 2013 11:08 am

What IR sensor are you using that can also transmit?

adafruit_support_rick
 
Posts: 13070
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: Send and Receive IR at the same time?

by JC Hammer on Thu Jul 18, 2013 2:16 am

Oh sorry. I am using the TSOP38238 and IR LED from your site. I am just wondering if I need to just cycle back and forth between read and transmit on each device and hope that the timing works out so device 1 will be in read mode while device 2 is in transmit mode.

Thanks.
JC Hammer
 
Posts: 2
Joined: Tue Jul 09, 2013 1:29 am

Re: Send and Receive IR at the same time?

by adafruit_support_rick on Thu Jul 18, 2013 10:40 am

Well, yes and no.

If you are using the transmit and receive code from the tutorial, then the answer is no, because the signal timing is handled in software, and there is no way to transmit and receive simultaneously without disrupting the timing.

It is possible to write code which uses the timer hardware in the ATmega processor to handle signal timing, making simultaneous transmit and receive possible. But we don't have code like that available for download.

Regarding alternating transmit and receive on your two devices (a.k.a. "half-duplex"), letting them independently cycle while hoping for the best is probably not a good approach.

The simplest thing would probably be a master-slave arrangement, in which the slave listens to the master, and doesn't "speak unless spoken to". I'd probably arrange a sort of idle state, where the master sends out a message once every second or so, and the slave responds. Sort of like "Are you still there?"/'Yup, I'm still here".

I don't know who gets the push-button signal, but it can work no matter who gets it. If the master gets the push button, then the conversation looks like this:
Code: Select all | TOGGLE FULL SIZE
master: "are you still there"
slave:  "I'm still here"
master: "I've got some data for you"
slave:  "OK, send it"
master: "<data>"
slave:  "OK, I got the data"
master: "are you still there"
slave:  "I'm still here"
…etc...

if the slave gets the push-button, then the conversation looks something like this:
Code: Select all | TOGGLE FULL SIZE
master: "are you still there"
slave:  "I've got some data for you"
master: "OK, send it"
slave:  "<data>"
master: "OK, I got the data"
slave:  "cool"
master: "are you still there"
slave:  "I'm still here"
…etc...


If you want to do it right, you'll have to handle errors, like the data transmission failed, or the master stops hearing from the slave, or the slave stops hearing from the master. You'll also want to wrap the data in a packet structure - something like this:
Code: Select all | TOGGLE FULL SIZE
<data message code>
<byte count>
<data bytes…>
<checksum>


Lay out all the possible queries and responses in the conversation, and assign an IR code to each one. Then write your code starting from there.

adafruit_support_rick
 
Posts: 13070
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY