Powering off via UI while using a Mausberry Circuit
-
@caver01 I was on the wrong track - sorry!
But there is an solution... you need a Solid State Relais like this and connect the output in parallel direction to your switch. So you can use the switch or the SSR...The innput for the SSR is annother GPIO in ouput direction... if you set now echo 1 command in this GPIO direction.. LED inside the relais will glow and switch is closed.
So you have 2 switches ... the physical and one software remoted. I have some of these bought cost 1$ each and work fine.
@caver01 What happens if you change direction to the second GPIO?
-
What happens if you change direction to the second GPIO?
If we change direction on pin 24, I can’t write to it. I tried change the value too and it does nothing.
I think I will look into the relay option. Do I need any other components such as resistors connected anywhere? I don’t think I have ever hooked up a relay before.
-
@caver01 I'll be back ;)
I tried change the value too and it does nothing.
I can't get this... Was there an error message? So can you please test if you change status uf $GPIOpin2 with sudo command
sudo echo "1" > /sys/class/gpio/gpio$GPIOpin2/value
It is setted to 1 what happens if it is setted to 0?I don't get what the purpose. It seems like a check state... for, is the Pie is running!
As the mausberry contains a AVR µc I can't get it why the developer sends voltage output and does not wait for receiving a signal?As you mentioned:
is there a way to force the signal on the GPIO pin itself so that the MB circuit hardware really DOES detect something? This would get picked up by the script too.
and I said:
Maybe you're right and the hardware button does something with the mausberry but as far as I understood the mausberry works with permanent and momentary switches
the mausberry sends a high signal to the Pie..... sadly!
I tested with a switch and LED and I was able to trigger the switch by change input to output direction. But as the MB sends the signal.... it won't work like that.
About the opto-mosfet... yes you will need a resistor to not damage the build in LED. For 3.3 V I used 330 Ohm. But those values are in the data sheet delivered with the IC. I think that will be the nicest way to get the mausberry full working and you need just to plug one more GPIO. And this device acts as a switch... I think the resistance is just 1 Ohm... that's a very bad value for a "switch" but it will surly work.
-
@cyperghost
If I set the gpio2 (actually, it's wired to 24) to "0" it does nothing.That pin gets set to "1" in the script, so it must be for monitoring. When the Pi finishes the soft shutdown, the pin will drop, and the MB circuit should see that, right? But my thinking is that the MB circuit doesn't check GPIO2 for drop to "0" until AFTER it detects a button press. Because, if it DID check all the time, it would immediately cut power before the script gets executed that sets it to "1"!
-
@caver01 Yes this behaviour sounds logical.
Man... it could be so easy but I think the SSR is also a good catch. I use one to activate and deactivate the monitor from LCD by switching on/off the video input via GPIO. So in fact it is just the same approach as to toggle a LED on/off. -
It's hard to blame the design--if all you ever do is use the power button, it's fine. But if you do a soft shutdown without using the button, it seems as though the mausberry has no way to detect that, and it sits in a powered state.
-
@caver01 We will change this via SSR-GPIO software switch ;)
-
What I need is a normally open switch that closes when power gets cut. If I wired that in parallel with the power button, it will trigger when the Pi shuts down without any need for a GPIO command to be sent.
<EDIT> ha ha I just read the first sentence on the link to the SSR. Says it is a normally open switch. . . I may have to pick one up.
-
@caver01 Normally means powered, so indeed it should work ;)
-
@cyperghost
Ok, so I was thinking if we had a component that was OPEN when powered, but closes when the power goes off, we could wire this to a power pin and in parallel with the power button. It would trigger the mausberry like a button press when the Pi goes off. But that would make the circuit think the power button is being held down!So, if you plug in the system, it would power up immediately. Maybe it would even loop.
-
@caver01 But the mausberry works with permanent switches?
But I think the real button won't work anymore ;(So use a GPIO to set event on/off ;)
-
@caver01
So you soldering the SSR next to your switch. So you have two switches running.
I'm guessing the hardware switch is a momentary one - with normal state off?
So the SSR can also act as a momentary, unpowered via GPIO it is off, powerd via GPIO it is on....So it think it should work ;)
-
@cyperghost said in Powering off via UI while using a Mausberry Circuit:
@caver01 But the mausberry works with permanent switches?
But I think the real button won't work anymore ;(So use a GPIO to set event on/off ;)
Yep. use it to trigger an actual (parallel) button press.
What I can't figure out is why, even after the pi shuts down with a soft shutdown, the mausberry ignores my button presses. It is like it locks into a powered state. It must be checking the state of Pin 2:
If Pin2 = 0 and power button is closed, DO POWER ON
if Pin 2 = 1 and power button is closed, DO POWER OFFso, after a soft shutdown, the mausberry thinks I am trying to turn the pi back on, but it is already on, so it does nothing. It's like an anti-bounce state, the time right after a POWER ON, but before the script is running and can set Pin 2 = 1.
-
@cyperghost If I get one of these to test, I will need help. Which pin on the SSR goes to what, and which pin gets the resistor?
-
@caver01 page 7 shows connection diagramm
Pin 1 goes to positive value (= GPIO Pin), Pin 2 is ground, set a resistor with right value (330ohm for 3.3V).Pin 3 and 4 is the switch ... Connection does not matter here see page 4, it is independent if you switch the ground or positive value.
-
@cyperghost Looks like the diagram has the resistor on Pin 1. Does it matter?
-
@caver01 No but the resistor has to be placed somewhere in the line (+) LED (-)
So (+) R LED (-) or (+) LED R (-) doesn't matter -
@cyperghost Oh I get it. . . because the device itself uses an LED internally for actuation.
Hey, thanks for your input here and the fun conversation about this. @madmodder123 I hope I didn't overstep by totally dominating your original post. I think we were on the same page with this, and it looks like a little testing may prove that while the Mausberry circuit is an excellent solution for an add-on power switch (especially when coupled with the updated script), it comes with an assumption that the button you add will be the only shutdown method used. It is not setup with awareness of additional soft shutdown procedures that aren't triggered by the button and the circuit itself.
-
@caver01 I'm pretty sure that a normally opened ssr works together with a momentary switch!
Annother suggestion. I think if we use a normally closed SSR and connect it to the $GPIOPin2 so there is no current as long as the Pie is active. But if is inactive it would close the reset pads of the mausberry... do you think that may work?
-
Some "improvments" to the original script! It might be a bit faster as there is no if-then-else....
#!/bin/bash #this is the GPIO pin connected to the lead on switch labeled OUT GPIOpin1=23 #this is the GPIO pin connected to the lead on switch labeled IN GPIOpin2=24 echo "$GPIOpin1" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction echo "$GPIOpin2" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio$GPIOpin2/direction echo "1" > /sys/class/gpio/gpio$GPIOpin2/value power=$(cat /sys/class/gpio/gpio$GPIOpin1/value) until [ $power = 1 ]; do power=$(cat /sys/class/gpio/gpio$GPIOpin1/value) sleep 1 done [ $power = 1 ] && echo "Shutdown now!" && poweroff
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.