3D Printing : Remotely Switch on/off your 3D Printer



Background

I think, like most of the 3D Printer guys, you have your printer in your basement. This is indeed a great place, but it means each time you are about to start a print, you have to go downstairs, start the power switch, and go back at your computer place and star the print. OctoPrint is easy to get remote access to the printer, but, what about controlling the power switch ?!?

OctoPrint

Yes, OctoPrint is great and it runs most of the time on a Raspberry Pi dedicated for that purpose. The nice thing with Raspberries is they potential to remotely control various things with they GPIO ports.
But, wait. Why would I want to remotely control the power switch of my 3D printer ? At the end of the day, I need to be close to it for inserting filament and when done, I need to take my printed part !

True. On top of that, in my case I have a computer in the basement close to the printer. So, why does it worth controlling PSU from a remote location ?

I see two reasons

1) Cool to start the printer on when in the warm atmosphere of my office. Especially when the filament I need is already loaded and ready to use
2) Even better to power the printer off when I realized something bad is happening and I would like to prevent any further waste of material or damage the printer itself.

Both 2 above reasons can be done remotely (with the OctoPrint UI in my LAN) and when I'm outside (using Octo Everywhere plugin). 

How does it work ?

Easy. 

Build of material :
  • Get a cheap Relay switch following your local electrical regulations. Here is the one I used;
  • Get a new power cable - we are going to modify it - here is the one I used;
  • Get 3 Dupont-style cables for signal - here are the one I used; 
The logic I used is the following : 

Connect the power cable of your 3D Printer to the relay using normally closed. This way, the Raspberry must always send a signal to the relay to maintain current. I prefer to use this way, I feel it more safe. Indeed, if there is something wrong with the raspberry, it will not be able to send signal to the relay and then the printer remains off.

You need to cut the brown cable (in Europe, black in US). Pay attention not to damage the cable insulation !


On the relay side, you have 3 PINs. I was lucky, mine comes in Chinese ;) Hopefully, Google translate came to the rescue.


So, from left to right, the PINs are :
  • Normally Closed
  • Common
  • Normally Opened
On the other side of the relay comes Dupont PINs. We need 3 : signal (green), 3V+ (red) and Ground (black).


You need to locate 3 available ports on the GPIO side of your Raspberry and connect the Relay. Important : we are not connecting the power yet on the other side, first, let's test the relay.

I'm using signal PIN number 22 on my GPIO ports. Check if yours can accommodate that PIN otherwise, adjust the script below.

Here is a sample python code to test the relay logic :

$ cat relay.py
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM) # GPIO Numbers instead of board numbers

R1_GPIO = 22
GPIO.setup(R1_GPIO, GPIO.OUT) # GPIO Assign mode

try:
while True:
GPIO.output(R1_GPIO, True) # on
print("Relay ON")
time.sleep(5)
GPIO.output(R1_GPIO, False) # off
print("Relay OFF")
time.sleep(5)
finally:
GPIO.cleanup()

Simply run the script this way : 

python relay.py
Relay ON
Relay OFF
Relay ON
Relay OFF
^C

Every 5 seconds, the relay will switch from Open to Close state. You should hear a click and there is also a LED that turns ON and OFF on my model. Press Ctrl+C to exit.

Af this stage, we have a working relay. We can now attach the power cable to the relay.


I had quickly printed a box to secure the assembly. I used this design found on Instructable (Top and Bottom)

Plugin Configuration

Now, we need to add a specific plugin in Octoprint to be able to control the relay. I'm using PSU Control. This is part of the plugin repository, simply search for it and install it. There are about 4 or 5 PSU control plugin, chose the one below.


When installed and once Octoprint has been restarted, simple go to the plugin configuration and enter the relevant details. The most important is the GPIO PIN used to connect the relay.


To activate the power, there is a lighting icon on the OctoPrint main screen. When greyed out power is off, when yellow, power is on.


Before switching the power off, there is a confirmation dialog (just in case of). On cool option is the "connect when power on". Problem : it is trying to connect too quickly and therefore, it is generating an error message. I would have be nice to have a delay of 1 or 2 seconds before trying to connect. Apart from that, the plugin is perfect !

Plugin in action


I know many people are using wifi connected power plugs, but this is costing a lot ! The above solution is less than USD 5 !!! The real driver is not only the cost, I always prefer to learn something new rather than buying something already packaged.

Special thanks to _Gyro from Instructables.

I hope this will help other ;)







Comments

What's hot ?

Wallbox : Get The Most Of It (with API)

PCBWay : CNC Machining

Nutanix : CVM stuck into Phoenix