Switching the RasPi on/off like a PC

raspberry-pi

#1

Hi there!

I just made a tiny extension to the ATX PS I use for my Prusa i3 MK2.5.

For a Raspberry Pi can be shutdown like a PC, the PS should know about this circumstance.
I developed this schematic:

These is the connector pinout:

  1. GND from ATX PS
  2. GPIO signal from RasPi
  3. 5V STB from ATX PS
  4. 5V to on button
  5. Signal from on button
  6. To Power On of ATX PS

and here is the sketch of the ATtiny 45:

   const int PowerOn = 2;       //Power on via MOSFET
   const int PowerButton = 1;   //Power on Button
   const int GPIOin = 3;        //GPIO Signal from RasPi
   const int DelayLED = 4;
   const int DelayTime = 22000; //44 seconds (two times for loop)
 
   int Started = LOW;           // is needed to remind the start up   
   int delayLoop = DelayTime/1000;
 
 
 void setup() {
   pinMode(PowerOn, OUTPUT); 
   pinMode(PowerButton, INPUT);
   pinMode(GPIOin, INPUT);
   pinMode(DelayLED, OUTPUT); 
   digitalWrite(PowerOn, LOW); //PS off
   digitalWrite(DelayLED, LOW); //LED off
 }
 
 void loop() {
   if (digitalRead(PowerButton) == HIGH)              // someone pushed the On Button
   {
    digitalWrite(PowerOn, HIGH);                      // power up the PS 
   }
   
   if (digitalRead(GPIOin) == HIGH && Started == LOW) // OctoPrint running but not already confirmed?
   {
    Started = HIGH;                                   // confirm start.   
   }
   
   if (digitalRead(GPIOin) == LOW && Started == HIGH) // OctoPrint shuts down the RasPi and start is still confirmed?
   {
    for (int count = 0;count < delayLoop; count++)    // then let's wait...
    {
     delay(125);                                      // ... and blink a bit (the ATtiny 45 needs 125 for a second)
     digitalWrite(DelayLED, HIGH);
     delay(125);
     digitalWrite(DelayLED, LOW);
     if (digitalRead(GPIOin) == HIGH)                 // ok, the server is already up again (=Restart)
     {
      break;                                          // and back to work
     }
    } 
    if (digitalRead(GPIOin) == LOW)                   // still shut down?
    {
     digitalWrite(PowerOn, LOW);                      // Power off
     Started = LOW;                                   // unconfirm running 
    }
   }
 }

I made it on a breadboard with some additional LEDs

How it works:

When the Button is pressed, a signal goes to PB1.
The ATtiny indicates that and sets PB2 to HIGH. The MOSFET is opend and the ATX is turned on.

When the RasPi with OctoPrint is powered up, a GPIO has to be set to HIGH. I used the Enclosure Plugin for this. It gives the posibility to set a GPIO pin with the OctoPrint server start.

The sketch sees the GPIO as HIGH and sets a remainder variable.

When you shutdown OctoPrint and RasPi , the GPIO pin goes LOW. The ATtiny recognizes this but waits about 44 seconds because it could be a restart (this is re reason of the remainder variable).
Usually The server restarts within 36 seconds, the GPIO pin is HIGH again and nothing more happens then.
Is the GPIO pin still LOW after 44 seconds, the ATX PS is shut off and the remainder variable is set to LOW.

In the ZIP there are the sketch and the Target 3001 files
PowerO_O.zip (16.7 KB)


How to make printer with octoprint available to be turned on, on command?
How to make printer with octoprint available to be turned on, on command?
Power switch for OctoPi via GPIO pins
#2

@Ewald_Ikemann,

This looks great. I'm not much into designing circuits, so this would be very helpful. That said too, I'm not an expert at reading schematics... I think I do understand yours, but I want to confirm that the heavy black lines at the bottom of the drawing are Ground (GND), the same as pin 1.

Do you have any thoughts on what it would take to make a dumb power supply (non-ATX) power supply be controlled in a similar fashion? There are definitely some advantages to an ATX in that it splits off 5V and 12V for you in one device, but I already have a rig setup and if I could just figure out how to add some electronic to make it act like an ATX, that would be great. When I say "act like an ATX", only would need to in as much as a soft button power up and an auto-power off after a shutdown.

Any thoughts would be appreciated.


#3

Hello @Jim!

Sure, this is also usable with conventional PS.

