legacy:accessory:display:3.5inch_lcd_shield:3.5inch_lcd_shield

3.5 inch LCD Shield

Fully assembled a 3.5-inch display with 480×320 pixels TFT LCD and a resistive touch overlay. Just plug it on top of your Odroid.

You will need an official Ubuntu image to configure it.

You can simply download the Kernel updates (via dist-upgrade) and configure your Odroid for this display shield.

  • You need an HDMI connection or a Serial/SSH console connection to follow the instruction below.
  • You need the Shifter-Shield board to use this display on Odroid-XU4.
  • ODROID-C1+
    • Ubuntu Mate 16.04.5 + kernel 3.10.107-192
    • Ubuntu Mate 18.04.1 + kernel 3.10.107-11
  • ODROID-C2
    • Ubuntu Mate 16.04.4 + kernel 3.14.79-117
    • Ubuntu Mate 18.04 + kernel 3.16.57-23
  • ODROID-XU4 with Shifter Shield
    • Ubuntu Mate 16.04.4 + kernel 4.14.47-132
    • Ubuntu Mate 18.04 + kernel 4.14.52-145
  • ODROID-N2
    • Ubuntu Mate 18.0.4 + kernel 4.14.213-67
  • Issues I've found out
    • Automatically start in X-Window mode is not working on ODROID-XU4 16.04 / 18.04, ODROID-N2 18.04.
    • Automatically start in console mode is not working.
    • Touch screen calibration seems not working well on Ubuntu 18.04.

First of all, check out this operation confirmed table with the following conditions.

ODROID-C1+ ODROID-C2 ODROID-XU4 ODROID-N2 ODROID-C4
Ubuntu Mate 16.04 3.10.107-192 3.14.79-117 4.14.47-132
Ubuntu Mate 18.04 3.10.107-11 3.16.57-23 4.14.52-145
Ubuntu Mate 20.04 4.9.230 4.9.230

Updating kernel is always highly recommended.

And install fbset package to modify the device tree blob.

target
$ sudo apt update && sudo apt full-upgrade
$ sudo apt install fbset

To enable sx865x touch driver on your Odroid, you need to edit a dtb using the following commands.

ODROID-C1+/C2

target
sudo modprobe aml_i2c
sudo modprobe pwm-meson
sudo modprobe pwm-ctrl
sudo modprobe fbtft_device name=flexpfb rotate=270
sudo modprobe flexfb chip=ili9488
sudo modprobe sx865x

This warning message can be ignored since we need only one PWM output.

"pwm-ctrl pwm-ctrl: cannot export to PWM-1 : modprobe pwm-meson npwm=2"

And you have to activate LCD shield by turning PWM on.

target
echo 500000 | sudo tee /sys/devices/platform/pwm-ctrl/freq0
echo 1 | sudo tee /sys/devices/platform/pwm-ctrl/enable0
echo 1023 | sudo tee /sys/devices/platform/pwm-ctrl/duty0

If you're using Ubuntu 18.04 on C2, enter the following commands instead.

target
echo 500000 | sudo tee /sys/devices/pwm-ctrl/freq0
echo 1 | sudo tee /sys/devices/pwm-ctrl/enable0
echo 1023 | sudo tee /sys/devices/pwm-ctrl/duty0

ODROID-XU3/XU4

  • Kernel Version == 3.10.y
target
sudo apt install device-tree-compiler
sudo cp /media/boot/exynos5422-odroidxu3.dtb /media/boot/exynos5422-odroidxu3.dtb.old
sudo fdtput -t s /media/boot/exynos5422-odroidxu3.dtb /hsi2c@12CB0000/sx865x@49 status "okay"
sudo reboot
  • Kernel Version >= 4.9.y
    • ODROID-XU4 Board dtb file : exynos5422-odroidxu4.dtb
    • ODROID-XU3 Board dtb file : exynos5422-odroidxu3.dtb

Following are the example for ODROID XU4 users. If you try with ODROID XU3, edit entered dtb file name.

