4 4
adrb

OrangePi Zero, mainline kernel, SPI LCD + touchscreen

Recommended Posts

It's simple guide, presenting how to setup LCD (ili9431) with integrated touchscreen (tsc2046) on mainline kernel (4.11). It may be not fully "armbian way", since I'm pretty new in armbian ;)

 

In case that somebody is interested, I recently bought couple those displays from here

 

Few basic informations:

 

1. OrangePiZero has two SPI buses. First one is usually occupied by build in memory. So we can only use bus1

2. tsc2046 chip is fully compatible with ads7846, and we have drivers for it since years now

3. Maximum clock frequency for ads7846 is 3.25Mhz, but don't expect that it will work with that.  Reasonable value is something beetween 0.5-2Mhz. Lower frequency, if you observing misbehavior.

4. Probably most important information :) ili9431 and tsc2046 poorly cooperate on shared bus. I don't know exactly why, because I don't have access to logic analyzer,  but it's proven fact (at least on my equipment). You have to lower bus frequency to 2MHz (highest common value), and even then it work very unstable.  My educated guess is that, missed interrupt from touchscreen (when SPI is busy with sending data to LCD) makes it stop making further attempts to communicate. Or maybe there is some incompatibility on electrical level, I really don't know.

5. My electrical setup (keep in mind it's 3.3V)

 

OPIZ - LCD (ili9431)

PA13 - CS

PA14 - SCK

PA16 - SDO

PA15 - SDI

PA03 - DC

PA00 - RESET

PA06 - controls transistor which is driving current to LCD pin. You may also connect LCD pin to VCC, and leave PA06 floating.

 

And here is part for touchscreen. We are going to use emulated spi bus with bitbang. At this point bitbang isn't compiled in armbian kernel - we will take care of this later.

 

OPIZ - LCD (tsc2046)

PA10 - T_CS

PA18 - T_IRQ

PA19 - T_CLK

PA11 - T_DIN

PA12 - T_DO

 

Configuration for the first spi bus:

Spoiler

/* author: Adrian Brzezinski: adrb at wp.pl, adrian.brzezinski at adrb.pl */

/dts-v1/;
/plugin/;
 
/ {
    compatible = "allwinner,sun8i-h3";
 
    fragment@0 {
        target-path = "/aliases";
        __overlay__ {
            spi1 = "/soc/spi@01c69000";
        };
    };
 
    fragment@1 {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
 
            spidev {
                compatible = "spidev";
                reg = <0>;
                spi-max-frequency = <50000000>;
            };
        };
    };
};

 

Configuration for touchscreen driver:

Spoiler

/* author: Adrian Brzezinski: adrb at wp.pl, adrian.brzezinski at adrb.pl */

/dts-v1/;
/plugin/;
 
/ {
    compatible = "allwinner,sun8i-h3";
 
    fragment@0 {
        target-path = "/aliases";
        __overlay__ {
            spi2 = "/spi2";
        };
    };
 
    fragment@1 {
        target-path = "/";
        __overlay__ {
            spi2 {
                compatible = "spi-gpio";
                #address-cells = <0x1>;
                ranges;
 
                gpio-sck = <&pio 0 19 0>; // PA19
                gpio-mosi = <&pio 0 11 0>; // PA11
                gpio-miso = <&pio 0 12 0>; // PA12
                cs-gpios = <&pio 0 10 1>; // PA10
                num-chipselects = <1>;
                status = "okay";
 
		ads7846@0 {
                    compatible = "ti,ads7846";
                    reg = <0>; /* Chip Select 0 */
                    status = "okay";
                    spi-max-frequency = <500000>;
                    interrupt-parent = <&pio>;
                    interrupts = <0 18 2>; /* PA18, IRQ_TYPE_EDGE_FALLING */
                    pendown-gpio = <&pio 0 18 2>; /* PA18, IRQ_TYPE_EDGE_FALLING */
                    vcc-supply = <&reg_vcc3v3>;
 
                    ti,pressure-min = /bits/ 16 <0>;
                    ti,pressure-max = /bits/ 16 <0xfff>;
                    ti,x-plate-ohms = /bits/ 16 <40>;
 
                    wakeup-source;
 
                    /* swap axis if LCD has been rotated by 90 or 270 degrees  */
                    //ti,swap-xy = <1>;
                    //*
                    ti,x-min = /bits/ 16 <0>;
                    ti,y-min = /bits/ 16 <0>;
                    ti,x-max = /bits/ 16 <0xffff>;
                    ti,y-max = /bits/ 16 <0xffff>;
                    //*/
                };
 
            };
        };
    };
 
};

 

