Introduction: Octoprint Enhanced Control

Hello everybody!!

I just wanted to control remotely my 3d printer, so I got a raspberry pi.

I setup octopi/octoprint and everything ran smoothly but I couldn't power off the printer main power remotely.

Trying to find solutions on the net I found this instructable from MakinThings.

So I decided to control not only the light, but also the main power for the printer.

Step 1: Materials

  • Raspberry Pi: The core for the control system is the raspberry. I got a Raspberry PI 3 Model B+. Probably any other raspi model would run octopi smoothly. If you already have one running don't change it ... if something works, don't touch it!!
  • Relays: You'll need a relay that can be operated through the GPIO system of the raspi. I chose a module with two relays able to drive 250V/10A. It is far enough for this project but are soooo cheap. I got this, but sure there are other options.
  • You'll need a case to hold the raspberry and the relays. Well, maybe this is not a must. The case is designed for the form factor of the raspi 2 B+ and the model 3 B+. It fits perfectly. You'll need to print it, so a 3d printer and a little bit of filament will be great.
  • Light: If you want a light you need a light ... and adequate power source. I use a 12V DC LED strip and a recycled PS from an old router.
  • Stuff: Of course, you'll need wires, screwdrivers, terminals, some tools, time, ... that stuff that need every maker-man.

Step 2: Case

First of all I designed and printed a new version of my raspberry case adapted to hold the components. I published the STL printable objects on thingiverse.

Easy. If you reached this part of the tutorial I'm pretty sure you know how to print it ...

Step 3: Connections

The connections are easy. Everything is just an extension from this instructable.

First you need to power the relay module. Keep the jumper in the position JD-VCC - VCC and conect:

  • Relay pin GND to Raspi pin 9 (or any other free GND pin)
  • Relay pin VCC to Raspi pin 2 (or any other free 5V pin)

For the command signal you need to find out two gpio free pins (I'll use WiringPi gpio 0 & 1, pinout 11 & 12)

  • Relay pin IN1 to Raspi pin 11
  • Relay pin IN1 to Raspi pin 12

Connect the output relay 1 Normaly Open to the positive of the LED strip and the other to the positive of the 12V DC Power source (negative goes direct to the LED strip).

For the main power of the printer I inserted a terminal, and deriven one of the poles to the relay 2 to control it.

It's pretty easy when you see the pictures.

Step 4: Programming

I suppose you have already octoprint working. If not you might check how to download and install octopi.

Find out your local IP and conect via ssh to your raspberry.

My octopi installation had already installed wiringpi, but if you need to do it:

sudo apt install wiringpi 

You can check that it works fine and list the raspi pinout with

gpio readall

If everything is ok now you can switch the relays. Just check this commands from the command line:

Light ON:

gpio mode 0 out && gpio write 0 0

This command line will try to put the gpio pin in "out" mode, so it can drive the relay. If everything is ok it will try to write a 0 to close the relay circuit (this relays are active at low level). The command will return error in case of any problem, making possible to octoprint to show us through a message.

Light OFF

gpio mode 0 out && gpio write 0 1

Printer ON

gpio mode 1 out && gpio write 1 0

Printer OFF

gpio mode 1 out && gpio write 1 1

Test that all commands acts as you want. You can check them easily before making the final connections checking the relay noise when opening and closing. Also a multimeter can be useful to assure you actually power on when you try to power on ...

When everything is conected we can add this commands to the octoprint menu to execute them easily from the web interface. To do this you must edit the file:

.octoprint/config.yaml

Don't forget the initial dot.

At the end of this config file, inside the system section (if there is no system section you must create it) you must add the actions to execute the comands tested previously.

This is what I added to my config. Change the names, the text or the options to fit your needs.

system:
  actions:
  - action: light_on
    command: gpio mode 0 out && gpio write 0 0
    name: Light ON
  - action: light_off
    command: gpio mode 0 out && gpio write 0 1
    name: Light OFF
  - action: divider
  - action: printer_on
    command: gpio mode 1 out && gpio write 1 0
    name: Printer ON
  - action: printer_off
    command: gpio mode 1 out && gpio write 1 1
    confirm: You are about to shutdown the printer main power.<br><b>Be warned that any ongoing print job will be abruptely interrupted.</b>
    name: Printer OFF

The confirm line makes octoprint ask for confirmation before executing the action. I added it to avoid powering off the printer accidentally with an ongoing printing job. You can change the confirmation message as you wish.

When the command is executed correctly, octoprint shows a green banner confirming the action. In other case you get a red one showing an error message.

Enjoy!