target
sudo apt install device-tree-compiler
sudo cp /media/boot/exynos5422-odroidxu4.dtb /media/boot/exynos5422-odroidxu4.dtb.old
sudo fdtput -t s /media/boot/exynos5422-odroidxu4.dtb /soc/i2c@12cb0000/sx865x@49 status "okay"
sudo reboot


After editing the device tree for your platform, then load the modules.

  • If the device /dev/fb* is not created and the following messages appears from dmesg,
[  621.952761] flexfb_probe_common : ioremap gpiox register success!
[  621.957496] flexfb flexpfb.0: fbtft_request_gpios: gpio_request_one('wr'=190) failed with -16
  • Enter the following command to unload SPI modules and try again.
target
sudo modprobe -r spidev
target
sudo modprobe fbtft_device name=flexpfb rotate=270
sudo modprobe flexfb chip=ili9488

ODROID-N2/C4

  • In Odroid-N2/C4, you should use DTBO rather than using FDT tools.

Open /media/boot/config.ini file and go to the bottom of the file. Then find the below part.

Edit overlay_profile part to hktft35. Refer to the following contents.

target
; Device Tree Overlay
overlay_resize=16384
overlay_profile=hktft35
overlays="spi0 i2c0 i2c1 uart0"
 
[overlay_custom]
overlays="i2c0 i2c1"
 
[overlay_hktft32]
overlays="hktft32"
 
[overlay_hktft35]
overlays="hktft35 sx865x-i2c1"

ODROID-C1+/C2/N2

You will have a new frame buffer /dev/fbX.

Find a node named flexfb.

  • The frame buffer 0, 1 (/dev/fb{0,1}) always exists. Proceed with /dev/fb2 or other named flexfb.
  • THE BEST WAY is that find out which frame buffer device has a name flexfb by yourself.
  • This guide assumes that you're working on ODROID C2. In this case, the frame buffer device for an LCD shield is /dev/fb2.
target
$ ls /dev/fb*
# results like..
/dev/fb2
 
$ cat /sys/class/graphics/fb2/name
# results..
flexfb

ODROID-XU3/XU4

You will have a new frame buffer /dev/fbX.

Find a node named flexfb.

  • It's different between two conditions.
    • When the HDMI connected and you're working with a monitor.
    • When any monitor isn't connected and you're working via SSH or serial connection.
    • If the monitor connected, the frame buffer device 0(/dev/fb0) would be assigned at the connected monitor. So the other frame buffer could be for a LCD shield, like /dev/fb1.
  • THE BEST WAY is that find out which frame buffer device has a name flexfb by yourself.
  • This guide assumes that you're working on ODROID C2. In this case, the frame buffer device for a LCD shield is /dev/fb2.
target
$ ls /dev/fb*
# results like..
/dev/fb2
 
$ cat /sys/class/graphics/fb2/name
# results..
flexfb

ODROID-C4

You will have a new frame buffer /dev/fbX.

Find a node named fb_hktft35.

  • THE BEST WAY is that find out which frame buffer device has a name fb_hktft35 by yourself.
target
$ ls /dev/fb*
# results like..
/dev/fb4
 
$ cat /sys/class/graphics/fb4/name
# results..
fb_hktft35

Map the console to the frame buffer device assigned at the LCD shield.
This guide assumes that you're working on ODROID C2, so the proper frame buffer device would be /dev/fb2.

target
# Usage: con2fbmap {CONSOLE} [FRAME_BUFFER]
# If the frame buffer isn't specified, it shows the currently mapped frame buffer.
sudo con2fbmap 1
# results
console 1 is mapped to framebuffer 0
 
sudo con2fbmap 1 2
sudo con2fbmap 1
# results
console 1 is mapped to framebuffer 2

Change the foreground screen by using the command chvt. That means you will move to the selected console.
[ The command chvt N makes /dev/ttyN the foreground.
Since the frame buffer device for the console #1 is assigned at the LCD shield, terminal screen shows up at the LCD shield after entering the command.
If you face a problem with enter chvt command, try again via SSH or serial(UART).

target
# Usage: chvt {CONSOLE_NUM}
sudo chvt 1

Edit tty1 service.

target
sudo systemctl edit getty@tty1

Add the following codes and save by pressing Ctrl + K and X when if JOE editor shown.

[Service]
ExecStart=
ExecStart=-/sbin/agetty -a odroid --noclear %I $TERM

Check if it saved.

target
sudo systemctl cat getty@tty1 | grep Exec
# results
ExecStart=-/sbin/agetty --noclear %I $TERM
ExecStart=
ExecStart=-/sbin/agetty -a odroid --noclear %I $TERM

Restart tty1 service.

target
sudo systemctl restart getty@tty1

This guide assumes that you're working on ODROID C2, so the proper frame buffer device would be /dev/fb2.

This step is for set up the target frame buffer device to show the X-window (X11) screen. Since the frame buffer device /dev/fb2 is assigned at the LCD shield, X-window screen will show up at the LCD shield.

ODROID-C1+/XU3/XU4

target
sudo mv /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
 
# Enter this command too if you're using XU4. This file might be there by default but to make sure it doesn't exist.
sudo rm /etc/X11/xorg.conf.d/exynos.conf

Add following lines into the /etc/X11/xorg.conf file.

target
sudo vi /etc/X11/xorg.conf
Section "Device"
    Identifier    "C fbdev"
    Driver        "fbdev"
    Option        "fbdev" "/dev/fb2"
EndSection

ODROID-C2/N2/C4 with Ubuntu 18.04 or higher

Create /usr/share/X11/xorg.conf.d/99-odroid.conf file and put the below contents into that file.

target
sudo vi /usr/share/X11/xorg.conf.d/99-odroid.conf
Section "Device"
    Identifier    "c fbdev"
    Driver        "fbdev"
    Option        "fbdev" "/dev/fb2"
    Option        "TransformationMatrix" "-1 0 1 0 -1 1 0 0 1"
EndSection
  • In C2, edit /usr/share/X11/xorg.conf.d/99-odroidc2.conf file instead.
    • Change /dev/fb0 to /dev/fb2.
target
cd /usr/share/X11/xorg.conf.d
sudo cp 99-odroidc2.conf 99-odroidc2.conf.bak
sudo vi 99-odroidc2.conf
  • If you rotate the screen 180°, the touchscreen coordination must be rotated too.
  • If you have a problem with running X-window on your LCD module, please try again after following “Create a new config file” (Edit /etc/X11/xorg.conf) instruction.

Map the X-window console to the frame buffer device for the LCD shield.

target
# Usage: con2fbmap {CONSOLE} [FRAME_BUFFER]
# If the frame buffer isn't specified, it shows the currently mapped frame buffer.
sudo con2fbmap 7 2
sudo con2fbmap 7
# results
console 7 is mapped to framebuffer 2

Change the foreground screen by using the command chvt. That means you will move to the selected console.
The command chvt N makes /dev/ttyN the foreground.
Since the frame buffer device for the console #7 is assigned at the LCD shield, make the console that LCD shield displays to #7.
If the display manager ready, graphical desktop screen will appear.
If you face a problem with enter chvt command, try again via SSH or serial(UART).

target
# Usage: chvt {CONSOLE_NUM}
sudo chvt 7

Restart display manager to show up the screen on the LCD shield.

target
sudo service lightdm restart

Then you can see graphical desktop on your LCD shield.

Edit /etc/lightdm/lightdm.conf file.

target
sudo vi /etc/lightdm/lightdm.conf

Add the following lines.

[SeatDefaults]
autologin-user=odroid
autologin-user-timeout=0

Save and restart lightdm.

target
sudo service lightdm restart
  • ODROID-C1+/C2 only.
  • ODROID-XU4 does not use PWM control.

Set PWM frequency and enable it.

target
echo 500000 | sudo tee /sys/devices/platform/pwm-ctrl/freq0
echo 1 | sudo tee /sys/devices/platform/pwm-ctrl/enable0

You can enter 0 ~ 1023(total 1024 step) to the duty0 file to adjust backlight brightness of the LCD shield.

target
echo 1023 | sudo tee /sys/devices/platform/pwm-ctrl/duty0

If you're using Ubuntu 18.04 on C2, be careful for the changed pwm-ctrl path.

target
echo 500000 | sudo tee /sys/devices/pwm-ctrl/freq0
echo 1 | sudo tee /sys/devices/pwm-ctrl/enable0
echo 1023 | sudo tee /sys/devices/pwm-ctrl/duty0

Install the calibrator.

target
sudo apt install xinput-calibrator xserver-xorg-input-evdev
  • If your display mode is portrait(rotate 0 or 180), run the following command.
target
sudo DISPLAY=:0 xinput set-prop 'SX865X Touchscreen' 'Evdev Axes Swap' 0

Enter the command below and make sure you will enter via installed 3.5 inch LCD shield.

target
sudo DISPLAY=:0 xinput_calibrator

Follow the directions on your screen.
Then you will see like,

You should add a property “Driver” to the result yourself.
Then it will be like,

Section "InputClass"
	Identifier	"calibration"
	MatchProduct	"SX865X Touchscreen"
	Driver  "evdev"
	Option	"Calibration"	"89 3848 254 3854"
	Option	"SwapAxes"	"0"
EndSection

Copy that result to /etc/X11/xorg.conf.d/99-calibration.conf.

target
sudo mkdir /etc/X11/xorg.conf.d/
sudo vi /etc/X11/xorg.conf.d/99-calibration.conf
 
# Ubuntu 18.04 on C2
sudo vi /usr/share/X11/xorg.conf.d/99-calibration.conf

Restart display manager.

target
sudo service lightdm restart

There are four tact switches on LCD shield. The switches will change a ADC value when you press these buttons.
Each sysfs nodes are:

  • C2 - /sys/class/saradc/ch0
  • C1 - /sys/class/saradc/saradc_ch0
  • XU4 - /sys/devices/12d10000.adc/iio\:device0/in_voltage3_raw
  • N2 - /sys/devices/platform/ff809000.saradc/iio:device0/in_voltage2_raw
  • C4 - /sys/devices/platform/ff809000.saradc/iio:device0/in_voltage0_raw
SBCswitch #ADC value
C2/C1 SW1 5 ±10
SW2 515 ±10
SW3 680 ±10
SW4 770 ±10
XU4/N2/C4 SW1 0 ±100
SW2 2030 ±100
SW3 2695 ±100
SW4 3014 ±100
target
sudo apt install git
git clone https://github.com/hardkernel/wiringPi
cd wiringPi
sudo ./build

4 Keys on the shield will be mapped to SPACE, UP, DOWN, ENTER input event.

ODROID-C2/C1

tftlcd35_key.c

target
wget https://dn.odroid.com/source_peripherals/lcd35/tftlcd35_key.c

Compile & Run.

target
gcc -o tftlcd35_key tftlcd35_key.c -lwiringPi -lwiringPiDev -lm -lpthread -lrt -lcrypt
sudo ./tftlcd35_key &

ODROID-XU4/N2/C4

tftlcd35_key_xu4.c

target
wget https://dn.odroid.com/source_peripherals/lcd35/tftlcd35_key_xu4.c

Compile & Run.

target
gcc -o tftlcd35_key_xu4 tftlcd35_key_xu4.c -lwiringPi -lwiringPiDev -lm -lpthread -lrt -lcrypt
sudo ./tftlcd35_key_xu4 &

Auto Run

Applications

  • legacy/accessory/display/3.5inch_lcd_shield/3.5inch_lcd_shield.txt
  • Last modified: 2021/04/28 12:10
  • by luke.go