Is it possible to read and write on one pin???

Hi,

I have a question; is it possible to connect a device that communicates through one I/O pin to an Arduino board?

If so, how do I have to do this? Is it possible to program one pin as an input and as an output?

Something like:

pin: output
send a request to the device connected to the Arduino
pin: input
read the data the device sends you

Or is my thinking totally wrong?

Kind regards

foha

Your thinking is correct! Check out the pinMode() function at: pinMode() - Arduino Reference

floresta

Yes, the capability is there to flip a pin from input or output on the fly. However you have to be concerned about the timing and protocol used. If both the Arduino and the other external device were both in output mode at the same time and sending different levels, one at high and the other low, then high current would flow possibly causing permanent damage to their respective I/O pin.

Lefty

Hello,

Thank you floresta and retrolefty for your advice.
So, to get this right... it is possible to do, but it's not that easy.

Do you know some examples of this where I can see how the code is build?? Because now I'm a bit scared to damage my I/O pin.

Kind regards

Well you could read up on how one commerical protcol works called 1-wire. Here is link to get you started.

http://www.arduino.cc/playground/Learning/OneWire

Lefty

Ok, thank you retrolefty.
I will check it out and try to make some code.

Kind regards

I2C also uses one pin for read and write (plus a second for a clock).

-j

you can use a resistor of resonably low value in series with the pin to slow down the current in the case of both Pins in output mode.

the resistor will slow the current flow and prevent damage to the chip(s)