Installing OctoPrint on OrangePi Zero (part 1)

I have started modifying my own 3D printer and one of the mods is a WEB interface. To have the WEB interface, the printer is connected to its own WEB server which has Octoprint running on a small OrangePi Zero Linux computer.

Octoprint is an open-source project which is intended to allow 3D printing without a host (regular PC) connected to the printer. Usually, the host is replaced with a Raspberry Pi, connected to LAN or WLAN and running an Octoprint instance. In this case, I have replaced the Raspberry Pi with an OrangePi Zero.

This is a two part post. The second part can be found here.

Table of contents

OrangePi Zero

OrangePi Zero Top View

I have chosen OctoPrint on an OrangePi instead of a Raspberry Pi (3B version), because I had issues with a power supplies – it is quite hard to get a good PSU suitable for RPi and OrangePi Zero seemed to work a lot better even with cheapest USB Chargers. Also, the OrangePi Zero is smaller and has just enough I/O for this use case: one USB (as only one is needed to connect to the printer), one LAN connector, and some I/O pins for external buttons (will be used to power-off/reboot the system).

Furthermore, the Orange Pi Zero has a quad core CPU running at 1GHz and 512MB of RAM which is plenty, if basic WEB interface is going to be used and might not be enough if a WEB Cam streaming (or other RAM and CPU intensive features) will be used for viewing the printing process in real time. During printing, CPU usually sits at around 5% and RAM – at 25-30% of usage. Only during gcode load to the OrangePi CPU sits at 100% and it might take several seconds to load the file. It seems that high CPU usage is caused by printing time calculations which are done during the first file load to the Octoprint.

Finally, OrangePi Zero might be one of the cheapest (Aliexpress) board which can be used to run Octoprint.

First steps with the OrangePi Zero

Firstly, we need an OS running on the Orange Pi. Armbian is a good Linux choice on such small computers.

Installation is quite simple. First of all, you need to download Armbian from official page (I have chosen ‘bionic’ distro which is Ubuntu based)(note that the link is for OrangePi Zero and not Zero+). Then extract the file you have downloaded. To write extracted ISO file to an SD card, you can use BalenaEtcher (this is what I use to flash an SD card). After writing the file to the SD card, insert it into Orange Pi Zero, connect LAN cable and power it up by connect to an USB cable. It might tike some minutes on first boot, because Armbian expands its partition to make all space on SD card usable.

Next thing to do, is to SSH to the Orange Pi. For that you need to know the IP address of the device. The easiest method should be just to check it through your router admin panel. The second way of finding out the IP is to directly connect USB-UART adapter to the Orange Pi header near the LAN connector.

After figuring out the IP address, you can connect to the device with SSH using either a terminal on Linux or a terminal emulator such as Putty on Windows machine.

On the first connection, you will be asked to create a new ‘regular’ user. So, I have created a user named octopi which will be used in the further setup.

Finally, a good practice before doing anything else is updating the system:

sudo apt-get update
sudo apt-get upgrade

Installing Octoprint

A good guide how to install Octoprint on a Linux machine is here. As there is everything that you might need, I will show only steps that I have done, leaving behind everything that I haven’t needed (such as a webcam setup). In the end you will have OctoPrint running on the OrangePi.

Firstly, if you haven’t done it yet, reboot OrangePi Zero and log in as a regular user created earlier (octopi in my case). Then, a python virtual environment needs to be installed:

sudo apt install python-pip python-dev python-setuptools python-virtualenv git libyaml-dev build-essential

After that OctoPrint folder is created:

mkdir OctoPrint && cd OctoPrint

Then I tried running virtualenv venv command, but got message that virtualenv is not installed, so I installed it:

sudo apt install virtualenv

After that, virtual environment can be created:

virtualenv venv 

And finally, it can be activated:

source venv/bin/activate

Next, we need to install octoprint into virtual environment:

pip install pip --upgrade
pip install octoprint

Also, octopi (the user) needs to have access to the serial ports:

sudo usermod -a -G tty octopi
sudo usermod -a -G dialout octopi

Finally, to start Octoprint type:

~/OctoPrint/venv/bin/octoprint serve

Now if you type in a web browser <octoprintIP>:5000 (where <octoprintIP> is Orange Pi IP address) you should connect to its web interface. On the first connection it will show setup wizard:

Octoprint First Setup Wizzard Image

