Warning
Klipperscreen hangs if "Screen Power Off Time" is enabled, set it to "Never" in settings.
- This guide is mostly based on willngton guide on how to connect MKS TS35 screen in Raspberry Pi to run Klipperscreen, which is also based on other guides (see his git for details).
- Due to some Linux kernel and Xorg changes, the touchscreen calibration would not work anymore, thus the necessity of this guide.
This was validated with Raspberry Pi Os Lite 32-bit, release September 6th 2022, kernel 5.15, Debian 11 (bullseye).Updated and tested with release from September 22th 2022.Updated and tested with release from Febuary 21st 2023.- Updated and tested with release from May 3rd 2023. Kernel 6.1 drivers were update and now works as intended.
- If something goes wrong, break, or don't work, unload the screen device tree from step 5 and redo everything.
Write RaspiOS Lite image in your microSD card, connect either via SSH or Serial, and follow instructions at KIAUH, and within the script, proceed installing Klipper, Moonraker, your favorite web interface (Mainsail or Fluidd), and KlipperScreen.
sudo nano /etc/X11/Xwrapper.config
- Add these lines in the bottom of the file:
needs_root_rights=yes
sudo apt install gldriver-test -y
- Install binaries:
sudo apt-get install cmake -y
cd ~
git clone https://github.com/tasanakorn/rpi-fbcp
cd rpi-fbcp/
mkdir build
cd build
cmake ..
make
sudo install fbcp /usr/local/bin/fbcp
- Create service:
sudo nano /etc/systemd/system/fbcp.service
- Add the contents below to the file.
[Unit]
Description=fbcp
After=KlipperScreen.service
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/local/bin/fbcp
[Install]
WantedBy=multi-user.target
CTRL+X
to exit, and press Y
to confirm changes to the file.
- Enable the fbcp service.
sudo systemctl enable fbcp.service
sudo nano /boot/config.txt
-
Change
dtoverlay=vc4-kms-v3d
todtoverlay=vc4-fkms-v3d
(around line 62). -
Add these lines in the bottom of the file:
dtoverlay=disable-bt
# MKS TS35
dtparam=spi=on
hdmi_cvt=480 320 60 1
hdmi_group=2
hdmi_mode=87
display_rotate=0
dtoverlay=tinylcd35,touch
CTRL+X
to exit, and press Y
to confirm changes to the file.
Reboot host and reconnect. After booting, KlipperScreen must load after console screen.
Download, compile and install xlibinput_calibrator. Follow the instructions in it's GitHub page to resolve dependencies and compile, or:
sudo apt install libxfixes-dev libxi-dev libxrandr-dev x11proto-input-dev x11proto-randr-dev -y
cd ~
git clone https://github.com/kreijack/xlibinput_calibrator
cd xlibinput_calibrator/src/
make
g++ -MT main.o -MMD -MP -MF .d/main.Td -Wall -pedantic -std=c++17 -c -o main.o main.cc
sudo install xlibinput_calibrator /usr/local/bin/xlibinput_calibrator
List your displays with:
DISPLAY=:0 xlibinput_calibrator --list-devices
And you should see your SPI screen ID and name:
pi@klipper:~ $ DISPLAY=:0 xlibinput_calibrator --list-devices
6: ADS7846 Touchscreen
Coordinate Transformation Matrix: 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Enabled: 1
Device Node: /dev/input/event0
Device Product ID: 0, 0
libinput Calibration Matrix: 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
libinput Calibration Matrix Default: 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
libinput Send Events Mode Enabled: 0, 0
libinput Send Events Mode Enabled Default: 0, 0
libinput Send Events Modes Available: 1, 0
You can either run the calibration routine with your display name or ID:
sudo DISPLAY=:0 xlibinput_calibrator --output-file-x11-config=/usr/share/X11/xorg.conf.d/99-calibration.conf --device-name="ADS7846 Touchscreen" --verbose
or
sudo DISPLAY=:0 xlibinput_calibrator --output-file-x11-config=/usr/share/X11/xorg.conf.d/99-calibration.conf --device-id=6 --verbose
Follow the instructions on the screen. Use a stylus type pen for more precision. The calibration matrix will be automatically calculated and saved to /etc/X11/xorg.conf.d/99-calibration.conf
Reboot host and type DISPLAY=:0 xinput list-props "ADS7846 Touchscreen" | grep "libinput Calibration Matrix"
, your current calibration should persist between shutdowns and reboots, and touch is spot on.
MKS TS35 screen has an active buzzer that can be used by Klipper macros to play tones. Differently from the LCD itself which is fed with 5v, the buzzer logic level is 3.3v (fed by Raspberry Pi GPIO logic level), requiring one more wire to be connected.
Flash RPi Microcontroller service as described in Klipper documentation so Klipper can access Raspberry Pi GPIO.
Add these lines in you printer.cfg
:
[mcu rpi]
serial: /tmp/klipper_host_mcu
[output_pin BEEPER_Pin]
pin: rpi:gpio17 # for Raspberry Pi
pwm: True
Add this macro in your macros.cfg
or whatever the structure you have in your machine settings. Source.
[gcode_macro M300]
gcode:
{% set S = params.S | default(1000) | int %} ; S sets the tone frequency
{% set P = params.P | default(100) | int %} ; P sets the tone duration
{% set L = 0.5 %} ; L varies the PWM on time, close to 0 or 1 the tone gets a bit quieter. 0.5 is a symmetric waveform
{% if S <= 0 %} ; dont divide through zero
{% set F = 1 %}
{% set L = 0 %}
{% elif S >= 10000 %} ;max frequency set to 10kHz
{% set F = 0 %}
{% else %}
{% set F = 1/S %} ;convert frequency to seconds
{% endif %}
SET_PIN PIN=BEEPER_Pin VALUE={L} CYCLE_TIME={F} ;Play tone
G4 P{P} ;tone duration
SET_PIN PIN=BEEPER_Pin VALUE=0
[gcode_macro BUZZER_TEST]
gcode:
M300 S1000 P100
M300 S1000 P100
M300 S1000 P100
Save and restart to apply changes, test with BUZZER_TEST
.