So you need an all time 5V/0.1A supply for this circuit.

Instead of the MOSFET (BS170) you can control one of these small relay boards.
grafik

When you have a 12V (or 24V) PS for your printer, you can switch it on/off on the mains side.

Be aware what you are dealing with. 120V/240V is deadly stuff.

Either you need a second PS with 5V/2.5A output or a down stepper from 12V/24V to 5V at least 2.5A for the RasPi.
(https://www.amazon.de/MissBirdler-USB-7V-24-KIS3R33S-Spannungswandler/dp/B01M351H6H).

With the second solution keep in mind the needed power of the printer. If the 12V24V PS is to weak, you get problems with the RasPi.


#4

@Ewald_Ikemann Can you post the actual images of the device and connections so we can see what it looks like in real life?

Also what is the benefit/difference of this mod vs just turning it on off at the power switch?

Please post the complete parts list..


#5

Hi @madmax2 !

First to the benefits: It's like a regular PC that you shutdown via software. The hard way (disconnecting from power) includes the problem that you may terminate an important procedure that write something to the storage and in a bade case destroys the directory structure of the SD card. In short: It's safe.

I already fitted all the hardware into the enclosure:

I first planned to make a PCB, but for just one board...

I've enclosed the Target 3001 file in the first post.
There you can extract the BOM.


#6

@Ewald_Ikemann
So when you issue the shutdown command in the octoprint menu
it will completely power off the raspberry pi?

This is a pretty good mod then since it can also be implemented in a kodi raspberry pi..
because when I do a shutdown, I still need to physically turn off the power switch.
If it can completely turn off the power then that is pretty good.
Could it be used like in that case I stated?

Also is it possible for you implement a physical switch so we can turn it on/off the rpi like a normal PC?
So if we press press the button it will initate a shutdown command

And when it is completely powered off, if we press the button, it will power on the rpi (like a pc)?

Can we also add a restart button (like the pc) and issue a restart when the button is pressed?


#7

Yes, the RasPi is completely without power then.

Usually you have a main switch on the ATX PS. So you can power everything of. Also in case the RasPi stucks completely.

And yes, just a button to power on. Tap it and it starts.

In the moment I use just use the feature in the web frontend to reboot the RasPi.
It could be possible to implement a second button via a GPIO pin, but I think there is no plugin that can activate a restart by triggering from the GPIO. On my own part, I'm not quite involved in creating plugins.


#8

This is an interesting project. I have been working on something similar to this. The ATXPiHat. There are currently two versions, outside of controlling on and off of the printer, they have all sorts of other features, LED support, sensors, etc. I am building a new one that is significantly stripped down. I also provide a Plugin for Octoprint specifically for V1 and Zero version of the boards. I am modifying the software as we speak to handle the "Lite" or stripped down version. The design difference is that I leave the Pi running. There is no harm doing this and it allows for access to the printer without having to be close to it. Good luck with this project. Looks great.


#9

Hello @banichow!

Yes, I saw your ATXPiHat and I was about to use it. But my attempt was it to power down the pi too.
So a lot of success wit your project too :+1:


#10

do you have the pic of the button that power on the rpi and how do I add it to the circuit?

Is it connected to the rpi GPIO ?


#11

It's a simple push button and is connected to the pins 4 (+5 STB) and 5 (PB1 of the ATtiny) of the connector K1


#12

can you still post a pic?
It would be easier to see what and how is connected to the pi or circuit


#13

So, back from work now.
For I've already fitted the stuff into a case, I here have an extended schematic diagram:

The colors mentioned are those of an ATX PS.


#14

I did something sort of "remotely" similar, but, not quite

My goal was to turn on and off the Pi without actually physically touching anything

So I used the purple wire on the ATX just like you did to power the Pi, and a relay attached to the Pi to short the green wire to initiate the "on" sequence of the ATX which then powered the printer

As to the on and off of the Pi, I sent a shutdown command, then, I had an Alexa outlet power down the ATX. For "ON", I sent the "on" to Alexa outlet, then I used the enclosure plugin to switch the relay

It's extremely primitive, but, I established my goal of on and off without touching it, or even being in the same room, or, in fact, the same town (as long as I have an internet connection to my phone to talk to alexa)

From the white papers I've read, it seems that Alexa is secure, unless somebody is in the room with an active Alexa device.

I've not tried the "drop in" function yet tho... That seems worth looking in to...