Jump to content

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 :/

 

 

 

 

 

Link to comment
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 ... )

Link to comment
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.

Link to comment
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

Link to comment
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

Link to comment
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.

 

 

Link to comment
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 ...

Link to comment
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.

Link to comment
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.

 

Link to comment
Share on other sites

Update:

 

I have bought

https://www.fasttech.com/products/0/10020192/5321900-3-5-320-480-tft-lcd-display-touch-board-for

Sold with the following specs:

Quote

# SKU MPI3501
# SKU 5321900
# XPT2046
# ILI9486

which seems to me very similar to

https://www.amazon.fr/gp/product/B06X191RX7/ref=oh_aui_detailpage_o02_s00?ie=UTF8&amp;psc=1

 

I started with image Armbian_5.35_Orangepizero_Ubuntu_xenial_next_4.13.16.img

 

And then, ran the following commands to get the LCD working on oPi0:


 

aptitude dist-upgrade
vim /root/myili9431.dts # see previous message
reboot
aptitude install linux-headers-next-sunxi
armbian-add-overlay myili9431.dts
reboot
modprobe fbtft_device custom name=fb_ili9486 gpios=dc:18,reset:2 speed=16000000 busnum=1

 

and now I have a console in portrait mode.

 

# cat /root/myili9431.dts
/* 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>;
            };
        };
    };
};

To get X:


 

# Some of the following packages may be facultative.
aptitude install startx xinit x11-xserver-utils xinput-calibrator xinput xserver-xorgxserver-xorg-video-all xterm x11-utils
startx # gives a black console
# or
xinit # gives a white console

 

Mouse does not work very well. Did not try keyboard. No touchpad (I don't need it, so, no time to loose on this).

 

Rotation of screen works, but produces crappy output.
 

# Need reboot each time
modprobe fbtft_device custom name=fb_ili9486 gpios=dc:18,reset:2 speed=16000000 busnum=1 rotate=90
modprobe fbtft_device custom name=fb_ili9486 gpios=dc:18,reset:2 speed=16000000 busnum=1 rotate=180
modprobe fbtft_device custom name=fb_ili9486 gpios=dc:18,reset:2 speed=16000000 busnum=1 rotate=270
# 90 and 270 produce a rectangle in landscape orientation; unusable in neither console or X.
# 180 works fine.

Bed time; more tries later.

 

Some tips to make conf persistent:

https://kaspars.net/blog/linux/spi-display-orange-pi-zero

Link to comment
Share on other sites

Random tips :
- orange pi zero all have 2 SPI bus: one in the main GPIO port, and one for the flash on the back side. If you don't have the plus model, you can unsolder the FLASH and use the port. FLASH is port 1, so, GPIO is port 1. This is very important when you follow tutorials written for other opis
- before you start following a tutorial, you need to understand which kernel you are using. If the turial is written after jan 2017, and mentions adding an overlay in armbianEnv.txt, then it's for kernel 4; if the tuto is before feb 2018, and does not mention altering armbianEnv.txt for SPI compatibility, author is using kernel 3. This is critical.
- I got adressable LEDs working on both kernels, 3 and 4. Easier on 4.
- SPI LCDs work only on kernel 3; I have spend days on kernel 4, just forget them; drivers exist, but they are broken.
- con2fbmap is required only on kernel 3
- to get X working, you need to create /etc/X11/xorg.conf.d/99-fbturbo.conf
- check your FB number with a command like this: dmesg | grep ili | grep graphics | grep -i fb . I have seen people using 0, 1 and 8.

 

Now, I have ili9486 working perfectly fine ... with image Armbian_5.35_Orangepizero_Ubuntu_xenial_default_3.4.113 (kernel 3.4.113).

Link to comment
Share on other sites

On 12/22/2018 at 8:40 PM, DoubleHP said:

Random tips :
- orange pi zero all have 2 SPI bus: one in the main GPIO port, and one for the flash on the back side. If you don't have the plus model, you can unsolder the FLASH and use the port. FLASH is port 1, so, GPIO is port 1. This is very important when you follow tutorials written for other opis
- before you start following a tutorial, you need to understand which kernel you are using. If the turial is written after jan 2017, and mentions adding an overlay in armbianEnv.txt, then it's for kernel 4; if the tuto is before feb 2018, and does not mention altering armbianEnv.txt for SPI compatibility, author is using kernel 3. This is critical.
- I got adressable LEDs working on both kernels, 3 and 4. Easier on 4.
- SPI LCDs work only on kernel 3; I have spend days on kernel 4, just forget them; drivers exist, but they are broken.
- con2fbmap is required only on kernel 3
- to get X working, you need to create /etc/X11/xorg.conf.d/99-fbturbo.conf
- check your FB number with a command like this: dmesg | grep ili | grep graphics | grep -i fb . I have seen people using 0, 1 and 8.

 

Now, I have ili9486 working perfectly fine ... with image Armbian_5.35_Orangepizero_Ubuntu_xenial_default_3.4.113 (kernel 3.4.113).

 

Hello friend,
I know it's an old discussion but I have read many posts on many forums and I couldn't find a clear answer.
I have an orange pi zero and I am not sure which version of armbian is compatible with SPI LCDs. I have a chinese waveshare clone 3.5" which is working fine on raspberry pi with waveshare drivers (both lcd and touchscreen).
Which armbian and kernel version should I use? You mention that we should use kenrel 3.x but you had some success with 4.x as well (on another forum).
Did you manage to enable touchscreen? I read that it could be done if we unsolder the flash rom so we could use the second SPI bus with touchscreen. Is it possible? Is there any other workaround?
Thank you

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines