1
\$\begingroup\$

The NES controller is a simple parallel-in-serial-out chip with clock, latch and data pins exposed, as well as 5 V and GND through its connector.

The thing is (and I already researched but I haven't found any "good" methods) I'd like to detect when it is plugged in.

I'm not good in electronics.

I've seen a solution adding a transistor, but wouldn't it be possible to add a resistor from controller's GND pin to an input, so it acts kind of a pull-down, and you can read the voltage coming from that GND pin?

Is there any solution?

Also I've seen a possible solution using a 5 V Zener diode, but I don't know how I would connect it.

My idea is to have a pin to sense it, as other solutions suggest powering the Arduino with a transistor so when current is drawn by the controller Arduino is powered, but I need Arduino to be powered always as I'll have 2 controller ports on the same board, and I need to enable/disable joysticks in my PC programatically.

\$\endgroup\$
17
  • 1
    \$\begingroup\$ What are you proposing with a resistor? It's hard to envision what you mean. Could you draw it? \$\endgroup\$
    – Hearth
    Commented Jun 5, 2023 at 1:04
  • \$\begingroup\$ @Hearth well, 5V from arduino would go to 5V of the controller, and GND pin of the controller would go to GND pin of the arduino (to get usb power). I tought maybe between the GND pin of the controller and GND pin of the arduino adding a resistor to a pin? Or something similar? Again, I can't imagine a way. \$\endgroup\$
    – maduranma
    Commented Jun 5, 2023 at 1:07
  • \$\begingroup\$ pin 5 and pin 6 in the connector are unused by the controller \$\endgroup\$
    – jsotola
    Commented Jun 5, 2023 at 1:15
  • \$\begingroup\$ @jsotola I considred that, but those pins are not internally connected, just floating, so I cannot measure continuity through them \$\endgroup\$
    – maduranma
    Commented Jun 5, 2023 at 1:41
  • \$\begingroup\$ @maduranma Are you talking about using a current shunt? You could do that, but you'd definitely need a current sense amplifier attached to it if you don't want to use such a large resistor that it just doesn't work at all. \$\endgroup\$
    – Hearth
    Commented Jun 5, 2023 at 1:47

1 Answer 1

1
\$\begingroup\$

Depending on which Arduino you have: sense the controller's output (SDO) pin.

Easiest way is to set passive pull-up and pull-down, and check if the input pin level follows the pulls or not.

That is:

 SDO   |  pin setting  | pin level
-------+---------------+----------
 open  | weak pullup   |    1
       | weak pulldown |    0
-------+--------------------------
driven | weak pullup   |    0
 '0'   | weak pulldown |    0
-------+--------------------------
driven | weak pullup   |    1
 '1'   | weak pulldown |    1

You won't know in general whether the controller is driving '0' or '1', but the fact that it doesn't change with pull direction is the part that matters.

If your Arduino doesn't support weak pull-down, you can approximate this by setting the pin (strong) high or low (i.e. DDR = '1') for a few cycles then hi-Z (DDR = '0') immediately after. (You probably can't assign for a few cycles within the Arduino library calls, but as fast as can be, in that case.) Then read the pin value immediately after -- capacitance will hold it there for a short time.

Meanwhile, preferably connect the controller to the SPI peripheral for easy use. It can also be bit-banged (manually set SCK high/low, read SDO), which is a bit of a bother to implement, but nonetheless usable.

Apparently there are some other signals on the connector as well, which might be useful. Dunno.

\$\endgroup\$
4
  • \$\begingroup\$ Hi, there's one more handicap to that, I'm gonna have 2 controller ports on the same Arduino (this is a requirement as it will go inside my computer and I only have a half USB-2 header available in the motherboard (so I can only connect one arduino). The Arduino I'm using is the Pro micro, problem is I've got to do this twice, so I cannot use SPI pins \$\endgroup\$
    – maduranma
    Commented Jun 5, 2023 at 3:58
  • \$\begingroup\$ I mean you can use SPI for one, but duplicating the bit-bang code for two would be easier, yes. \$\endgroup\$ Commented Jun 5, 2023 at 4:03
  • \$\begingroup\$ problem is I cannot use SDO port for both, how would I do it without it? \$\endgroup\$
    – maduranma
    Commented Jun 5, 2023 at 4:47
  • 1
    \$\begingroup\$ You just asked about detection. Bit-bang serial is a separate question (and I suspect already well answered, search around). \$\endgroup\$ Commented Jun 5, 2023 at 6:28

Your Answer

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

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