0
\$\begingroup\$

I've got a machine I'm making (A raspberry Pi with a picade Hat), which has a soft power off functionality (one click to power on, one click to power off).

I'm putting it in a toy which had a key to close the original circuit (turn right to power on, turn left to power off).

There are two pins to manage an external button, but the functionality is the same (If I close the circuit it powers on, if I close it again it shuts down).

Is there a way to make it work as I want it (power on when closing the curcuit, power off when opeing it) ?

\$\endgroup\$
  • \$\begingroup\$ I think you mean a "momentary switch" rather than a temporary switch (which has no meaning). So basically, it sounds like you want the toggle switch to MOMENTARILY connect the two pins every time the toggle state is changed? \$\endgroup\$ – DKNguyen Aug 13 at 22:15
  • \$\begingroup\$ Sorry @DKNguyen, that's updated. And yes, that's exactly what I want to do. \$\endgroup\$ – Marc Brillault Aug 13 at 22:20
  • 1
    \$\begingroup\$ @MarcBrillault It might be easiest to consider a small reed switch, a mercury-wetted variety perhaps, to use in replacing the Hat switch. Then, if you can arrange it, place a simple magnet on the toy key (or whatever the toy key moves inside the toy when you turn it) so that the magnet sweeps by the reed switch. If you imagine the permanent magnet rotation as, say, 90 degrees then you might place the reed switch at the 45 degree position (middle of the rotation.) The switch would be open, then closed for a moment, this way. (It's still possible to get the key out of sync with the PI.) \$\endgroup\$ – jonk Aug 14 at 2:54
  • \$\begingroup\$ @jonk that would be a good hack, but the full key course is currently a little less than 45°, so the magnet could be triggered bu the two positions. I'll still give it a try if everything else fails. \$\endgroup\$ – Marc Brillault Aug 14 at 10:20
  • \$\begingroup\$ @MarcBrillault The reed switches come with different selectable responses to magnet strength. With a smaller range of action, I believe it's still "doable." But you may need to correctly match the magnet with the reed switch to succeed. So it would take some careful thought to select a few reed switches in the right ballpark. It's relatively easy to quantitatively measure your magnet (compass, tape measure, and rough knowledge [easy to get] of your local magnetic field for Earth.) That, and how close you sweep the magnet to the switch, would give you a number to use for buying a reed switch. \$\endgroup\$ – jonk Aug 14 at 18:05
0
\$\begingroup\$

This might work. But it also might not depending on the toggle switch and the debouncing behind the pins on the Pi. It also won't work if the Pi is looking for the momentary pushbutton being released rather than being pressed.

It relies on the time between the toggle switch breaking the original connection and making the new one to imitate a momentary push button. It relies on the Pi remembering whether it is actually supposed to be off or on.

This means that if the toggle switch is in the wrong state when power is lost and then restored (maybe replacing batteries), then the on/off position of the toggle switch will be reversed.

It doesn't make a true pulse but I don't think you can make a true pulse without consuming power on some level all the time. What it does is more like if you pressed the button to turn it on and never let go, only releasing it to push it to turn it off and then never letting go again except to push it to turn it back on.

schematic

simulate this circuit – Schematic created using CircuitLab

EDIT: I just assumed you had a SPDT toggle switch, but you have a SPST switch. From the voltage measurements you have given between the pins and relative to ground, the following should be what is on the other side of the pins. But I fiddled with it a bit and can't make it work with a SPST. There's just not enough degrees of freedom. A large cap in series with the switch will make it pulse low momentarily when the switch is closed, but I can't think of a way to make it to the same when the switch is opened.

schematic

simulate this circuit

\$\endgroup\$
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. Any conclusions reached should be edited back into the question and/or any answer(s). \$\endgroup\$ – Dave Tweed Aug 14 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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