Raspi button hacking - Page 1
Forum section: electronics / beginners

author: matts-uk
author_rank: Contributor
timestamp: May 02, 2024, 12:53:05 pm
content: What I am trying to do is read the state of a soft power button with a Raspberry Pi.I put a circuit together on a bread board with parts in the recycle pile. Pretty sure the opti is a PC817. It seems to work but before commiting to strip board and connecting up, I thought I would ask for a second opinion here.How sensible?Any glaring flaws?What could be improved?Constructive critique is appreciated.

author: Ian.M
author_rank: Super Contributor
timestamp: May 02, 2024, 01:12:12 pm
content: Unless there are long wires between the button and the Pi, optoisolation is pointless!What's wrong with a simple resistor potential divider, say 20K upper, 12K lower to reduce the 8.5V to approx 3.2V to suit the Pi's input + Schottky dual series diode BAT54S or similar, clamping the GPIO to Pi 3.3V and Gnd? During initial power up, before the Pi's 3.3V rail comes up, the clamp can dump 260uA into the 3.3V rail when the button is pressed, but since the Pi's 3.3V rail current consumption is over 50mA at idle, that's not a problem.

author: matts-uk
author_rank: Contributor
timestamp: May 02, 2024, 03:53:03 pm
content: Thanks for the suggestion.The wire between the button and the Pi is about 200mm long.The 817 has two advantages over a BAT54:I have a handful I can salvage from an old board.Easy to fit in bread board and strip board.

author: zilp
author_rank: Frequent Contributor
timestamp: May 02, 2024, 04:05:45 pm
content: Quote from: matts-uk on May 02, 2024, 12:53:05 pmIs there any reason why the button needs to be connected to +8.5 V or why it can only provide ~ 400 µA?The circuit as-is certainly is weird, and probably way overcomplicated, though the latter depends on requirements.

author: Ian.M
author_rank: Super Contributor
timestamp: May 02, 2024, 04:21:49 pm
content: 200mm isn't very long. 10nF between GPIO and Gnd may be added if it does pick up too much noise. Instead of the SMD BAT54S, you can substitute 2x any other small signal axial leaded Schottky diode you have handy, one between Gnd and GPIO, and the other between GPIO and +3.3V, both cathode positive. Anything rated for 30-200mA and <=100V should be suitable, but avoid >=1A or >100V power Schottky diodes.However, what you've designed wont harm your Pi, so if it exactly meets your requirements, and you can build it immediately, for free out of junkbox parts, the only downsides are its size and complexity, and the extra approx. 5mA current it wastes.

author: matts-uk
author_rank: Contributor
timestamp: May 05, 2024, 04:21:28 pm
content: Quote from: Ian.M on May 02, 2024, 04:21:49 pmWill definitely be giving it a go at some point. Do they need to be Schotkkey? I have plenty of 1N4148s hanging about.QuoteThanks for this. Indeed my weird circuit didn't blow up my Pi and I made some good progress yesterday. Not bothered about a few milliamps. There is an audio amplifier involved and the nominal draw is around 8 Watts.Part III need to invert one of the inputs. The transistor is a BC547Same questions as last time.How sensible?Any glaring flaws?What could be improved?

author: Ian.M
author_rank: Super Contributor
timestamp: May 05, 2024, 04:33:35 pm
content: The reason for Schottky clamp diodes to protect MCU and logic inputs is their low Vf relative to a Silicon PN junction. This means they will take the bulk of the current rather than sharing it with the silicon junction ESD diodes (or other clamping structure) inside the chip.For your transistor inverter, get rid of the 220K from collector to gnd. As the pullup is to 3.3V it does nothing useful. Instead put it base to Gnd to mop up any leakage current to ensure the transistor is fully off when the switch is open. The resistors chosen will give quite a slow response but still far far faster than a human can press a button.

author: matts-uk
author_rank: Contributor
timestamp: May 05, 2024, 04:36:49 pm
content: Quote from: zilp on May 02, 2024, 04:05:45 pm8.5V is the maximum voltage measured at the switch when powered by a 9 volt wall wart. 400uA is a finger in the air. I figure half a milliamp is not going overstretch anything upstream.QuoteThat's why I'm asking questions in the Beginners forumI know enough to hack a circuit together and carry out simple repairs but no way am I an EE designer.

author: zilp
author_rank: Frequent Contributor
timestamp: May 05, 2024, 05:47:52 pm
content: Quote from: matts-uk on May 05, 2024, 04:36:49 pm... but why "upstream"?! Like, why don't you just use the 3.3 V, say?Quote from: matts-uk on May 05, 2024, 04:36:49 pmYeah, sure. It's just difficult to make suggestions if one doesn't know what your requirements actually are.Like, do you actually *need* the button to connect to +8.5 V, or was that just what you used because it worked with your circuit? Do you need the button to not be loaded with more than 500 µA, or was that just what you used because it worked with your circuit?Simplification usually means to achieve the same goal in a different way, not to build the same circuit with different components, and that requires some understanding of what about a circuit can be varied while still fulfilling the function.

author: matts-uk
author_rank: Contributor
timestamp: May 05, 2024, 11:23:01 pm
content: Quote from: zilp on May 05, 2024, 05:47:52 pmI would say the requirements are in the first post.The button IS connected to 8.5V. The button is a soft power button mounted on the front panael of a device I am shoe-horning a Raspi inside of. I want to read the state of the button to add some parallel functionality. Part II, now I can read the power button I want to read other buttons on the front panel but need an 8.5V logic high to pull a 3.3V GPIO pin low.QuoteThe button is the button. The Raspi is the Raspi. What is in the middle is up for grabs. I'm very open to suggestions.I had some spare time to spend on my project this weekend but only with the compoents in my parts bin. This weekend what works was more important than what is best. I can always revisit this small part of the project after ordering the necessary parts and waiting on delivery.I've ordered som Schotkkeys.