Wednesday 20 January 2021

Remote power control with Octoprint

10A relay module

     Over the last couple months I've been working on a bunch of secret stuff and workshop upgrades, more on those later in the year, but one project I can share is converting the Mega Kossel to full remote control via the attached Octoprint node. Out of the box Octoprint allows for the attached printer to be monitored via USB and an optional webcam, but there isn't any means of switching the printer on or off remotely, resulting in a lot of wasted electricity to maintain it in a state of 'ready to print'. The solution for this problem requires a bit of hardware modification along with installing an optional plugin for Octoprint called 'PSU Control'. I'm going to start with the suprisingly simple hardware addition first.

Tools and parts for remote power control upgrade

      The primary addition needed to control the power state of the 3D printer, (North America only), is a common 10A relay of the type found in a lot of hobby electronics kits, I'm using this one from Amazon, but there are lots of variations to chose from, it just needs to have 5V switching logic for compatibility with the Raspberry Pi. The rest of the tools and supplies are some 16/18 gauge wire, 3 DuPoint jumper lines, a couple female spade connectors, a wire-crimp/striper tool, and a couple screwdrivers, #0 and #1 Philips in my case. I've also printed a case for the specific relay module, but any electronics project enclosure will work, this is a key safety precaution since the relay will be switching mains power and the terminal block does have exposed metal on the top and front, so this modification is at your own risk.

Inside of power socket/switch with target wire removed.
     The first step is to unplug the printer and unscrew the power switch/socket assembly, this usually is just taking 2 screws out from the top and bottom holes. Once the socket is out, there are a bunch of wires that lead to the power supply, we want to remove the short section of wire that leads from the fuse to the power switch, this is going to be replaced with some leads to the relay. 
Relay polarity wiring
     Wiring the relay is fairly simple, we want it connected in the normally closed (NC) position. This allows the printer to still be used normally if the Octoprint node is offline for any reason. The other end of the 18-gauge wires should be crimped with the spade connectors, then one goes on each exposed blade in the power switch assembly.
Final Relay to Pi wiring
     On the OctoPi side, we're connecting to the 5V, 3.3V, GND, and one of the data pins on the Pi's GPIO, so you will need a 15W power block for the pi to prevent performance issues when the relay is active. Firstly I've pulled the coloured jumper and am using the relay board in isolated mode to prevent damage to the Pi's 3.3V logic systems. Full pinout is pin 2(5V) to JD_VCC, pin 1(3.3V) to VCC, pin 6(GND) to GND, and pin 13(GPIO) to IN1/Control. Of these, the only one you'll need to note down is which pin the control line is on. We'll need this number to configure the plugin in the next step.
Octoprint Settings with PSU Control installed
     Installing the PSU Control plugin is fairly standard for Octoprint, just searching 'PSU' in the plugin manager brings it up, after that it's just clicking 'install' and follow the prompts. Once the plugin is loaded, scroll down to the page shown above and switch the switching mode to 'GPIO', then enter '13' in the box below. After that scroll down to 'Power On Options' and enable 'Connect when powered on' with a 10 second delay and you're done for basic configuration. There's also a couple options to automatically shut-down the printer when idle or finished printing. These make it so the printer will stay completely dormant when not in use, ideal for when doing long prints that finish at odd hours.
Completed install before testing