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:
- GND from ATX PS
- GPIO signal from RasPi
- 5V STB from ATX PS
- 5V to on button
- Signal from on button
- 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)