Go Down

Topic: IR-communication (Read 766 times) previous topic - next topic

Giete

Hi to all


We are making a project an in this project we have to make a full duplex communication system using IR led's(940mm smd) and recievers (TSOP2238).
We need to be able to send a certain string using IR to an arduino, this arduino has to process this string and then 'produce' an answer which he has to send back to the first one.

The sending is not such a big problem, we used 'dirt cheap wireless' (code an more details at this link: http://tthheessiiss.wordpress.com/2009/08/05/dirt-cheap-wireless/). The answering however is a problem. We use the RX an TX pin, the TX to send and the RX to recieve. we use the serial monitor of arduino to write a string, for example the word 'test'. This string is then forwarded to the TX pin which encodes the signal en sends it (using the ir led an the ir reciever) to the TX port of the second arduino. The problem is however (at least that is what we think it is) that this string is immediately rewritten to the  TX port of the second arduino. So if you use the TX pin of the second arduino to send your answer then the both arduino's will go in an endless loop of sending and receiving.

We need to break this loop at a certain point to make al this work. Can anyone help us?


Thanks in advance
Giete

Grumpy_Mike

I think your problem is that the receiver is receiving the signal from its own transmitter. This is the problem with trying to implement full duplex in any medium.
One thought, it might be possible to use a different modulation frequency for each path. Using a TSOP chip get one running at 30KHz and the other at 40KHz, that might give you enough separation.
However, it is much easier to implement half duplex, you still get two way communications, you just have to implement a protocol.

Giete

#2
Oct 16, 2012, 10:29 am Last Edit: Oct 16, 2012, 10:50 am by Giete Reason: 1
Thanks for the fast answer. You need a third pin to use half duplex, to control which channel is open (the send or recieve channel an on the other board the opposite). Which pin do I use for this and how do I implement this in my software?

Send code:
//dirt cheap wireless TX
//generates 38kHz carrier wave on pin 9 and 10
//sends data via TX every 500ms

char incomingByte;
void setup()
{
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  // Clear Timer on Compare Match (CTC) Mode
  bitWrite(TCCR1A, WGM10, 0);
  bitWrite(TCCR1A, WGM11, 0);
  bitWrite(TCCR1B, WGM12, 1);
  bitWrite(TCCR1B, WGM13, 0);

  // Toggle OC1A and OC1B on Compare Match.
  bitWrite(TCCR1A, COM1A0, 1);
  bitWrite(TCCR1A, COM1A1, 0);
  bitWrite(TCCR1A, COM1B0, 1);
  bitWrite(TCCR1A, COM1B1, 0);

  // No prescaling
  bitWrite(TCCR1B, CS10, 1);
  bitWrite(TCCR1B, CS11, 0);
  bitWrite(TCCR1B, CS12, 0);

  OCR1A = 210;
  OCR1B = 210;

  Serial.begin(2400);
}

void loop()
{
  if (Serial.available()>0) {
    incomingByte = Serial.read();
  Serial.print(incomingByte);
  }
}

Receive code:

//dirt cheap wireless RX
void setup()
{
  Serial.begin(2400);
  pinMode(13, OUTPUT);
}

void loop()
{
  // if incoming serial
  if (Serial.available()) {
    readSerial();
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
  delay(10);
}

void readSerial() {
  char val = Serial.read();
  Serial.print(val);
}

Thanks in advance

Grumpy_Mike

Quote
You need a third pin to use half duplex

No you don't.
You just shut down the sending LED when you are expecting to receive.

Please read the sticky topic read this before posting to see how to post code correctly.

pylon

Your code is (on both ends) just sending everything it receives on the serial interface out of the serial interface. So you have a loop even if send on the two boards with different carrier frequencies. You need a different interface (not the hardware USART) for your control commands (the input into the system).

The system you linked to uses just a one way communication, you describe a hardware solution for two way communication. Maybe I misunderstood your description of the hardware setup, then it might be a good idea to draw a schematics to show us what you've wired.

Go Up