Controlling a 3D Printer's Power Supply with OctoPrint
This will probably be the first in a series of posts about my journeys tinkering with my stock Creality Ender 3 printer. One of the first things I wanted to do after buying the Ender 3 back in August 2020 was the ability to power on/off the printer via the OctoPrint interface. Luckily there is a robust PSU Control plugin that already exists. I just needed to figure out the hardware. I was also able to find this Raspberry Pi enclosure for the Ender 3 on Thingiverse which I've remixed to add a hole for a female barrel connector.
There are various other tutorials about similar setups but none that match exactly what I was looking to do. Hopefully this can help others looking to do the same. Having said that this is by no means the right or best way to do this. It is just the way that worked best for me after a few iterations.
- Keep the Raspberry Pi always powered on
- Turn the printer on/off via OctoPrint interface via PSU Control plugin
- Ability to easily physically disconnect and remove the RPi when needed
- Compact footprint and cable management
- Creality Ender 3 (but could work with any printer running OctoPrint)
- Raspberry Pi running OctoPrint
- IoT Power Relay (Amazon, Adafruit)
- 1ft Power Cord (Amazon)
- Printed Pi Enclosure (Thingiverse)
- A. Dupont 2-pin female connector
- B. 18-22 AWG wire (Amazon)
- C. Heat shrink (Amazon)
- D. Female barrel connector (Amazon)
- E. Male barrel connector (Amazon)
- F. Wire ferrules (optional) (Amazon)
- G. Relay screw terminal (Included with IoT Power Relay)
- Double sided tape (Amazon)
- Wire striper (Amazon)
- Lighter/heat gun (Amazon)
- Ferrule Crimping Tool (Amazon)
- Micro Connector Pin Crimping Tool (Amazon)
- Soldering iron (Amazon)
Mains power is provided to the IoT Power Relay. The "Always On" outlet provides constant power to the Raspberry Pi. By plugging the power cord from the printer's power supply into the "Normally Off" outlet power will not be provided until the Raspberry Pi sends a 3.3v signal to the IoT Power Relay via the wiring we set up.
For the connection between the RPi and the printed enclosure we need a short length of relatively short wire (about 50cm)[b]. Ground should be soldered to the larger terminal on the female barrel connector [d] and power to the smaller terminal. Wrap them in heat shrink[c]. On the other end of the wire crimp and connect the 2-pin Dupont connector[a].
For the connection between the printed enclosure and the PSU controller we again need to solder the ground wire to the larger terminal and power to the smaller terminal of the male barrel connector[e]. Again covering both in heat shrink[c]. The other end can be either crimped with ferrules[f] or plugged right into the PSU connector[g].
Feed the dupont end of the wire through the hole in the print enclosure until the ring of the female barrel connector sits flush with the printed enclosure. Slide the washer and locking nut over the wire and hand tighten until the barrel connector feels snug.
Fit the Pi into the case and plug the dupont connector into the GPIO header. Physical pin 37 for red and physical pin 39 for black.
I just used some double stick tape to adhere the Power Relay to my Ender 3's power supply. This allowed me to have the shortest possible lengths for both the wire from the Raspberry Pi to the power relay and the cord from the power relay to the power supply.
The Pi enclosure slides into the aluminum extrusion of the Ender 3 and then wire connections can be made.
Install the following two plugins to your OctoPrint instance.
- Set Switching Method to
- Set On/Off GPIO Pin to
Enable switching with G-Code commands.
- Set On G-Code Command to
- Set Off G-Code Command to
- Set Sensing Method to
- Set Sensing Plugin to
PSU Control - RPI.GPIO
- Set Polling Interval to
- Set GPIO MODE to
- Set Switching > Pin to
- Set Sensing > Pin to
Save your settings and refresh OctoPrint. You should now have a lightning bolt icon in the top nav bar that you can use to turn on and off your printer.
You should be all set now. Again, this might not be the right or best way to do it. However it is what works for me. If you have any comments or questions feel free to reach out to me via email johnzanussi [at] gmail.com.
Found the above useful? Have a question? Thought of something I didn't?
Consider buying me a coffee, leaving a comment below, or sending an email at firstname.lastname@example.org.