Looking for something?

In Starndard
Raspberry Pi Touchscreen Octoprint Controller

As everyone knows I love my Raspberry Pis. I'll put them in whatever I can fit them in. I am in the process of finishing my 3D printer rack and I wanted to get my new Anet A8 printer on wifi so that I didn't need to shuffle the difficult to remove SD card from it when I wanted to print something.

Along comes Octoprint... Now, there are plenty of "how to install octoprint on a Raspberry Pi" documents out there, but nothing quite as pedantic as I would have liked. So I set off to do it my way.

This project uses a fantastic Adafruit designed 3D printed case: https://learn.adafruit.com/3-dot-5-pitft-octoprint-rig/3d-printed-case to wrap a Raspberry Pi 3 + Adafruit PiTFT Plus 3.5" touch screen.

Getting Started

This is a very simple project. Here are the things you will need:

  • Raspberry Pi 3
  • PiTFT Plus 3.5"
  • SD Card
  • 3D Printer

Most of this is already covered in Adafruit's fantastic guide: https://learn.adafruit.com/3-dot-5-pitft-octoprint-rig/overview.

My approach has been updated and is a bit more bare bones... You will download the latest Raspbian Jessie Lite from https://www.raspberrypi.org/downloads/raspbian/, and burn it to your SD card.

Do the usual Raspberry Pi setup process... Change the default password, enable SSH, get on to your wifi, etc. Once raspbian is running and secured on your Pi3 you can proceed with this guide.


Install required packages

As root (sudo -i), please do the following:

apt-get install python-pip python-dev python-setuptools python-virtualenv git libyaml-dev build-essential chromium-browser raspi-gpio xcompmgr dbus-x11 libgl1-mesa-dri xserver-xorg xserver-xorg-video-fbdev xserver-xorg-input-evdev xinit xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable xinput ttf-mscorefonts-installer xinput-calibrator  

Base setup

Create the octoprint user. This user will be used to run both the backend and the frontend of octoprint:

adduser --disabled-password --disabled-login --gecos "" octoprint  

usermod -a -G cdrom,audio,video,render,plugdev,users,dialout,dip,input,tty octoprint  

Fix the xorg config permissions so that a non-root user can run X correctly:

chmod ug+s /usr/lib/xorg/Xorg  

Now we will update a few X config files to optimize for this use case:

edit: /etc/X11/Xwrapper.config

allowed_users=anybody  
needs_root_rights=no  

edit: /etc/kbd/config

BLANK_TIME=0  
BLANK_DPMS=off  
POWERDOWN_TIME=0  

edit: /etc/X11/xinit/xinitrc

xset s noblank  
xset s off  
xset -dpms  

Install Octoprint

Switch from root to the octoprint user su octoprint:

cd /home/octoprint

git clone https://github.com/foosel/OctoPrint.git

cd OctoPrint

virtualenv venv  
./venv/bin/pip install pip --upgrade
./venv/bin/pip install setuptools==7.0
./venv/bin/python setup.py install

mkdir ~/.octoprint  

This should leave you with a happy install of octoprint located at /home/octoprint/Octoprint.

Setup systemd services

edit: /etc/systemd/system/octoprint-backend.service

[Unit]
    Description=OctoPrint service

[Service]
    User=octoprint
    ExecStart=/home/octoprint/OctoPrint/venv/bin/octoprint

[Install]
    WantedBy=multi-user.target

edit: /etc/systemd/system/octoprint-frontend.service

[Unit]
Description = Octoprint Frontend  
After = systemd-user-sessions.service network.target sound.target

[Service]
User = octoprint  
Group = octoprint  
Type = simple  
ExecStart = /usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/bin/chromium-browser --start-maximized --window-size=480,320 --window-position=0,0 --disable-restore-background-contents --noerordialogs --disable-session-crashed-bubble --disable-infobars --disable-pinch --overscroll-history-navigation=0 --incognito --kiosk http://127.0.0.1:5000 -- :0 -s 0 dpms -nocursor -nolisten tcp vt7  
Restart = on-abort  
RestartSec = 5

[Install]
WantedBy = multi-user.target  

Enable both services to start at boot:

systemctl enable octoprint-backend.service  
systemctl enable octoprint-frontend.service  

Octoprint setup

Log in to your octoprint instance using a browser on your computer. It should be something like http://YOUR_PI_IP:5000. You can find your Pi's ip address by running ifconfig as root. You will be presented with the "Setup Wizard". Follow the instructions to complete the setup process.

To keep things simple I recommend DISABLING access control. I would not recommend this if you are putting your Raspberry Pi on a public network.


TouchUI plugin

To best fit on the 480x320 screen, you should enable the TouchUI plugin. On your computer connect to the octoprint instance running on the Raspberry Pi (instructions above). "Under the settings section, goto the plugin manager and search for "Touch UI", then click the install button." --Adafruit


Enable the PiTFT

Adafruit has a guide: https://learn.adafruit.com/adafruit-pitft-3-dot-5-touch-screen-for-raspberry-pi/easy-install, but it doesnt seem to play nice with the latest Raspbian.

Run the following as root (sudo -i):

echo "deb http://apt.adafruit.com/raspbian/ jessie main" >> /etc/apt/sources.list

wget -O - -q https://apt.adafruit.com/apt.adafruit.com.gpg.key | apt-key add -

apt-get update  
apt-get install -y adafruit-pitft-helper  

Then run adafruit-pitft-helper:

adafruit-pitft-helper -t 35r  

Check /boot/config.txt to ensure the defined orientation will work for you. The line to review should look like:

dtoverlay=pitft35r,rotate=90,speed=42000000,fps=20  

The rotate= variable tells the driver to rotate the screen 0, 90, 180, or 270 degrees.

  • 0 is portrait, with the bottom near the USB jacks.
  • 90 is landscape, with the bottom of the screen near the headphone jack.
  • 180 is portrait, with the top near the USB jacks.
  • 270 is landscape, with the top of the screen near the headphone jack.

Now reboot (reboot).

After the reboot (in theory) you will see the octoprint web interface on your PiTFT. But you will need to calibrate the touchscreen before you can interact with it.


Touch calibration

As root (sudo -i) run the following:

DISPLAY=:0.0 xinput_calibrator  

Follow the onscreen calibration process:

Once complete you should have a snippet of config to paste relevant to your touch screen.

edit: /etc/X11/xorg.conf.d/99-calibration.conf and paste the output you got from xinput_calibrator.

Example output:

Section "InputClass"  
    Identifier  "calibration"
    MatchProduct    "stmpe-ts"
    Option  "Calibration"   "3932 82 141 3877"
    Option  "SwapAxes"  "1"
    Option "InvertX" "1"
    Option "InvertY" "1"
EndSection  

If your config does not contain InvertX or InvertY (mine didn't), you can add it manually to fix input inversion problems you may have.

Reboot (reboot), and enjoy your octoprint rig!.


My Octoprint controller

I mounted my octoprint controller to the shelving that I have my 3D printers on using double sided adhesive. Overall I am very impressed with how simple octoprint is and how well it works with my Anet A8 3D printer.

0 Comments 21 July 2017
Daniel Chote

Daniel Chote

Daniel Chote, the Code Monkey, Cat Herder, Maker, H4x0r, uav pilot, sim racer, bullshit artist and dad. Made in Hastings, New Zealand... Now living in the USA!

Related Post

Comments powered by Disqus