Compile and add those DTS with "armbian-add-overlay" command.

Next, download armbian sources and cross compile kernel - without any modifications, just to make sure that everything is compiling without issues:

# mkdir armbian
# cd armbian
# git clone https://github.com/armbian/build.git
# git clone https://github.com/igorpecovnik/lib
# cp lib/compile.sh .
# ./compile.sh BRANCH=dev BOARD=orangepizero KERNEL_ONLY=yes PROGRESS_DISPLAY=plain RELEASE=jessie

Enable required modules :

echo "CONFIG_SPI_BITBANG=m" >> lib/config/kernel/linux-sun8i-dev.config
echo "CONFIG_SPI_GPIO=m" >> lib/config/kernel/linux-sun8i-dev.config

... and recompile kernel, then install deb packages from output directory. You may also copy drivers, it may be faster for testing but it's not advised for "serious" deployment.

Loading modules at startup:

# cat > /etc/modprobe.d/fb_ili9341.conf << _EOF_
 
options fbtft_device custom name=fb_ili9341 gpios=dc:3,reset:0,led:6 speed=16000000 busnum=1
 
_EOF_
# echo fbtft_device >> /etc/modules
# echo ads7846 >> /etc/modules

If you connected LED pin to VCC, then you should omit that ",led:6" in configuration above. 

 

I hope that this will help anyone who want to connect LCD display and build simple touchscreen based Orange Pi Zero terminal ;)


 

Spoiler

 

ps:

I'ts late and i'm tired so im preety sure that there is a bunch of grammatical errors :/

 

 

 

 

 

Share this post


Link to post
Share on other sites
On 06/07/2017 at 1:35 AM, adrb said:

Compile and add those DTS with "armbian-add-overlay" command.

 

Where do we store those files ? Which directory ? which file name ? Which compiler should be use ? What's the compile command ? What you are quoting is not any of the 12 languages I know (x86 ASM, ARM ASM, Saturn ASM, C, C++, Bash, Shell, Perl, Python, Prolog, VHDL ... )

Share this post


Link to post
Share on other sites

After reading https://docs.armbian.com/Hardware_Allwinner_overlays/ I have tried:

# aptitude install linux-headers-sun8i
# aptitude install linux-headers-dev-sun8i
# armbian-add-overlay myili9431.dts
Kernel headers are not installed properly. Please install the kernel headers package
# uname -r
4.13.16-sunxi

 

so in short, Armbian does not provide any package header for the default kernel ...

 

EDIT: after a good sleep, I have found the right kernel-headers:

 

# dpkg -S /boot/vmlinuz-4.13.16-sunxi
linux-image-next-sunxi: /boot/vmlinuz-4.13.16-sunxi
# aptitude install linux-headers-next-sunxi

I have stored your first bit of code in /root/myili9431.dts:

# armbian-add-overlay myili9431.dts
Compiling the overlay
Error: myili9431.dts:29.1-6 syntax error
FATAL ERROR: Unable to parse input tree
Error compiling the overlay

After removing the very last line "EOF":

# armbian-add-overlay myili9431.dts
Compiling the overlay
Copying the compiled overlay file to /boot/overlay-user/
Reboot is required to apply the changes

So please edit your initial post and remove that EOF thing. I don't plan on using the touch layer, so, I am not going to break my mind on that part.

 

Now comes the second big issue:

# ./compile.sh BRANCH=dev BOARD=orangepizero KERNEL_ONLY=yes PROGRESS_DISPLAY=plain RELEASE=jessie
Error: missing build directory structure
Please clone the full repository https://github.com/armbian/build/
# ls
build  compile.sh  lib

I have cloned this twice, and it's still asking me to clone it.

Share this post


Link to post
Share on other sites

In the end, what worked for me:

 

0: my system: "ARMBIAN 5.35 user-built Debian GNU/Linux 8 (jessie) 4.13.16-sunxi" (called next)

1: I am not going to try using the touch layer.

2: wire things as described (with LED directly on 3.3V)

3: aptitude install linux-headers-next-sunxi

4: copy the content of "Configuration for the first spi bus" from initial post, except last line about EOF, into /root/myili9431.dts

5: armbian-add-overlay myili9431.dts

