Author Topic: Raspi button hacking  (Read 796 times)

0 Members and 3 Guests are viewing this topic.

Offline matts-ukTopic starter

  • Contributor
  • Posts: 46
  • Country: gb
  • select * from user where clue = null
Raspi button hacking
« on: May 02, 2024, 12:53:05 pm »

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. 

 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13009
Re: Raspi button hacking
« Reply #1 on: May 02, 2024, 01:12:12 pm »
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.
« Last Edit: May 02, 2024, 01:21:16 pm by Ian.M »
 

Offline matts-ukTopic starter

  • Contributor
  • Posts: 46
  • Country: gb
  • select * from user where clue = null
Re: Raspi button hacking
« Reply #2 on: May 02, 2024, 03:53:03 pm »
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.

 

Offline zilp

  • Frequent Contributor
  • **
  • Posts: 329
  • Country: de
Re: Raspi button hacking
« Reply #3 on: May 02, 2024, 04:05:45 pm »
What I am trying to do is read the state of a soft power button with a Raspberry Pi.

Is 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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13009
Re: Raspi button hacking
« Reply #4 on: May 02, 2024, 04:21:49 pm »
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.
 
The following users thanked this post: matts-uk

Offline matts-ukTopic starter

  • Contributor
  • Posts: 46
  • Country: gb
  • select * from user where clue = null
Re: Raspi button hacking
« Reply #5 on: May 05, 2024, 04:21:28 pm »
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.
Will definitely be giving it a go at some point.  Do they need to be Schotkkey?  I have plenty of 1N4148s hanging about.

Quote
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.
Thanks 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 II

I need to invert one of the inputs.  The transistor is a BC547

2165962-0

2165968-1

Same questions as last time.

How sensible?
Any glaring flaws?
What could be improved?
« Last Edit: May 05, 2024, 04:23:31 pm by matts-uk »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13009
Re: Raspi button hacking
« Reply #6 on: May 05, 2024, 04:33:35 pm »
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.
« Last Edit: May 05, 2024, 04:38:54 pm by Ian.M »
 
The following users thanked this post: matts-uk

Offline matts-ukTopic starter

  • Contributor
  • Posts: 46
  • Country: gb
  • select * from user where clue = null
Re: Raspi button hacking
« Reply #7 on: May 05, 2024, 04:36:49 pm »
Is there any reason why the button needs to be connected to +8.5 V or why it can only provide ~ 400 µA?
8.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.

Quote
The circuit as-is certainly is weird, and probably way overcomplicated, though the latter depends on requirements.
That's why I'm asking questions in the Beginners forum ;)

I know enough to hack a circuit together and carry out simple repairs but no way am I an EE designer. 
 

Offline zilp

  • Frequent Contributor
  • **
  • Posts: 329
  • Country: de
Re: Raspi button hacking
« Reply #8 on: May 05, 2024, 05:47:52 pm »
Is there any reason why the button needs to be connected to +8.5 V or why it can only provide ~ 400 µA?
8.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.

... but why "upstream"?! Like, why don't you just use the 3.3 V, say?

Quote
The circuit as-is certainly is weird, and probably way overcomplicated, though the latter depends on requirements.
That's why I'm asking questions in the Beginners forum ;)

I know enough to hack a circuit together and carry out simple repairs but no way am I an EE designer.

Yeah, 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.
 

Offline matts-ukTopic starter

  • Contributor
  • Posts: 46
  • Country: gb
  • select * from user where clue = null
Re: Raspi button hacking
« Reply #9 on: May 05, 2024, 11:23:01 pm »

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?

I 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.

Quote
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.

The 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.
« Last Edit: May 05, 2024, 11:24:39 pm by matts-uk »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf