Raspberry Pi 3 B+ with KeDei 3.5 inch 480×320 TFT LCD display

Up until now my DIY indoor climate logger was based on a Teensy 3.1 microcontroller combined with a 16×2 character monochrome LCD display for basic visualisation of the measurements. After experimenting with Home Assistant, I thought it was time for a more appealing visualisation. I migrated my sensors to a Raspberry Pi, and intended to show the measurements on a 3.5″ graphic LCD that would be mounted on top of the Pi.

I specifically wanted a SPI display connected through the GPIO header in stead of a HDMI display that has an awkwardly cable running to the HDMI connector. I knew SPI display support used to be kinda shoddy, but after seeing developments such as fbcp I had some more confidence. I bought a cheap, good looking 3.5″ LCD on Aliexpress, complete with case (pictured) and stylus, assuming Raspbian support for SPI displays would be more or less crystallised by now.

Well, it isn’t.

Turns out the LCD I bought was a KeDei display. These displays are notorious for their bad or often completely missing software support and for changing the type of display controller or even the pinout between iterations of the display, thereby leading to totally different ways of getting the display to work depending on the revision. They do provide their own kernel to make the displays work with Raspberry Pi, but this breaks compatibility with a lot of stuff that otherwise runs just fine on regular Raspbian.

The version I received was v6.3 with date 2018/4/9.

It took me some time to piece together the information required to get this display to work, so I wrote this guide for those who currently find themselves in the same position as me. The hardware used in this guide is a Raspberry Pi 3B+ running the official Raspbian distro with kernel 4.14.34-v7+. It’s possible this guide also works for other hardware and distros, or even other versions of the display, but your mileage may vary.

Login to your Pi through SSH or start a command line shell from the GUI. It can never hurt to first update your Pi, so everything is the latest version.
sudo apt-get update
sudo apt-get upgrade

When this is done, browse to your home location and download the driver from the manufacturer.
cd Downloads
wget http://en.kedei.net/raspberry/v6_1/LCD_show_v6_1_3.tar.gz

When the tarball has been downloaded, lets unpack it and browse to the newly created directory.
tar -xvzf LCD_show_v6_1_3.tar.gz
cd LCD_show_v6_1_3

Now run the install script, and wait a very long time.
sudo ./LCD35_v

The Pi will reboot in the process, but everything will take several minutes. Go grab a coffee and let everything run its course. Your LCD should display the Raspberry Pi berries once the Pi has rebooted. Log back in to the Pi.

To make the LCD work, we need to activate the OpenGL support on the Pi. Run the Raspi config tool with
sudo raspi-config

Go to option 7 “Advanced Options”

Go to A6 GL Driver, and select G2 GL (Fake KMS). Select OK and then Finish. Exit raspi-config and reboot again.

Now for the finishing touches, we need to edit config.txt. This is sort of the BIOS of the Pi, where it stores configuration information that is read during boot. Navigate to the boot directory and open the file.
cd /boot
sudo nano config.txt

Search for, uncomment and/or change the following lines (in my config file it was lines 28 & 29, and 48)

(Note that rather strangely you need to disable SPI to make the SPI display work.)

Finally, add or change the following lines at the end of the file.

Press ctrl-x and save under the same name.

Now reboot the Pi one last time
sudo reboot

Rejoice! After the Pi has booted the Pi’s desktop should now be displayed on the LCD. The touchscreen should be working too now.

Note that you can’t use the SPI display and HDMI output at the same time, unless you use some kind of framebuffer copy. If you want to use the HDMI output again, start a shell into your Pi and run the LCD_hdmi script
cd Downloads
cd LCD_show_v6_1_3
sudo ./LCD_hdmi

After a reboot, the video output should now be on HDMI again.