6: edit /boot/armbianEnv.txt and edit this line (some parts may be useless or overkill) overlays=usbhost2 usbhost3 spi-spidev spidev myili9431 (this appeared to be useless)

7: reboot

8: modprobe fbtft_device custom name=fb_ili9341 gpios=dc:3,reset:0,led:6 speed=16000000 busnum=1

... and immediately the LCD turned from all white, into classic console (black background with prompt at the top)

 

Here is my dmesg:

 

[  166.951033] fbtft: module is from the staging directory, the quality is unknown, you have been warned.
[  166.962129] fbtft_device: module is from the staging directory, the quality is unknown, you have been warned.
[  166.967576] fbtft_device: GPIOS used by 'fb_ili9341':
[  166.967602] fbtft_device: 'dc' = GPIO3
[  166.967627] fbtft_device: 'reset' = GPIO0
[  166.967649] fbtft_device: 'led' = GPIO6
[  166.967703] spi spi1.0: fb_ili9341 spi1.0 16000kHz 8 bits mode=0x00
[  166.983929] fb_ili9341: module is from the staging directory, the quality is unknown, you have been warned.
[  167.341354] Console: switching to colour frame buffer device 30x40
[  167.344793] graphics fb0: fb_ili9341 frame buffer, 240x320, 150 KiB video memory, 16 KiB buffer memory, fps=20, spi1.0 at 16 MHz

https://kaspars.net/blog/linux/spi-display-orange-pi-zero mentions rotate=90 ... could be usefull for someone :)

 

9: xinit worked immediately

Share this post


Link to post
Share on other sites
On 6.7.2017 at 1:35 AM, adrb said:

./compile.sh BRANCH=dev BOARD=orangepizero KERNEL_ONLY=yes PROGRESS_DISPLAY=plain RELEASE=jessie


@adrb First of all thanks for your instructions, but if I try to use the compile script in my folder where I copied it, I get the following message:
 

./compile.sh BRANCH=dev BOARD=orangepizero KERNEL_ONLY=yes PROGRESS_DISPLAY=plain RELEASE=jessie
Error: missing build directory structure
Please clone the full repository https://github.com/armbian/build/


What did I wrong? I followed all you points till I get this message.

 

Thank you in advance

Share this post


Link to post
Share on other sites
On 1/17/2018 at 10:36 AM, DoubleHP said:

In the end, what worked for me:

 

0: my system: "ARMBIAN 5.35 user-built Debian GNU/Linux 8 (jessie) 4.13.16-sunxi" (called next)

1: I am not going to try using the touch layer.

2: wire things as described (with LED directly on 3.3V)

3: aptitude install linux-headers-next-sunxi

4: copy the content of "Configuration for the first spi bus" from initial post, except last line about EOF, into /root/myili9431.dts

5: armbian-add-overlay myili9431.dts

6: edit /boot/armbianEnv.txt and edit this line (some parts may be useless or overkill) overlays=usbhost2 usbhost3 spi-spidev spidev myili9431 (this appeared to be useless)

7: reboot

8: modprobe fbtft_device custom name=fb_ili9341 gpios=dc:3,reset:0,led:6 speed=16000000 busnum=1

... and immediately the LCD turned from all white, into classic console (black background with prompt at the top)

....

9: xinit worked immediately

 

Ad3.

Yes, guide is for mainline kernel, I tested it on 4.11 if I recall correctly.

Ad 4.

Yes, sorry my bad.

 

 

Share this post


Link to post
Share on other sites
On 19/03/2018 at 10:17 PM, Kevin Wietzorek said:

What did I wrong? I followed all you points till I get this message.

 

Either I tried to mkdir build, or, maybe I made the LCD work without this git tree; I forgot. But according to my last post, I probably got it working without this git tree. Try my post from Jan 17th 2018 ...

Share this post


Link to post
Share on other sites
4 minutes ago, DoubleHP said:

 

Either I tried to mkdir build, or, maybe I made the LCD work without this git tree; I forgot. But according to my last post, I probably got it working without this git tree. Try my post from Jan 17th 2018 ...

 

If you don't plan to use touchscreen, then no need to recompile kernel.

Share this post


Link to post
Share on other sites
On 3/19/2018 at 9:17 PM, Kevin Wietzorek said:

What did I wrong? I followed all you points till I get this message.

 

I would check armbian docs, maybe something changed - I must admit that I was busy with other things and hadn't recompile Armbian kernel since then.

 

Share this post


Link to post
Share on other sites
4 4