I got this screen on Amazon here: https://www.amazon.com/Quimat-320x480-Resolution-Display-Raspberry/dp/B06X191RX7/
These are the changes I had to make on a fresh Kali 2019.2a
install on a raspberry pi 3:
It's an SPI screen which means it is rather slow to update. But it's good enough.
Add the dtoverlay
entry to /boot/config.txt
:
Note: This sets the SPI update speed. If 24MHz is too fast, try 16MHz (16000000
). You can try 32MHz as well but might get artifacts...
Other note: This also sets the resistive range of the touchscreen overlay. Without the xohm=150
bit, your touchscreen values will be entirely wrong when you try to calibrate things
# Set the top of the screen to be on the HDMI port side:
dtoverlay=piscreen,speed=24000000,rotate=90,xohm=150
# Set the top of the screen to be on the GPIO header side:
dtoverlay=piscreen,speed=24000000,rotate=90,xohm=150
The above is all you should need if you're just looking to draw directly to the screen via it's framebuffer. For example, if you've got X running on another monitor and want a simple touchscreen interface on the screen. Keep in mind: This is an SPI screen. That means the FB is not accelerated and won't work for OpenGL stuff.
If you want the terminal or X running on the screen, you'll need to use the rest of this document:
Add terminal framebuffer preference order to end of boot command (you can use cat /proc/fb
to see the available framebuffers):
Note: This means it'll try the "second" framebuffer if one exists, and fall back to the first if not. Since the order is basically: 0=hdmi, 1=tft these values will default to the tft even if the hdmi cable is plugged in.
fbcon=map:10
With the above config, as long as you don't have an HDMI monitor attached, X11 should be able to load on this screen. However, if you do have another monitor hooked up, you'll have to use something like the following config to tell X11 about it.
Create an X11 config inside /usr/share/X11/xorg.conf.d/
named something like 99-fb-for-tft.conf
that switches over to using the new framebuffer:
Section "Device"
Identifier "PiScreen"
Option "fbdev" "/dev/fb1"
EndSection
# Show xinput things:
DISPLAY=:0.0 xinput
# Show props for an xinput thing:
DISPLAY=:0.0 xinput --list-props "6"
# Reset current settings:
DISPLAY=:0.0 xinput set-prop "ADS7846 Touchscreen" 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
DISPLAY=:0.0 xrandr # Get current dimentions
DISPLAY=:0.0 ./xtcal -geometry 320x480
That will output something like:
fullscreen not supported
Calibrate by issuing the command below, substituting <device name> with the name found using `xinput list`.
xinput set-prop <device name> 'Coordinate Transformation Matrix' 0.004668 -1.065470 1.023457 -1.135843 0.070809 0.986081 0 0 1
Note: You'll have to hide the menu panel/"start bar" with a height of 0 pixels
for the duration of the calibration to get accurate results.
So then this should set the calibration:
DISPLAY=:0.0 xinput set-prop "ADS7846 Touchscreen" 'Coordinate Transformation Matrix' 0.004668 -1.065470 1.023457 -1.135843 0.070809 0.986081 0 0 1
And this in /usr/share/X11/xorg.conf.d/99-calibration.conf
should lock in those values after a reboot:
Section "InputClass"
Identifier "Touchscreen Calibration"
MatchProduct "ADS7846 Touchscreen"
Driver "libinput"
Option "TransformationMatrix" "0.004891 -1.081049 1.038604 -1.090886 -0.000032 1.053982 0 0 1"
EndSection
Calibrate the touchscreen using the xinput_calibrator
(from apt install xinput_calibrator
):
Note: You need to run this from inside an X11 session!
# Generate a snippet to put into an X11 config file inside /usr/share/X11/xorg.conf.d/
xinput_calibrator
# OR generate a snippet that will configure the calibration settings using xinput (you will need to run the command every boot!)
xinput_calibrator --output-type xinput
X11 callibration config will look like:
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "2973 213 206 3934"
Option "SwapAxes" "0"
EndSection
And if you asked for them, the xinput
commands will look like:
xinput set-int-prop "ADS7846 Touchscreen" "Evdev Axis Calibration" 32 3972 213 206 3934
xinput set-int-prop "ADS7846 Touchscreen" "Evdev Axes Swap" 8 0
This was really helpful getting this set up: http://ozzmaker.com/piscreen-driver-install-instructions-2/
That's it!