0
\$\begingroup\$

I'm using an Arduino Uno to read input from an NES controller (a simple 8-bit shift register). This is working just fine, but I'd like to be able to detect when the controller is disconnected to shut down the I/O polling, otherwise the ATmega reads a bunch of nonsense input from the floating input pins.

My main problem is that I am extremely not an EE, so I'm not quite sure how to go about doing that. The controller has 5 pins: Vcc (5V), ground, strobe (latch the 8 parallel inputs), clock (shift the bits out), and a data output pin. It looks like there's a pretty substantial voltage drop at the ground pin on the controller when no buttons are being pressed.

Essentially, I just need to detect when the Vcc-to-ground circuit is broken, and set one of the Arduino's input pins high or low accordingly. Doesn't matter which logic level represents disconnected, as the code can be easily adapted either way.

I've got a few hundred resistors of various sizes, a box of assorted NPN, PNP, and JFET transistors, and only a cursory understanding of how to use them. :)

\$\endgroup\$
1
  • \$\begingroup\$ I suggest connecting pull-up or pull-down resistors to the floating input pins so that they are not floating. \$\endgroup\$
    – user20574
    Commented Feb 28, 2020 at 12:27

1 Answer 1

3
\$\begingroup\$

I suggest using another method:

  1. You do not do anything to data input pin on Arduino
  2. Guess you have one more input pin available on Arduino, right? Call it "V"
  3. So you change the SW to ignore all data when this V pin is Low
  4. All the electronics you need is: -- common PNP transistor -- resistor 4K7 or about -- resistor 47K or about
  5. Connect: -- pnp Emitter to +5 V power supply and to 47K resistor -- pnp Base to Power Input of NES controller and to another end of 47K -- pnp Collector to 4K7 resistor and to V input pin of Arduino -- other end of 4K7 goes to Ground

Current consumed by NES makes PNP transistor conducting and it holds V pin at logical High. That's it

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
4
  • \$\begingroup\$ It is probably best to give him a schematic in your answer. To open schematic editor in the editor, toolbar at top has a resistor, diode, etc symbol or hit Ctrl+M. \$\endgroup\$ Commented Apr 12, 2016 at 21:24
  • 1
    \$\begingroup\$ There we go, that seems to be working. (It wasn't at first, then I noticed I had connected the + rail to 3.3V...) What's the purpose of the 47K resistor? That's the one part I'm not totally clear on. \$\endgroup\$
    – db2
    Commented Apr 12, 2016 at 22:49
  • \$\begingroup\$ @db2 I think that 47K resistor is what's known as a pull-up resistor. When high-impedance electrical inputs are not connected to anything, like the PNP transistor base or your Arduino input pins, they are floating at some random voltage. The 47K resistor ensures that the PNP base defaults to 5V, but, as it's a big resistor, it is still easy for the SNS to lower the voltage. See here: learn.sparkfun.com/tutorials/pull-up-resistors \$\endgroup\$
    – dpdt
    Commented Apr 13, 2016 at 1:14
  • \$\begingroup\$ @dpdt Oh right, that would make sense. The chip's Vcc would be getting its +5V through the base of the PNP, right? I was thinking it was getting powered through the 47K, and was a bit perplexed why that was still working. I need to pick up a better electronics book this weekend; I've got one that's great if you want to study theory and physics - it's a bit like a cookbook that starts with how to farm and raise livestock - but I need something that starts with practical uses, and then delves into the how/why. Thanks for the help everyone. \$\endgroup\$
    – db2
    Commented Apr 13, 2016 at 11:21

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.