[How To] KlipperScreen on Android Smart Phones

Morning everybody.

I have a Xiaomi, but not rooter.

I have run KlipperScreen directly on Pi Zero 2 and XSDL server on my phone.
I have juste changed

ExecStart=/usr/bin/xinit /home/pi/.KlipperScreen-env/bin/python /home/pi/KlipperScreen/screen.py

by

ExecStart=/home/pi/KlipperScreen/screen.py

in

/etc/systemd/system/KlipperScreen.service
and enable

systemctl --user set-environment DISPLAY=phone_ip:0

and

chmod +x /home/pi/KlipperScreen/screen.py

and change

#!/usr/bin/python

by

#!/usr/bin/pyhton3

And this run like a charm.

Sorry for my english, Iā€™m so frenchā€¦ :stuck_out_tongue:

I hope can help anybody without rooted phoneā€¦

I think it run on Pi zero W/H.

2 Likes

Salut Skippythekangoo,

jā€™ai un xiaomi redmi7 et rien a faire pour lā€™install de klipperscreen, peut- tu mā€™aider?

JP

Salut.
Oui je peux tā€™aider, mais dis moi oĆ¹ tu en esā€¦
As-tu installĆ© Klipper et Klipperscreen sur ton Piā€¦
XSDL sur ton tĆ©lĆ©phoneā€¦???

Out of courtesy to the other readers: Please keep the conversation in English. Many thanks

1 Like

YEs, of course.

Sorry for this incovenientsā€¦

2 Likes

