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.

asked Oct 21, 2016 at 19:43

2 Answers 2

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!

answered Oct 21, 2016 at 20:00
2
  • Does it mater that the device isnt a 1-wire protocol item? Its NeoPixel Rings. such as adafruit.com/products/1643 Commented Oct 21, 2016 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. Commented Oct 21, 2016 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 I2C and 1-wire.

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

answered Oct 22, 2016 at 1:51
3
  • The three states are "High", "Low", and "High-Impedance"; a tri-state pin is always an output. Commented Oct 22, 2016 at 1:56
  • @IgnacioVazquez-Abrams True - brain fade on my part. Commented Oct 22, 2016 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). Commented Oct 22, 2016 at 10:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.