OctoScreen on Adafruit PiTFT 320×240
Finally got around to moving my Ender 5 Plus, and it’s load power supply, out of my office. So more then ever I want OctoPrint up and running for remote monitoring of my setup. I had a Raspberry Pi 4 unused and found an old Adafruit PiTFT 320×240 touch screen in the scrap bin. Getting OctoPrint up and running is easier then ever with the pre-built image for Raspberry Pi. The old touch screen was another story so here is my final notes on how to get it up and running. I assume that my audience already have OctoPrint up and running and just want the screen to work.
So first we need to upgrade everything to the latest version. Connect to the OctoPi via SSH, the default usernam/password is pi/raspberry.
sudo apt-get update && sudo apt-get upgrade
Then make sure that OctoPrint is up to date from the OctoPrint web UI. Then we can install the screen with Adafruits automation script. More information here: https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install-2
cd ~ sudo apt-get install -y git python3-pip sudo pip3 install --upgrade adafruit-python-shell click==7.0 git clone https://github.com/adafruit/Raspberry-Pi-Installer-Scripts.git cd Raspberry-Pi-Installer-Scripts sudo python3 adafruit-pitft.py
Go for the option with HDMI mirroring not console! When setup is completed correctly you should have the login screen showing after reboot.
OctoScreen installation and setup
Installation of OctoScreen is pretty straight forward. It’s uses an X11 application instead of a web browser like TouchUI and similar. More information on the OctoScreen install: https://github.com/Z-Bolt/OctoScreen
sudo apt-get install libgtk-3-0 xserver-xorg xinit x11-xserver-utils wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb sudo dpkg -i octoscreen_2.7.2_armhf.deb
After the installation completes and a reboot one arm of the OctoPrint octopus becomes visible on the screen. We need to change the resolution to match the screen. So edit the OctoScreen config file and change the OCTOSCREEN_RESOLUTION value to 320×240.
sudo nano /etc/octoscreen/config
The screen still doesn’t look as expected and need some additional tweaking. First change the resolution settings for the screen in the boot config.
sudo nano /boot/config.txt
Un-comment and set the following values:
At the bottom change the HDMI settings to:
hdmi_cvt=660 390 60 1 0 0
After a reboot the screen should look fine but the touch screen will not be aligned and unusable. Both the X and Y axis seems to be inverted but not in a fully logical way. This also has to do with the change of the resolution. Install xtcal to calibrate the touchscreen for X11 use.
cd ~ sudo apt-get install libxaw7-dev libxxf86vm-dev libxaw7-dev libxft-dev git clone https://github.com/KurtJacobson/xtcal cd xtcal make
Now we run the calibration with the same values we used for the framebuffer settings to get an accurate calibration.
pi@octopi:~ $ DISPLAY=:0.0 xtcal/xtcal -geometry 660x390 fullscreen not supported Calibrate by issuing the command below, substituting with the name found using xinput list. xinput set-prop 'Coordinate Transformation Matrix' -0.003810 -1.123983 1.038378 1.124421 0.006780 -0.076729 0 0 1
The output we get at the bottom is the actual calibration information needed to get it all to work. In this case -0.003810 -1.123983 1.038378 1.124421 0.006780 -0.076729 0 0 1. Then we build an transformation matrix to offset and calibrate the touch screen. Edit sudo nano /usr/share/X11/xorg.conf.d/20-calibration.conf and add the information below. You can see where the calibration output is added into this. Then reboot the Pi again and it should all work just fine. You can read more about the calibration here: https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/resistive-touchscreen-manual-install-calibrate
Section "InputClass" Identifier "STMPE Touchscreen Calibration" MatchProduct "stmpe" MatchDevicePath "/dev/input/event*" Driver "libinput" Option "TransformationMatrix" "-0.003810 -1.123983 1.038378 1.124421 0.006780 -0.076729 0 0 1" EndSection
This will work just fine and you can use most of the menus. Some of them will not fit properly on the screen and you will not be able to get back to the main screen. If that happens and you don’t want to reboot the Pi you can issue sudo service octoscreen restart over ssh.
So this is somewhat useful but you can see that this isn’t designed for such a small screen. Bur if you ended up on this post you’re probably in the same situation I was and just want it to work!