Since a long time i wanted to set a tft touch screen on my raspberry and run Kodi on it.
I bought a cheep waveshare 3,2 '' (exactly this one), it's a resitive screen which come s with a small pencil and ... that all (actually it should come with a cd but ..not).
Installing Archlinux
I have a rapberry pi b+ and i follow the classique way to install Archlinux on the sdcard:Find the disk using gparted
Umount the sdcard
umount /dev/sdX
Start fdisk to partition the SD card:
fdisk /dev/sdX
At the fdisk prompt, delete old partitions and create a new one:
- Type o. This will clear out any partitions on the drive.
- Type p to list partitions. There should be no partitions left.
- Type n, then p for primary, 1 for the first partition on the drive, press ENTER to accept the default first sector, then type +100M for the last sector.
- Type t, then c to set the first partition to type W95 FAT32 (LBA).
- Type n, then p for primary, 2 for the second partition on the drive, and then press ENTER twice to accept the default first and last sector.
- Write the partition table and exit by typing w.
Create and mount the FAT filesystem:
mkfs.vfat /dev/sdX1 mkdir boot mount /dev/sdX1 boot
Create and mount the ext4 filesystem:
mkfs.ext4 /dev/sdX2
mkdir root
mount /dev/sdX2 root
Download and extract the root filesystem (as root, not via sudo):
wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C root sync
Move boot files to the first partition:
mv root/boot/* boot
Unmount the two partitions:
umount boot root
Updating
The next step is to connect to the raspberry to the network, login into then update packages to the latest releaseConnect the raspberry to the network using the ethernet plug
Send power to the raspberry (5v usb)
From my machine i check the DHCP server on my ADSL router to know what is my Pi's IP
Then connect using SSH:
ssh alarm@192.168.XX.XX
alarm@192.168.xx.xx's password: (a password will be asked juste enter alarm)
Welcome to Arch Linux ARM
Website: http://archlinuxarm.org
Forum: http://archlinuxarm.org/forum
IRC: #archlinux-arm on irc.Freenode.net
[alarm@alarmpi ~]$
We are in !!
Now we need to be root to do the update
su
Password: (the root password is ... root (no lol pleaz), note the prompt should change)
pacman -Syu
:: Synchronizing package databases...
core is up to date
extra is up to date
community is up to date
alarm is up to date
aur is up to date
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...
Packages (6) linux-raspberrypi-4.1.18-5 raspberrypi-firmware-20160304-1 raspberrypi-firmware-bootloader-20160304-1
raspberrypi-firmware-bootloader-x-20160304-1 raspberrypi-firmware-examples-20160304-1
raspberrypi-firmware-tools-20160304-1
Total Download Size: 58.00 MiB
Total Installed Size: 75.70 MiB
Net Upgrade Size: 0.00 MiB
:: Proceed with installation? [Y/n]
choose Y
...
it's up to date now
Installing the screen
we need to shutdown the raspberryas root:
halt -p
wait few second then remove the power plug of the pi and install the screen on it
Once done, put the power plug back into the Pi.
The TFT screen should light up.
Install some useful tools
As i like to be confortable when i work on unix like computer i always install a bunch of package (such a true editor ...)
as root:
pacman -S vim tmux git wget curl
Install the video driver
the framebuffer driver is available in the driver tree, so there is no need to download something or/and build.ssh to the raspberry and su root (as above)
edit the file /boot/config.txt and uncomment the following line
device_tree_param=spi=on
save it then reboot the raspberry, this is important to reboot or at the next step, the module we try to load will not be found
reboot
Once the pi has restart reconnect to it as root
now try the following line, the Pi tft screen should turn black:
modprobe fbtft_device custom name=fb_ili9340 speed=48000000 gpios=dc:22,reset:27 bgr=1 rotate=270
Edit etc/modules-load.d/raspberrypi.conf and add the following lines
spi-bcm2835
ifb_ili9340
fbtft_device
create a /etc/modprobe.d/fbftf.conf file with the following
options fbtft_device custom name=fb_ili9340 speed=48000000 gpios=dc:22,reset:27 bgr=1 rotate=270
Install x packages
we need to install all the packages needed to go graphic.Let's start with base X packages:
pacman -Syu xorg-server xorg-xinit xorg-server-utils
we continue with the driver in our case we use the frame buffer
pacman -S xf86-video-fb xf86-video-fbdev
then the input device
pacman -S xf86-input-evdev xf86-input-libinput
And finally i added some classic X Client
pacman -S xorg-twm xorg-xclock xterm
Configure X to work with fb
Modify or create file /etc/X11/xorg.conf.d/99-fbdev.conf as folow:Section "Device" Identifier "myfb" Driver "fbdev" Option "fbdev" "/dev/fb1" EndSection
Install and configure touch
Once again the driver is provide in the device tree.First we add ads7845 to /etc/modules-load.d/raspberrypi.conf which should now look like this:
bcm2708-rng
snd-bcm2835
spi-bcm2835
fb_ili9340
fbtft_device
ads7845
the digitaliser needs some parameters which must be provide using the overlay mechanism.
It can be perform by modifying /boot/config.txt by adding :
dtoverlay=ads7846,speed=500000,penirq=17,swapxy=1
After a reboot here, you can check with a small test :
evtest
when you move the sylet on the screen it shout output stuff
to enable the configuration into X we have to add the folowing
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "3900 240 3900 240"
EndSection
into /etc/X11/xorg.conf.d/99-calibration.conf
One more thing, if the mouse moves upset, add a /etc/X11/xorg.conf/99-inversion.conf as follow:
Section "InputClass"
Identifier "axis inversion"
MatchProduct "ADS7846 Touchscreen"
# swap x/y axes on the device. i.e. rotate by 90 degrees
Option "SwapAxes" "off"
# Invert the respective axis.
Option "InvertX" "on"
Option "InvertY" "off"
EndSection
with different combinaison of swapAxes, InvertX , InvertY
usefull links:
https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README
https://archlinuxarm.org/forum/viewtopic.php?f=64&t=9230
https://github.com/watterott/RPi-Display/blob/master/docu/FBTFT-Install.md
https://github.com/notro/rpi-firmware/issues/6
http://www.circuitbasics.com/raspberry-pi-touchscreen-calibration-screen-rotation/
https://archlinuxarm.org/forum/viewtopic.php?f=31&t=9208
https://github.com/phortx/Raspberry-Pi-Setup-Guide
https://github.com/notro/fbtft_tools/wiki/ads7846_device
https://fedoraproject.org/wiki/Input_device_configuration
https://github.com/notro/fbtft/issues/215
https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=81150