I orderer a 3.5″ SPI touchscreen with a Raspberry Pi 2 and a case, thinking it would be easy to set up, as it seemed to be like the one here. Unfortunately that was not the case.
To install precompiled kernel version 4.1.x for Raspberry Pi 2:
- Install latest Raspbian
- Download this archive here (19.6 MB)
- Take the micro-sd from RPi2 and mount it on your Linux computer
- You should see two partitions mounted, one fat32 (BOOT), one ext4
- Open the archive, and copy all files under folder fat32 to the BOOT partition
- Copy all files under folder ext4 to ext4 partition
- Add a line to your /boot/config.txt: “
- Add a line to /etc/modules: “
- Now booting should result having the screen white
- You can change the terminal to the screen by using command “
con2fbmap 1 1” and back with “
con2fbmap 1 0“
- You can change the X to the screen by modifying /usr/share/X11/xorg.conf/99-fbturbo.conf: change “
fb0” to “
With some googling I found out it was made by KeDei LCD and exactly this screen. Identifying strings on the screens were “Madei in KeDei of china”, “3.5 linch SPI TFTLCD”, “480*320 16bit/18bit” and “vision 1.0 2015/6/11”. I hope the guys who made this screen can write code better than english… Seems like it requires custom drivers by KeDei. Drivers could be downloaded from Baidu and they include the diff to compile your custom kernel. I haven’t compiled kernels before, so lets see if I could manage without doing that.
I downloaded drivers and installed them in a fresh installation of Raspbian. They worked, somewhat at least. I could see console in the screen and also LXDE started in it. However it seemed to override HDMI output completely, as it was /dev/fb0 and no other framebuffers were present. Touchscreen appeared in /dev/input/event0, but I couldn’t get it respond. Probably the touch sensor is defective, as the glass on the screen also had a crack. I did get a free resend however, so I’ll see wether it was defective hardware.
The drivers replaced current kernel with a custom 3.18.x version with drivers in it, so you can’t update kernel if using that method. Perhaps I should try to compile more recent kernel with drivers.
I installed Ubuntu on my Macbook Pro on an external hard drive (which is a whole another story, thanks to EFI), so I could follow instructions on Raspberry Pi pages. Compiling on RPi is quite slow (tried that overnight), so cross compiling is the way to go. Following the instructions worked pretty well, however I cloned tools to my home directory and added /home/heikki/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin to my path. After that everything worked as expected. After cloning and changing branch to rpi-4.1.y I patched semi-manually from the supplied diff from KeDei, however I have uploaded my updated diff to make it easier for you. There’s instructions on patching too, but long story short it’s “
cat <patch-file> | patch -p1” in the base directory of the clone. The version I used was branch rpi-4.1.y, commit 785cea66a709eddb9858799192a7b7da566b44b0.
Update: I accidentally updated kernel with apt-get, so I tried to compile the kernel to the latest. However I noticed the patch missed a whole file, which belongs to drivers/video/fbdev/ and is attached here: ili9341.c. I still couldn’t get it right, so I just installed the previously compiled kernel.
I configured the kernel pretty much default, but the ili9341 drivers enabled. My config can be found here. Finally I got the kernel compiling. The config and built kernel are only for Raspberry Pi 2! For Raspberry Pi 1 you need to reconfigure the kernel and build it your self.
Installing custom kernel was simple following the kernel building instructions. I had an updated Raspbian on the sd, and copying the files over seemed to suffice. I have the copied files in an archive here (19.6 MB). You can hopefully figure out where to copy those.
I used a custom name for the kernel file (kernel-screen.img), so you should also add a line to your /boot/config.txt: “
kernel=kernel-screen.img“. Now booting will use our custom kernel! However the touchscreen remains empty. That’s because the module for the screen still needs to be loaded, you can try it with “
sudo modprobe ili9341“. If and when it works you can add a line to /etc/modules: “
ili9341” and the module is automatically loaded on boot.
You should now have two framebuffer devices, /dev/fb0 and /dev/fb1. I’m not quite sure how the fbtft library interferes with the patch, as it seems to be activated too, but it works so no problem. (Actually I first activated module fb_ili9341, so you can try that too, if it contributed to my success). You can change to console to fb1 by command “
con2fbmap 1 1” and back with “
con2fbmap 1 0“, or on boot by editing /boot/cmdline.txt: add “
fbcon=map:1” to the line somewhere. You can also change the font with “
fbcon=font:ProFont6x11“. More things like this here.
The framerate on this screen is really slow, something like 0.5 secs to refresh the screen, so no video playback on this screen. For simple GUIs probably quite sufficient. Haven’t tried whether backlight can be controlled, probably not, so always on.
I’ll test the touchscreen with custom kernel later when I get the new unit. The touchscreen driver seems to be added (/dev/input/event2 for me with Logitech keyboard/mouse connected), so it might work.
Update: Touchscreen working with patched kernel out of the box.
By the way, I had to make the A/V connector hole a tad larger to fit. One side of scissors through the hole (from inside) and carving did the trick.