I’m really enjoying my new 3d printer, but I just can’t leave my laptop connected to the printer all the time. I know that i could simply use SD cards or use another host computer, but there are better options. In order to untether myself from the printer I am using a Raspberry Pi and the OctoPrint printer host. This allows me to take g-code that I have generated and upload it to the Pi. Now I can start a print, check on the status, and view the printer through an attached webcam. The webpage also works well on the iPhone so I can keep track of what is going on from anywhere. I can also easily abort failed prints without having to come home to find a stringy mess. As great as that is I don’t like to leave the printer powered on if I’m not using it and I don’t like to leave the lights on when I’m not home.
Step 1: Circuit layout
The solution that I came across was to leverage the different power modes of the ATX power supply (see Ugifer's Arduino treatment of the topic at Instructables). ATX power supplies have a standby mode that allows them to supply 5v at 2.0A while not fully on. This is the ‘standby power’ mode that most PCs use to sense the button press that turns them on. It provides more than enough power to run the Pi and still have the printer off. The printer runs off the 12V power rail when the power supply is in full power mode. The only issue to contend with is that the Pi’s GPIO pin that I want to use to turn on the power supply is 3.3V and the ATX supply needs to sink 5v to turn on. Using just a 2n3904 transistor and a couple of 1k ¼ watt resistors I am able to turn on the powersupply from the Pi.
Step 2: Physical Layout
The lights that I am using are some 12v white LED panels that came from Ebay. They are inexpensive, less than a dollar each, and are common in automotive world for interior car bulb replacements. They can be wired to any black and yellow connector on the ATX supply.
I didn’t want to have a separate board with the components on it or have to buy an ATX connector so I put the parts inline with the wiring and then sealed them in tape and heat shrink tubing.
To get a good connection to the ATX header I pulled some pins off a broken motherboard and put them on the ends of my wires. To hold them in place I just used nylon zip ties around the connector.
Step 3: Software: Wiring Pi and OctoPrint Configuration
To control the GPIO pins on the Pi I installed WiringPi. This library makes it easy to read and set GPIO pins. I chose pins 5 and 6 on the Pi so that I could have a GPIO right next to GND.
The Pi will default to Input mode on GPIO pins so the first step was to issue a command to set the pin mode to Output. (note that the WiringPi pin numbers are different from the physical pin locations on the Pi. The ‘gpio readall’ command will provide a chart of software to software pin mappings. Pin 5 on the board is really 9 in software) From the command line:
‘gpio mode 9 out’
To make this change permanent I added ‘/usr/local/bin/gpio mode 9 out’ to my ‘/etc/rc.local’ file before the ‘exit 0’. (rc.local requires the full path to gpio)
To test the setup:
‘gpio write 5 0’ (set the pin LOW)
‘gpio write 5 1’ (set the pin HIGH)
If the wiring is correct the ATX power supply fan will come on, the printer will turn on, and the lights turn on.
Adding the buttons to the OctoPrint system menu to turn the printer on and off is straight forward. The new commands ‘Printer On’ and ‘Printer Off’ are added to the ~/.octoprint/config.yaml in the ‘system:’ section as follows:
- action: shutdown
command: sudo shutdown -h now
confirm: You are about to shutdown the system.
- action: reboot
command: sudo shutdown -r now
confirm: You are about to reboot the system
- action: restart
command: sudo service octoprint restart
confirm: You are about to restart OctoPrint
name: Restart OctoPrint
- action: Printer on
command: gpio write 9 1
name: Printer On
- action: Printer off
command: gpio write 9 0
name: Printer Off
Restart the Octoprint host software and the new buttons should show up