Here you can set up some features, like user credentials (for connecting to the web interface), anonymous usage tracking, web camera and other. Most of it I have left unchanged. Also, keep in mind, that setting up a web camera at this point is not a good idea, because it needs more configuration trough terminal (see the tutorial).

After finishing setup wizzard octoprint server can be closed (from already opened terminal) with typing in Shift+C.

Automatic OrangePi Zero and OctoPrint’s startup

It is good idea to start the octoprint automatically during system startup, as mentioned in the tutorial:

wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init && sudo mv octoprint.init /etc/init.d/octoprint
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default && sudo mv octoprint.default /etc/default/octoprint
sudo chmod +x /etc/init.d/octoprint

Then open /etc/default/octoprint (note: at this point you should know how to use vi editor to modify files, if not – google the basic commands or use another editor):

vi /etc/default/octoprint

And change a line to look like this:

DAEMON=/home/octopi/OctoPrint/venv/bin/octoprint

Note, that in the path above, ‘octopi’ is your created user during Armbian setup. Also, # should be deleted from the start of the line. Save and close.

After that add script to autostart:

sudo update-rc.d octoprint defaults

Now, the service should autostart on system startup, also it can be started, stopped or restarted by typing:

sudo service octoprint start 
sudo service octoprint stop 
sudo service octoprint restart

Adding OrangePi’s restart/shutdown commands in OctoPrint’s menu

To have ability to easily restart/shutdown system or restart OctoPrint service from the WEB interface, these commands need to be added in Settings-> Commands tab:

Restart OctoPrint: sudo service octoprint restart

Restart system: sudo shutdown -r now

Shutdown system: sudo shutdown -h now

After typing those commands in and closing the settings tab you will notice that after clicking either one of those buttons in the menu nothing will happen, because it will ask (if a user is connected) through terminal to type in user’s (in this case octopi’s) password. That is not convenient. To change this behavior and allow directly do those actions trough WEB UI, octopi user needs to have password-less access to the /sbin/shutdown program.

So, let’s create and edit the file (use sudo if needed):

vi /etc/sudoers.d/octoprint-shutdown

And add the line to it:

octopi ALL=NOPASSWD: /sbin/shutdown

Save and close. After this, the OctoPrint’s WEB UI should allow you to shut down and restart the OrangePi Zero system directly from within the UI, but it won’t allow you to directly restart the service. To change that, edit again the same file:

vi /etc/sudoers.d/octoprint-shutdown

And add a second line:

octopi ALL=NOPASSWD: /usr/sbin/service octoprint *

Save and close.

Now you should be able to restart the service within the WEB UI.

Accessing WEB UI through 80 port

For access of 80th port haproxy was used.

First of all, it needs to be installed:

sudo apt-get install haproxy

Then edit the haproxy configuration file (you might want to make a backup of this file before editing it):

vi /etc/haproxy/haproxy.cfg

And replace all lines in the file with these:

 global
        maxconn 4096
        user haproxy
        group haproxy
        daemon
        log 127.0.0.1 local0 debug

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        option http-server-close
        option forwardfor
        maxconn 2000
        timeout connect 5s
        timeout client  15min
        timeout server  15min

frontend public
        bind :::80 v4v6
        use_backend webcam if { path_beg /webcam/ }
        default_backend octoprint

backend octoprint
        reqrep ^([^\ :]*)\ /(.*)     \1\ /\2
        option forwardfor
        server octoprint1 127.0.0.1:5000

backend webcam
        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
        server webcam1  127.0.0.1:8080

Then edit the file:

sudo vi /etc/default/haproxy

And add (or change) a line:

ENABLED = 1

Also, you might want to add a line to the ~/.octoprint/config.yaml file:

server:
    host: 127.0.0.1

After that haproxy server can be started/stopped/restarted with:

sudo service haproxy {start|stop|restart|status}

At this point, you should be able to access Octoprint through OrangePi’s IP address instead of a port 5000.

Summary

So, this was a first step of adding the OrangePi Zero with OctoPrint to a 3D printer. This allows the 3D printer to be controlled trough a WEB interface with any device connected to the same LAN.

Next step is going to be two additional buttons for the OrangePi, so it could be restarted/powered off with physical push buttons. Also, the OrangePi needs a small case, having a bare board lying on the table is not a convenient solution.

Here is the second part of this post – power off and reboot buttons, 3D printed case.

Octoprint setup on a Raspbian

Subscribe to a newsletter!

Was this page helpful?