Input & Output on same pin

How do I go about using a single pin for both output and input?

I'm trying to use an Arduino to reset and monitor a Gecko 320 servo driver.

The gecko drive expects to have it's reset/error line held high for 5 seconds at power up and then monitored for an error condition.

I use a pin on the Arduino that I've set as an output and reset the gecko using:

pinMode(YerrIn, OUTPUT);

digitalWrite(YerrIn, HIGH); delay(5000);

This appears to work fine. I then set the Arduino pin as an input and monitor it using the following code.

pinMode(YerrIn, INPUT);

void loop(){ if (digitalRead(YerrIn)==LOW) { digitalWrite(PCestopOut, HIGH); // signal estop to PC digitalWrite(YStatus, LOW); } }

My problem is that reading from the pin is giving me inconsistent results. After some debugging it would appear that switching the pin to an input is the problem. If I put a delay in the code I get better results, however it's still not 100% consistent.

I've experimented with pullup/pulldown resistors but this doesnt fix the issue.

Is using a single pin for both input and output this way possible? If so any ideas where I'm going wrong?

thanks

Phil

Did you tie the ground from the Gecko to the Arduino?

hmm, I think so :)

at least the Gecko drive needs a +5v from the PC power supply and I'm using the USB to power the Arduino. I've checked the voltage differential between the grounds of the Gecko and Arduino using a multimeter and it's 0.02.

I tried using an external power supply for the Arduino but this made things much worse. The Arduino wouldnt even reset the Gecko. No surprise really as there was 3.2v difference between the grounds when trying this out.

thanks

Phil

After you switch the pin to input do a digital write high. This will enable the pull up resistor and stop the intermittent results.

I've checked the voltage differential between the grounds of the Gecko and Arduino using a multimeter and it's 0.02.

You should be tying the grounds together there should be no voltage measurable between them. Even if they are so close you will not get reliable results.

aha! looks like it was the grounding issue. I tried setting the pin high first but that made no noticeable difference. Tying the grounds together solved the problem.

Thanks very much for the help in resolving this.

Phil

I just want to point out that reading pretty close to 0 on a voltage scale doesn't mean the 2 points are both ground or both the same. It just means there's no voltage between them. If I have an unpowered arduino on my shelf and measure between its ground and the negative terminal of a battery that's also not connected to anything, I expect to read pretty close to 0.

yep makes sense. So much to learn and so few neurons left ;)

thanks

Phil