What is the best way to configure a bidirectional, open collector data pin?
If the other end of the link has the same signal voltage as your
Arduino, you can simulate an open collector with a single pin:


digitalWrite(pin, LOW); pinMode(pin, OUTPUT); sets the pin to output
an active low signal.
pinMode(pin, INPUT_PULLUP) sets the pin to input mode, or output
passive high which, in open-collector mode, is the same thing.


Note that in the first case the order of the commands is important: on
AVR microcontrollers, if you set the mode to OUTPUT before writing
LOW, the pin will for a short time output an active high, which is
forbidden in open-collector mode. I don't know how other MCUs would
behave in the same situation though.

Edit to address Ignacio Vazquez-Abrams’ comment: An open-collector
bus needs a pullup resistor on each data line to function properly. If
that pullup is already provided by your keyboard, or your cable, then
you should use pinMode(pin, INPUT) to accurately emulate an
open-collector output on the Arduino side. Otherwise you have to provide
that pullup, either as an external component or by using the internal
pullup of the MCU. Beware that the latter may be a little bit weak,
depending on your data rate.