Software serial, timeout and interrupt


I’m using an Arduino BT board. The task is pretty simple: I need to forward a serial communication to another device (@ 2400 / 4800 / 9600 bps).
In other words:

[DEVICE] <----> [ARDUINO BT] <----> [PC/MOBILE]

Basically, I want to read a byte from the PC and send it to the device. Viceversa, read a byte from the device and send it to the pc.
The serial between arduino and the device should be a software one, of course. I read it’s very limited because it does support neither serial.available() nor timeouts.

Because I don’t know the length of the incoming packets I can’t use the blocking read() function. So I’m wondering:

  1. is there the possibility to add a timeout to the read() function? If after n milliseconds nothing has been read it returns.

  2. I may connect together the RX pin with an EXT int pin (e.g. PD2). When I detect a falling edge I immediately call the serial read(). I don’t know if this could work, because if the read() waiting for the start bit itself it will miss the current byte.

Any hints?


Have you looked at NewSoftSerial?

Thank you very much! I'm downloading it right now ;)