Input And Output On A Single Pin

IO

[Emilio] has a Raspberry Pi with a few sensors running totally headless. It’s a great way to gather data and post it on the Internet, but for the rare occasions when the Pi needs to be turned off for maintenance, [Emilio] needs to connect a monitor, a keyboard, and a mouse. Not a perfect solution when a simple pushbutton and indicator LED would suffice. There’s one problem with adding a simple button and LED combo: there’s only one GPIO pin available in the setup. That’s nothing a few resistors won’t fix.

After wiring up a very simple circuit on a piece of perfboard, [Emilio] met his design goal of being able to tell if the Pi was running and giving it a software reset button using only a single GPIO pin. The circuit requires only two resistors, and the software to make everything run – a simple Python script – toggles the pin between input and output, checking if the button is held down for five seconds. If it is, the Raspi powers off for [Emilio]’s routine maintenance.

15 thoughts on “Input And Output On A Single Pin

  1. This is clever, although I have seen it before in some very old 6809 homebrew designs. It’s a great way to save pins but,

    The I2C expander chip is brain dead easy to use and they are cheap at $1.95 each. I have ran 4 of them on the same i2c port on the pi without problems. MCP23017 if you need 16 pins, MCP23008 if you only need 8. I buy them 10 at a time through ebay for about $1.95 each shipped.

    1. that’s lovely, except regardless of how cheap the expander is this solution is cheaper!

      your solution of expanding to get more pins rather than using existing pins more efficiently adds more board space needed, extra components needed etc.

      and for what? to get the same functionality as this guy gets with a single pin?

    2. i find it fascinating how those things cost more than a micro with more resources that could act as an i2c slave and do so much more… if only someone bothered to make the software.

      On another hand, you can actually use 2 LEDs on a pin and a button.

  2. With one more resistor, you can make it so pushing the button doesn’t visibly affect the LED state. See the bottom center of the schematic here: http://www.parallax.com/sites/default/files/downloads/32203-Spinneret-Web-Server-Schematic-Rev-A.pdf

    When the pin is an output, pushing the button will not effect the current through the LED. You can poll the switch by switching the pin to an input, reading it, and switching it back. If the button is pressed a very small amount of current will flow while the pin is an input (about 15 microamps) but most microcontrollers can poll in less than a microsecond, so the light emitted from the low current over a short time is imperceptible.

  3. OK, not to be rude but this technique has been used in electronics magazine projects and online projects since hobbyists and home EE’s started playing with microcontrollers.
    Is HaD trying to claim this is some sort of novel new “hack”?
    Every time I come to this site, I see pages of things which have been known/done forever, but being published as something new… Wth?
    You can turn a single analog pin on a microcontroller to a 4-bit input with 1-bit output with only some resistors, push button switches, an LED and a single JFET… It has been done forever… And you guys are amazed by a 1-bit in, 1-bit out pin???

      1. There’s a bunch of Android apps that do this (and quite a lot more) for the button on headsets. The one I use does pause, next track, previous track, start of current track, volume up, volume down, answer/end call, decine call/mute mic, and still has one combination I don’t use. Android ‘phones are reasonably popular, and my NSA-friendly friend has one on his iPhone. This trick has also been used on Arduinos for ages too.

        I agree with your posting it for people who don’t like search engines, and the general point that more information is better than less, but perhaps you should remember (and be flattered) that a lot of people come to this site for the novel, clever, and cool – Not for reminders about how Ohm’s law works.

        Just saying…

        1. Exactly. The title of this site “Fresh hacks, every day” is a joke. Nothing posted on this site is done by anyone who works for the little group of people who own it. They simply link to stale projects that have been done a thousand times over, and make no attempt to encourage people to build something from scratch and actually understand it.

          Back in the day, you didn’t get the level of detail that you get with these projects now. There were many “blanks” left which you would fill in yourself, and you would LEARN something as a result of this. Now, it’s mimic, mimic, mimic, with no understanding. I have absolutely no respect for this “maker” group of people, as the group has demonstrated with great clarity that it is made up of three types of people (These percentages are estimates, but based on what I have seen over the past decade, this is close):
          1 – 0.1% people who actually do NOVEL things, build projects from scratch, learning a great deal in the process.

          2 – 10% (call it 9.9%) people who do things that have been done a thousand times before, post their “project” online with or without the intent of claiming it is novel (some do try to claim they have created a “hack” or something novel, they are a joke; those who don’t claim this are simply trying to be helpful and understand that there is nothing new nor exciting about their project).

          3 – “The other 90%” – The mimics – Those who find these projects on the internet, copy them verbatim, learn nothing, do nothing novel, make no novel improvement, and ultimately waste their time doing this over and over and over. These are the mimics. Their time is worthless, I sometimes wonder if they all live in their parent’s basement, living off of EBT cards. Or their parents pocketbooks. Or maybe they are those 5+ year college students who make the choice to fail pathetically easy college classes, or participate in university-level government welfare handouts (they call it “graduate work” or “research”, lolol).

          This is why HaD and other sites like it are a joke, and everyone knows this but the mimics. Poor mimics.

          1. The sole purpose of my blog is to make electronics accessible to those who don’t work in it or didn’t go to school in it. So yeah, they can mimic my step-by-step instructions, and hopefully expand it. I guarantee you’ve “mimiced” quite a lot (read books, do you?), but you’re not being honest with yourself.

  4. This “hack” was mine. I don’t think it will win the “hackaday prize”, for sure- I’m accustomed to electronics and firmware from over 30 years and obviously this circuit is very old and many experts (or not so experts) will know such kind of arrangement… But now, there are millions peoples that doesn’t know nothing about electronics and software, but are buying the Raspberry Pi board just to learn both programming and interfacing other electronics and even a small circuit can help them to add something to their knowledge. That’s all. I’m not a genius, that’s clear to me, but I like to share my (limited) knowledge.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.