Salut, oui, klipper+moonraker+mainsail+ klipperscreen sont installƩ sur le PI. XSDL ne veut rien sur mon tƩl:( :frowning:

Hi, yes, klipper + moonraker + mainsail + klipperscreen are installed on the PI. XSDL doesnā€™t want anything on my phone :frowning:

Are you setting correctly a DISPLAY variableā€¦???

I do not know. I connect my smartphone to the pc, in USB (debog mode activated, file transfer). I run XSDL, I set the resolution, scale ā€¦ etc ā€¦ and then it asks me (blue screen) to export DISPLAY and PULSE_SERVER ā€¦ then there is a 3rd line pil with xfwm4 & firefox ??? port 6000 I havenā€™t touched anything ā€¦ So I run these commands but nothing happens ?! These commands must be launched from putty connected to the raspberryPI, right?

I have same problem. Do you solved this ?? :slight_smile:

#!/bin/bash
# forward local display :100 to remote display :0
adb forward tcp:6100 tcp:6000

If you run everything on pi and only use phone as display than it is necessary to connect your phone via USB cable and enable USB debugging on your android device. The magic is that you forward the display using above command.

You need to start Klipperscreen on the forwarded display which is done in my script with

DISPLAY=:100 /home/pi/.KlipperScreen-env/bin/python screen.py

I hope this helps a little bit.

Actually i made update by the KIAUH program. Fluidd said i was up to date but there was an update and everything works now :slight_smile:

I have not solved my problem. I donā€™t understand what ā€œjhsā€ says because I am not an expert on linux; I donā€™t have a global vision of the process. I will need a summary of the whole process to fully understand ā€¦
Thank you if someone wants to explain the whole process, it will be useful to many people I think :grinning: :+1: :+1:

Hi all, I will try to write a more detailed how to this weekend if you are planning to use the following setup:

Running klipper and Klipperscreen on raspberry pi and use USB connected android phone only to display Klipperscreen.

If youā€™re interested in this setup please let me know and I will try to write a more detailed how to.

2 Likes

Absolutely, my setup is klipper + klipperscrenn + mainsail and an android phone in USB debug mode. I am very interested, because I have been looking for this solution for a long time and I am stuck. This solution seems really interesting to me and adapted to the situation ā€¦
Thank you very much for this sharing which will make people happy

JP

Iā€™m interested in the manual you can do, thanks

I working on a setup and found that older versions of Android (Kindle 6th gen in my case) will not run latest xserver. Version 1.11.40 appears to be working (at least it starts).

Pretty sure I did everything right here but klipperscreen isnā€™t being displayed on the phone. I created the shell script copy/pasted jhsā€™ code in, named it launch_klipperscreen and placed it in /home/pi/KlipperScreen.

I have USB debugging enabled on the phone and XSDL is installed and the phone is connected to the pi over USB.

I modified the KlipperScreen.service file in /etc/systemd/system/ with the path to the shell script but Iā€™m just seeing the blue welcome screen giving me the instructions on how to forward the display.

Where did I go wrong? :sweat_smile:

Hello, I started to write down a new howto but it is not finished yet. I recommend to test your setup as follows.

  1. ssh into your pi with putty or linux command line ssh
  2. plug your android phone with usb debugging enabled into your raspberry
  3. if you have not yet installed it install adb using
pi@prusabear:~ $ sudo apt-get install adb
Reading package lists... Done
Building dependency tree       
Reading state information... Done
adb is already the newest version (1:8.1.0+r23-5).
  1. use command
pi@prusabear:~ $ adb devices
List of devices attached
0b4dca7f	device

to see if your phone is recognized by adb

  1. install x11-apps
pi@prusabear:~ $ sudo apt-get install x11-apps
Reading package lists... Done
Building dependency tree       
Reading state information... Done
x11-apps is already the newest version (7.7+7).
  1. enable port forwarding
pi@prusabear:~ $ adb forward tcp:6100 tcp:6000
* daemon not running; starting now at tcp:5037
* daemon started successfully
  1. start x111 program xeyes
    Turn off wifi on your phone. Start xsdl on your phone. If you see a mouse cursor disable in xsdl config:
    Device Configuration ā†’ In Mouse emulation ā†’ Mouse Emulation Mode ā†’ ā€œDesktop no emulationā€
pi@prusabear:~ $ DISPLAY=:100 xeyes 
Warning: locale not supported by C library, locale unchanged

Your telephone should look like this:

Mind the xeyes in the upper left corner.

If this does not work try if you have to confirm usb debugging on your phone.

You can use ctrl-c to stop xeyes.
If thiis runs you can copy following to

  1. define service
    /etc/systemd/system/KlipperScreen.service
[Unit]
Description=KlipperScreen
After=moonraker.service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=pi
WorkingDirectory=/home/pi/KlipperScreen
ExecStart=/home/pi/KlipperScreen/lauch_klipperscreen.sh

[Install]
WantedBy=multi-user.target
  1. define start script
    copy the folowing to

/home/pi/KlipperScreen/lauch_klipperscreen.sh

#!/bin/bash
adb forward tcp:6100 tcp:6000

adb shell dumpsys nfc | grep 'mScreenState=' | grep OFF_LOCKED > /dev/null 2>&1
if [ $? -lt 1 ]
then
    echo "Screen is OFF and Locked. Turning screen on..."
    adb shell input keyevent 26
fi

adb shell dumpsys nfc | grep 'mScreenState=' | grep ON_LOCKED> /dev/null 2>&1
if [ $? -lt 1 ]
then
    echo "Screen is Locked. Unlocking..."
    adb shell input keyevent 82
fi

adb shell am start-activity x.org.server/.MainActivity

ret=1
timeout=0
echo -n "Waiting for x-server to be ready "
while [ $ret -gt 0 ] && [ $timeout -lt 60 ]
do
    xset -display :100 -q > /dev/null 2>&1
    ret=$?
    timeout=$( expr $timeout + 1 )
    echo -n "." 
    sleep 1
done
echo ""
if [ $timeout -lt 60 ]
then
    DISPLAY=:100 /home/pi/.KlipperScreen-env/bin/python screen.py
    exit 0
else
    exit 1
fi

make the script executable

pi@prusabear:~ $ chmod a+x /home/pi/KlipperScreen/lauch_klipperscreen.sh

  1. enable service with
pi@prusabear:~ $ systemctl enable KlipperScreen.service 
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ===
Authentication is required to manage system service or unit files.
Authenticating as: ,,, (pi)
Password: 
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon ===
Authentication is required to reload the systemd state.
Authenticating as: ,,, (pi)
Password: 
==== AUTHENTICATION COMPLETE ===

and start systemd service

pi@prusabear:~ $ systemctl start KlipperScreen.service 
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'KlipperScreen.service'.
Authenticating as: ,,, (pi)
Password: 
==== AUTHENTICATION COMPLETE ===
2 Likes

Hi Jan,

Thanks very much for making the effort to expand upon your initial post with these more detailed instructions.

Iā€™m still not having any joy after following though. :cry:

The phone is definitely connected with the pi as ā€œadb devicesā€ reports itā€™s device number and when I start xeyes I get the comical eyes that follow your finger around the screen. Iā€™ve defined the service and start script as per steps 8 and 9 and used the command to make the script executable, then enabled the service and started sytemd. All authenticated as they should but no sign of klipperscreen on the phoneā€™s display. The problem seems to be with displaying klipperscreen. If I run the command from your shell script in a terminal via ssh:

DISPLAY=:100 /home/pi/.KlipperScreen-env/bin/python screen.py

I get the following error:

/home/pi/.KlipperScreen-env/bin/python: canā€™t open file ā€˜screen.pyā€™: [Errno 2] No such file or directory

The location of the file screen.py for me seems to be /home/pi/KlipperScreen/screen.py

Do I need to change the shell script for the way my Klipperscreen install seems to be arranged in the filesystem or something? :thinking:

Running DISPLAY=:100 /home/pi/KlipperScreen screen.py just tells me that ā€œ/home/pi/KlipperScreen is a directoryā€

How should I proceed from here?

Cheers,

Steve

pi@prusabear:~/KlipperScreen $ cat /etc/systemd/system/KlipperScreen.service 
[Unit]
Description=KlipperScreen
After=moonraker.service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=pi
WorkingDirectory=/home/pi/KlipperScreen
ExecStart=/home/pi/KlipperScreen/lauch_klipperscreen.sh

[Install]
WantedBy=multi-user.target

Looking at systemd this line is essential:

WorkingDirectory=/home/pi/KlipperScreen

if you want to try to start Klipperscreen from commandline please change into that directory and run

pi@prusabear:~ $ cd /home/pi/KlipperScreen
pi@prusabear:~/KlipperScreen $ ls -l
total 108
-rw-r--r-- 1 pi pi 33888 Sep  9 16:23 LICENSE
-rw-r--r-- 1 pi pi   864 Dec 19 21:35 README.md
drwxr-xr-x 3 pi pi  4096 Dec 19 21:35 docs
drwxr-xr-x 5 pi pi  4096 Dec 19 21:35 ks_includes
-rwxr-xr-x 1 pi pi   836 Sep 13 19:27 lauch_klipperscreen.sh
-rw-r--r-- 1 pi pi   284 Oct 21 21:01 mkdocs.yml
drwxr-xr-x 3 pi pi  4096 Dec 19 21:35 panels
-rw-r--r-- 1 pi pi 37617 Dec 19 21:35 screen.py
drwxr-xr-x 2 pi pi  4096 Dec 19 21:35 scripts
drwxr-xr-x 7 pi pi  4096 Dec 19 21:35 styles

once you are inside this directory try to launch klipperscreen with

pi@prusabear:~/KlipperScreen $ DISPLAY=:100 /home/pi/.KlipperScreen-env/bin/python screen.py

(screen.py:2275): Gtk-WARNING **: 19:02:23.239: Locale not supported by C library.
	Using the fallback 'C' locale.
INFO:root:KlipperScreen version: v0.2.0-10-g0b9d545
INFO:root:Passed config file: /home/pi/KlipperScreen.conf
2022-01-16 19:02:27,804 [screen.py:main()] - KlipperScreen version: v0.2.0-10-g0b9d545
INFO:root:Found configuration file at: /home/pi/KlipperScreen.conf
2022-01-16 19:02:27,807 [config.py:get_config_file_location()] - Passed config file: /home/pi/KlipperScreen.conf
DEBUG:root:Config path location: /home/pi/KlipperScreen.conf
2022-01-16 19:02:27,808 [config.py:get_config_file_location()] - Found configuration file at: /home/pi/KlipperScreen.conf
2022-01-16 19:02:27,809 [config.py:__init__()] - Config path location: /home/pi/KlipperScreen.conf
INFO:root: ===== Config File =====
[main]
moonraker_host = 127.0.0.1
moonraker_port = 7125
show_cursor = False
...
more output here

and see if this starts klipperscreen on your phone. Once you can start it from here we can try to solve starting it as a service.

Good luck and do not hesitate to ask if you need more help.