Looks like I didn't make myself clear, sorry. Update to clarify things / TL;DR version:
- 4 Arduino UNO pins are connected to respective DE-9 pins, responsible for UP, DOWN, LEFT, RIGHT directions
- Arduino sketch simulates joystick actions
- DE-9 device acts as a slave - I set respective Arduino pins to OUTPUT LOW (DE-9 device registers movement) or keep them as INPUT (DE-9 device registers no movement)
Question: what are the cons of exploiting open drain OUTPUT without pull-up in HIGH state for each pin, regarding this scenario?
Pros are: no more INPUT / OUTPUT switching, pin is disconnected and doesn't take any current what simulates original joystick state.
I have a small project interfacing the Atari joystick port (DE-9) used in retro computers. Basically, all DE-9 direction pins are in HIGH state. To trigger a movement the corresponding pin(s) must be pulled LOW.
At first I used Arduino pins in OUTPUT mode / HIGH state. This was probably not the best way, so now I keep them in INPUT mode and switch to OUTPUT when needed. But the more I read, the more ideas come to mind. I've learned that in open drain OUTPUT the pin is either LOW or switched off (floating). There is the usual recommendation to use a pull-up resistor so that the pin has a known state. But in my case this isn't necessary. I don't need to read the state of the DE-9 pins at all. I just need to pull them LOW or don't touch them at all. Open drain seems best for this purpose as I wouldn't have to switch between modes. Just LOW to trigger a move or HIGH to turn the pin off and cancel movement on DE-9.
Is this a good idea? Are there any side effects regarding lack of pull-up I should be aware of? I know this is a creative way, but this is a personal project and I don't have to follow strict rules.
2 Answers 2
We can differentiate these alternatives, omitting others that would need extra hardware:
- Set the pins in
OUTPUT
mode, and switch betweenHIGH
andLOW
.- This will produce short circuits when the controlled computer shares the pins between multiple joysticks or mice. For example, the Atari ST does this.
- Do not connect another joystick or mouse in this case. Neither for the same input, nor for another input.
- Switch the pin between
OUTPUT
mode with aLOW
level andINPUT
mode.- This will work just fine.
- If you happen to use the Arduino unconnected, the pins will float during
INPUT
mode. Since you do not plan to read the pins, it does not matter. However, supply current could increase when an input is "in between" in the illegal voltage range. - The MCU's pin protection usually avoids damage. However, discharging your electric charge on a sparking touch could be too much. Think "x-mas time" and "woolen pullover."
- Use open-drain mode, and switch between
HIGH
andLOW
.- You need direct SFR access for implementation instead of Arduino library functions.
- The rest is like above.
- Switch the pin between
OUTPUT
mode with aLOW
level andINPUT_PULLUP
mode.- This will work just fine, too.
- The levels are defined when unconnected.
- Of course the Arduino's pull-ups will be in parallel to the ones of the controlled computer. But because of the high resistor value, it makes no problem.
So, to answer your question ("Is this [open-drain mode] a good idea?"): Yes, it is. You might want to consider using a pull-up, though.
Note 1: Consider the small interval when switching the pin mode and the pin level. Make sure you do not create a short circuit, instead accept a short interval of floating.
Note 2: Make sure you connect "ground" as the fifth connection. You did not mention it in your question.
-
Thank you for the detailed explanation. This is exactly what I needed. You also nailed some details I wasn't aware of! GND is connected just like the fire button.tOad– tOad12/12/2024 19:32:48Commented Dec 12, 2024 at 19:32
A pull-up resistor is absolutely needed for open-drain communication. Whether you read the pin or not is irrelevant, as someone has to read it, otherwise there would be no communication. If the device at the other end of the link provides its own pull-up, then you don't need to add your own. If it doesn't, then you will have to provide it.
You have to watch out for the voltage levels. The pull-up should pull to
the logic level of the reader. If that voltage is greater than the logic
level of the writer (the Arduino), you need a proper level shifter.
Otherwise a simple connection should work fine. In the later case, you
can write by switching the pin between the INPUT
state and the
OUTPUT
LOW
state.
pinMode( myPin, INPUT_PULLUP )
in the case of interfacing to an open drain input device. On some MCUs, the process of writing HIGH to an input pin can force the pin's internal pull up resistor to be active which is also what you would want. As said in the first answer below, some sort of pull up is mandatory for an open drain/open collector type input to an MCU.