Control a 3D printer with Raspberry, Docker, OctoPi and Motioneye
Last Updated on 15th September 2020 by peppe8o
One of most interesting uses of Raspberry PI is controlling a 3D printer (mine one is an Anet A6) without needing to be connected with your PC.
This can help for long prints and improve controls available on printer status.
It is also really useful in tuning operations, because it allows to easily control manually your printer motors, so getting fastly correct positioning to improve bed and extruder accessibility and levelling.
What Is OctoPi
OctoPi is a fork from Octoprint, built to run on Raspberry Pi.
OctoPrint is an Open Source project which enables an improved web interface to control 3D printer and printing jobs. It allows to:
- Access the embedded webcam feed and watch remotely how your printer is creating your newest thing.
- Get constant feedback regarding the current progress of your print job.
- Take a look at the integrated GCODE visualizer to see a rendition of the GCODE you are currently printing.
- Keep an eye on the temperatures of your hotends and print bed and adapt them on the fly.
- Move the print head along all axes, extrude, retract or just define your own custom controls.
- Start, stop or just pause your current print job, you are in full control at any time.
OctoPrint and Docker
Everyone knows my love for Docker. But in this case the official Docker image available on Docker Hub is not built on ARM processor, se there is the need to use an unofficial image.
From the various images that I tried, the one from urrizzz user (https://hub.docker.com/r/urrizzz/octopi/) was correctly working on my Raspberry Pi.
Some considerations on Hardware. OctoPrint notifies that the Raspberry Pi Zero W is not recommended since severe performance issues were observed, caused by the WiFi interface when bandwidth is utilized (look here for GitHub issue). So I decided to test it on my Raspberry Pi 3 Model A+, which has also a Raspberry PI camera connected that will be used for video streaming.
What We Need
As usual, I suggest adding from now to your favourite e-commerce shopping cart all the needed hardware, so that at the end you will be able to evaluate overall costs and decide if to continue with the project or remove them from the shopping cart. So, hardware will be only:
- Raspberry PI 3 Model A+ (including proper power supply or using a smartphone micro usb charger with at least 3A) or newer Raspberry PI Board
- high speed micro SD card (at least 16 GB, at least class 10)
- Raspberry PI Camera
- 3d Printer
Step-by-Step Procedure
We start from a Raspbery PI with a light operating system installing Raspberry PI OS Lite. We’ll also need Docker installed (please follow Raspberry PI Docker installation procedure).
The following step is installing MotionEye into a container (also this can be done with the Raspberry PI Motioneye installation in Docker procedure, being careful to map also 8081 port for video streaming).
Before staring, we need to identify the port related to USB. Once your printer is powered on and connected with your Raspberry Pi, type:
ls /dev | grep tty
The port should sound something like /dev/ttyUSB0. Now the power of Docker comes to us and allows OctoPi installation with a single command line:
docker run -d --device /dev/ttyUSB0:/dev/ttyUSB0 -p 4000:5000 --name octopi urrizzz/octopi
Fantastic, isn’t it? Note that we had to change the host port (4000) in order to avoid port conflict with MotionEye
At the end of image download, extraction and run you will be able to connect your OctoPi setup wizard page by browsing the address http://<<YOUR_RPI_IP_ADDRESS>>:4000.
You can configure or simply press next (except for user and password creation) to reach the home page (all the settings can be edited later):
Click connect to contact your printer.
To connect also your webcam to OctoPi:
- go to the settings (icon on top-right with the wrench),
- select “Webcam and Timelapse”
- insert your streaming IP address ( http://<<YOUR_RPI_IP_ADDRESS>>:8081/ ) and press the test button
My configuration appears as in the following picture:
Press “Save” and you should find your video streaming in Control Section:
Enjoy!
G’Day,
Great write up! Very easy to follow.
I am having one problem when it comes to the Octoprint container starting when the printer is off. Obviously it cant find /dev/ttyUSB0, and this causes the container not to start. The problem is, i want to use Octoprint and a relay switched using the GPIOs to turn the printer on with a plug-in for Octoprint. Is there a work around for this? Is there a way to tell the container to start even though the device is not present?
Thanks