If you recall, I have this pretty cheap 3D printer by Monoprice. It’s pretty small/no frills; when I plug it in this is the information I get:
[ 1676.181721] usb 1-1.4: new full-speed USB device number 7 using dwc_otg [ 1676.315211] usb 1-1.4: New USB device found, idVendor=2e26, idProduct=0200, bcdDevice= 2.00 [ 1676.319203] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [ 1676.323298] usb 1-1.4: Product: Malyan 3D Printer [ 1676.327045] usb 1-1.4: Manufacturer: Malyan System [ 1676.330706] usb 1-1.4: SerialNumber: 207936614652 [ 1676.335658] cdc_acm 1-1.4:1.0: ttyACM0: USB ACM device
One of the more nagging things I get though is that it has no power button! So there is no means to turn it off short of unplugging the thing, let alone trying to turn it off remotely. This wouldn’t be a problem if the fans weren’t so loud while it was on.
So began the quest of how do I set up something to remotely turn this on/off?
The answer is to set up a relay that could handle switching on/off AC power to the printer. I instead opted for a more expensive but nicer packaged option that was essentially a power-strip controllable by an arduino, which branded itself as an “IoT Relay”, purchasable here or here. The neat thing about this is that is it’s safely properly enclosed, and the area where you attach the input has a detachable plug.
As for wiring it up, that was just a matter of hooking it up to one of the GPIO pins and ground on the Raspberry Pi. You can get one of these proto boards for the Raspberry Pi, and hook up your own wiring to it. This was a little overkill for my case, but I figured at some point I might add more sensors or something in the future. Attaching it was fairly seamless:
I got some cheap JST connectors to make it easy to detach in future, and soldered it to GPIO 26 and ground.
Et voila! Everything is wired up correctly:
In terms of connecting this up to OctoPrint, there is a plugin called PSU Control in their repositories. I tried to get it to use python native, without any luck, so instead wrote my own bash script and allowed it to be NOPASSWD sudo to control the relay:
#!/bin/bash PIN="26" if [ ! -d "/sys/class/gpio/gpio$PIN" ]; then echo $PIN > /sys/class/gpio/export; fi if [ "`cat /sys/class/gpio/gpio$PIN/direction`" != "out" ]; then echo out > /sys/class/gpio/gpio$PIN/direction; fi case $1 in on) echo "Turning printer on"; echo 1 > /sys/class/gpio/gpio$PIN/value; ;; off) echo "Turning printer off"; echo 0 > /sys/class/gpio/gpio$PIN/value; ;; esac
That’s it! Tune in next time for part 4 in the series as I hook up a timelapse camera to octoprint.