1

Is there a way to set an Arduino pin as being both an input, and an output?

I was looking at tristates, I'm not sure if that is related, or if there is some other method.

Perhaps I can try switching states rapidly. on one pin. I'm just not familiar with how to do it, and I don't see anything about it on the Arduino site.

This is a function of other microcontrollers, such as PICs, but I'm not sure about AVRs and Arduino types.

2

The source code for the 1-Wire protocol is a great place to start when learning how to use a single pin for both input and output.

See also chap. 18. I/O-Ports in the ATmega328p datasheet.

Cheers!

  • Does it mater that the device isnt a 1-wire protocol item? Its NeoPixel Rings. such as adafruit.com/products/1643 – j0h Oct 21 '16 at 20:16
  • 4
    @j0h: Why do you need to connect that as an input? The output from those is usually only useful for chaining them together. – Ignacio Vazquez-Abrams Oct 21 '16 at 20:25
2

A tri-state pin is not both an input and an output, rather each pin can be in 1 of 3 states (High, Low, High Impedance). These are typically used on a bus, where many similar devices are connected.

AFAIK the Arduino does not support tri-state, but it is possible to implement a bus. This was done by using open collector/drain devices with a resistor pull-up.

This was a common method of implementing computer busses (more than 40 years ago with RTL logic), but suffers from slow speed, and low fan-out, due to capacitance.

It is still used for low speed short busses such as I²C and 1-wire.

In practice all devices are set as Input. When a device wants to communicate it is configured as Output.

  • The three states are "High", "Low", and "High-Impedance"; a tri-state pin is always an output. – Ignacio Vazquez-Abrams Oct 22 '16 at 1:56
  • @IgnacioVazquez-Abrams True - brain fade on my part. – Milliways Oct 22 '16 at 1:59
  • 1
    All the I/O pins of an AVR-based Arduino are four-state: not only do they support the three states you mention, they also have a fourth INPUT_PULLUP state, which is a weak pull to Vcc. You can connect a pin to an open-collector bus directly and then just switch between INPUT (i.e. HiZ, to either read or write 1) and OUTPUT LOW (to write 0). – Edgar Bonet Oct 22 '16 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.