Simple STOP/START button for OctoPi – OctoPrint


Easy STOP/START button solution for stopping and starting 3D printing jobs using octoprint, running on raspberry pi from the printer’s location. The script can be edited to work on any device with GPIO and is meant to be a baseline for more complicated projects.


The code is very simple, every time the physical button is pressed the server check if there is a printer job running if there is one it stops it otherwise it starts a job that is selected.

The software

From the start coming from a default, octopi build we will need to download python-pip

This can be done with these commands.

sudo apt-get update
sudo apt-get install python-pip

The next step is that we will need to enable: Allow Cross Origin Resource Sharing (CORS) and the API as shown below.

For the next step, we will need the API key from this page. Copy the API key.

Create a new script and add the following code: (replace the dummy key with your own API key)

The Hardware

Beyond the Raspberry Pi we will need a button. The one I used was a simple push button from eBay but any button can be used with or without a PCB.


The wiring

Sensor = GPIO26

First test

If you run the script with this command, load a file on the octoprint interface and hit the button that we just connected it should start or stop the print.

Add script to startup

To have the script executed on startup we will need to add a line to crontab.
Open crontab with:
crontab -e
Add this to the last line:
@reboot python /path/to/script/

Replace the path with your own path to the script.

Now if we restart the raspberry the script will be running in the background.

The model

If you end up buying the same button here is a small enclosure for it. Really basic could be printed on low-quality printers too