Definitely, you'll want to get your GoogleFu up to speed in order to work on a 3D printer.
I'm fond of the TP-Link SmartPlug device which allows me to attach an IKEA KOPPLA power strip to this. One goes to the printer board, one goes to the Raspberry Pi's power adapter. So now, you can programmatically tell the TP-Link to power off, turning off all the devices at once.
Now for the graceful shutdown, you'll need to tell Raspbian to do so. The REST API within OctoPrint can be exercised to do the shutdown.
As for the button itself, you'll need to create a script to do something when a button is pressed.
Am I missing something. . top of the gui in about the center is a power button icon, click it and select shutdown system.... Then turn off the power to printer and pi..
I am in the process of building new 3d printer and added RPI shutdown button to it just 2 days ago.
I used push button, pull-up resistor and a buzzer. The button is connected to Ground (pin 39) and GP17 (pin 11). 10 kOhm pull-up resistor is connected to +3.3v (pin 1) and GP17. Buzzer, which is optional, is connected to GP19 (pin 35) and Ground. I wrote a script that starts at RPI boot and runs infinite loop checking if the button is pressed for longer than 5 seconds. If it is, buzzer beeps and RPI shutdown is initiated.
If this is something you are interested in, I can share the script.
That would be awesome if you could share that! The buzzer would definitely be added peace of mind. As I’m a bit of a noob I just need to figure out how to run a script in the background but I’m sure there is plenty of information about that on the interwebs. Thanks in advance
First of all - I am very new to Python, so the script is most likely very far from being perfect, but it works.
I am executing it from root cronjob with command:
Take a look at foosel's post here and my previous script attempt before that. She's using an event_detected litmus test to lower the amount of processing time.
You don't need this to be remote so you wouldn't need 75% of the electronics I used. You simply need a button, two wires over to the GPIO pins of the Raspberry and what I discussed earlier.
And of course you'll need the Python code that lmcbmai has provided at least to start.
I managed to install a shutdown button on a raspberry pi running retropie which was a pretty easy task but unfortunately getting one on octoptint is way beyond my skill set. Im in terminal looking at pi@octopi:~ so do you navigate around the same as if you were in pi@raspberry:~ ?. I feel silly for asking but my google fu is out of order on this one.
One easy option is to simply download the octoprint app for a mobile device phone tablet what ever and it takes 2 seconds to shut it down with the app then just unplug it or if you have a switch on the power supply flip the switch.
How do you do a shutdown from the OctoClient? I can’t find a shut button on the app and I can’t find the gcode for shutdown. I tried sudo shutdown-h now with no success and also I need to make the pi address static so I can actually connect to the printer without turning on the computer to access the modem ect ect. I appreciate the help but I’d like a way to turn off the printer all in its own, the old fashioned way.
what do you want to do, shut down the pi or the printer? If the printer, then just turn it off pi can keep running. Last I understood what you wanted, you wanted to shutdown the pi without using the octopi gui.
If you want to shut down the pi from the octoprint gui, top right of center is a power button icon, click it and select shutdown system count to 10 and then turn off the power to the pi and printer. Obviously you have to login to the octoprint and be a user that is setup for controlling the system..
Sorry I should’ve been more clear, when I said printer I meant printer and pi. I have the pi and printer running off the same psu so if I shutdown the pi I can then just flick the power switch on the psu and power will be cut to everything.
That's is what I thought. So you have said you can not find the button on the GUI to shut down the PI, or at least I think that is what you meant. Select shutdown system
I can find the shutdown button on the GUI, it’s the OctoClient app where I can’t find the button and I tried typing “shutdown -h now” into the terminal on the app and that didn’t work.
This is the guide I used. I'm also running my Pi off my Ender 3's PSU using a buck converter. I press the button to shut the Pi down, then I flip my printer's switch off. When the printer is turned back on, the Pi will turn on again automatically without needing to press the button again.