Jump to content

Guide: How to use Touchscreen + LCD on H3 devices


Recommended Posts

First of all, credits goes to https://4pda.ru/forum/lofiversion/index.php?t750921-2560.html

Device that I used for this guide: https://www.aliexpress.com/item/3-5-Inch-TFT-LCD-Moudle-For-Raspberry-Pi-2-Model-B-RPI-B-raspberry-pi/32707058182.html

Pinout: http://www.waveshare.com/3.5inch-rpi-lcd-a.htm (Yes, the device is a waveshare knockoff)

How to place the device? For Orange pi lite/one it is reversed. For the rest, it should be normal.

Refer to https://forum.armbian.com/index.php?/topic/724-quick-review-of-orange-pi-one/ for more info.

 

There are two sections to this guide.

Legacy / Mainline

Legacy Kernel [You can only EITHER use touch or LCD due to issues with spi chip select]

LCD

1) Load fbtft and fbtft_device on boot

sudo nano /etc/modules-load.d/fbtft.conf 
fbtft
fbtft_device

2) Load fbtft_device options

nano /etc/modprobe.d/fbtft.conf 
options fbtft_device rotate=90 name=piscreen speed=16000000 gpios=reset:2,dc:71 txbuflen=32768 fps=25

3) Make sure X11 loads to the correct framebuffer (fb8 for legacy)

nano /etc/X11/xorg.conf.d/50-fbturbo.conf
find fb0 and change to fb8

4) Reboot your device (sudo reboot) and you screen should be lit up

============================================

TOUCH

1) Download ads7846 touch driver (compatible with xpt2046)

mkdir ds7846 
cd ds7846 
wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.6.y/drivers/input/touchscreen/ads7846.c

2) Create a makefile (Take note that it is TABS instead of spaces before the $(MAKE))

nano Makefile
Insert the below in without the -----
--------------------------------
obj-m := ads7846.o 
KDIR := /lib/modules/$(shell uname -r)/build 
PWD := $(shell pwd) 
all:
	$(MAKE) -C $(KDIR) M=$(PWD) modules 
clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean 
install:
	$(MAKE) -C $(KDIR) M=$(PWD) modules_install
--------------------------------

3) Exit nano and run the following

sudo make
sudo make install
sudo depmod

4) Download and compile and install ads7846_device

cd .. 
git clone https://github.com/notro/fbtft_tools/
cd fbtft_tools/ads7846_device 
make 
sudo make install 
sudo depmod 

5) Load ads7846 and ads7846_device on boot

sudo nano /etc/modules-load.d/ads7846.conf 
ads7846 
ads7846_device

6) Load ads7846_device options

nano /etc/modprobe.d/ads7846_device.conf 
options ads7846_device model=7846 cs=0 gpio_pendown=1 keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900

7) Reboot your device and run evtest

sudo reboot
sudo evtest

Find your touch device and happy touching. Every touch should generate an event.

Link to comment
Share on other sites

Mainline Kernel [You can use BOTH LCD and TOUCH]

1) Enable overlays for spi and cs1

sudo nano /boot/armbianEnv.txt
add the following to the bottom

overlays=spi-spidev spi-add-cs1 
param_spidev_spi_bus=0 
param_spidev_spi_cs=1

2) Reboot your device

 

LCD

1) Load fbtft and fbtft_device on boot

sudo nano /etc/modules-load.d/fbtft.conf 
fbtft
fbtft_device

2) Load fbtft_device options

nano /etc/modprobe.d/fbtft.conf 
options fbtft_device rotate=90 name=piscreen speed=16000000 gpios=reset:2,dc:71 txbuflen=32768 fps=25

3) Since there is no GUI in mainline, lets enable the console to be displayed to LCD instead

sudo nano /etc/rc.local 
con2fbmap 1 1

For some others, you may wish to try con2fbmap 1 0 [If your device has no AVout]

 

4) Reboot your device (sudo reboot) and you screen should be lit up

===========================================================================

TOUCH

1) Download ads7846 touch driver (compatible with xpt2046)

mkdir ds7846 
cd ds7846 
wget https://sourceforge.net/p/openipmi/linux-ipmi/ci/master/tree/drivers/input/touchscreen/ads7846.c?format=raw
mv ads7846.c?format=raw ads7846.c 

2) Create a makefile (Take note that it is TABS instead of spaces before the $(MAKE))

nano Makefile
Insert the below in without the -----
--------------------------------
obj-m := ads7846.o 
KDIR := /lib/modules/$(shell uname -r)/build 
PWD := $(shell pwd) 
all:
	$(MAKE) -C $(KDIR) M=$(PWD) modules 
clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean 
install:
	$(MAKE) -C $(KDIR) M=$(PWD) modules_install
--------------------------------

3) Exit nano and run the following

sudo make
sudo make install
sudo depmod

4) Download and compile and install ads7846_device

cd .. 
git clone https://github.com/notro/fbtft_tools/
cd fbtft_tools/ads7846_device 
make 
sudo make install 
sudo depmod 

5) Load ads7846 and ads7846_device on boot

sudo nano /etc/modules-load.d/ads7846.conf 
ads7846 
ads7846_device

6) Load ads7846_device options

nano /etc/modprobe.d/ads7846_device.conf 
options ads7846_device model=7846 cs=1 gpio_pendown=1 keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900

 

Link to comment
Share on other sites

FAQ / Personal Experiences

Q1) If you wish to do manual testing, without rebooting, we have to rmmod and then modprobe manually [Make sure you have already done all the steps till depmod

sudo rmmod fbtft_device
sudo rmmod fbtft
sudo rmmod ads7846_device
sudo rmmod ads7846


sudo modprobe ads7846 
sudo modprobe ads7846_device model=7846 cs=1 gpio_pendown=1 keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900

sudo modprobe fbtft
sudo modprobe fbtft_device rotate=90 name=piscreen speed=16000000 gpios=reset:2,dc:71 txbuflen=32768 fps=25

 

Q2) My mainline kernel suddenly doesn't show me that my device is touchable through evtest. I experienced this and i did the following

Remove all on boot loading for ads7846 and fbtft

sudo rm /etc/modules-load.d/ads7846.conf
sudo rm /etc/modprobe.d/ads7846_device.conf
sudo rm /etc/modprobe.d/fbtft.conf
sudo rm /etc/modules-load.d/fbtft.conf

After which, lets manually 'automatically' load them through rc.local

nano /etc/rc.local
modprobe ads7846 
modprobe ads7846_device model=7846 cs=1 gpio_pendown=1 keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900
modprobe fbtft
modprobe fbtft_device rotate=90 name=piscreen speed=16000000 gpios=reset:2,dc:71 txbuflen=32768 fps=25
con2fbmap 1 0

Take note that con2fbmap is either 1 0 or 1 1 for mainline (1 0 --> orange pi lite or devices without AVOUT, 1 1 --> for devices with AVOUT like orange pi zero)

For advanced users, check /dev/ and see what is your fbX

 

Q3) I have installed a GUI for my mainline kernel but touch stops at times.

I experience this too and I have no idea on how to fix it.

 

Q4) I need to calibrate it

Yes, me too. However, my device isn't working very well. You need tslib and stuff to do the calibration.

Link to comment
Share on other sites

Small note - on mainline both fbtft displays and touch screens can be activated with DT overlays, without compiling extra modules or passing module parameters to modprobe.

For touch screens bindings are well documented, but since fbtft module is staging there is no official documentation in the kernel, so RPi overlays can be used as a reference: https://github.com/notro/fbtft/wiki/FBTFT-RPI-overlays

Link to comment
Share on other sites

Spoiler

 

On 31.7.2017 at 2:04 PM, kutysam said:

Mainline Kernel [You can use BOTH LCD and TOUCH]

1) Enable overlays for spi and cs1



sudo nano /boot/armbianEnv.txt
add the following to the bottom

overlays=spi-spidev spi-add-cs1 
param_spidev_spi_bus=0 
param_spidev_spi_cs=1

2) Reboot your device

 

LCD

1) Load fbtft and fbtft_device on boot



sudo nano /etc/modules-load.d/fbtft.conf 
fbtft
fbtft_device

2) Load fbtft_device options



nano /etc/modprobe.d/fbtft.conf 
options fbtft_device rotate=90 name=piscreen speed=16000000 gpios=reset:2,dc:71 txbuflen=32768 fps=25

3) Since there is no GUI in mainline, lets enable the console to be displayed to LCD instead



sudo nano /etc/rc.local 
con2fbmap 1 1

For some others, you may wish to try con2fbmap 1 0 [If your device has no AVout]

 

4) Reboot your device (sudo reboot) and you screen should be lit up

===========================================================================

TOUCH

1) Download ads7846 touch driver (compatible with xpt2046)



mkdir ds7846 
cd ds7846 
wget https://sourceforge.net/p/openipmi/linux-ipmi/ci/master/tree/drivers/input/touchscreen/ads7846.c?format=raw
mv ads7846.c?format=raw ads7846.c 

2) Create a makefile (Take note that it is TABS instead of spaces before the $(MAKE))



nano Makefile
Insert the below in without the -----
--------------------------------
obj-m := ads7846.o 
KDIR := /lib/modules/$(shell uname -r)/build 
PWD := $(shell pwd) 
all:
	$(MAKE) -C $(KDIR) M=$(PWD) modules 
clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean 
install:
	$(MAKE) -C $(KDIR) M=$(PWD) modules_install
--------------------------------

3) Exit nano and run the following



sudo make
sudo make install
sudo depmod

4) Download and compile and install ads7846_device



cd .. 
git clone https://github.com/notro/fbtft_tools/
cd fbtft_tools/ads7846_device 
make 
sudo make install 
sudo depmod 

5) Load ads7846 and ads7846_device on boot



sudo nano /etc/modules-load.d/ads7846.conf 
ads7846 
ads7846_device

6) Load ads7846_device options



nano /etc/modprobe.d/ads7846_device.conf 
options ads7846_device model=7846 cs=1 gpio_pendown=1 keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900

 

Thanks for your guide

Could you please tell how could I install fbtft on Armbian. The first step is installing fbtft but I do not know how could I do that.

Edited by Tido
unnecessary large Quote, added spoiler
Link to comment
Share on other sites

I was able to get everything working on mainline kernel w/ mate installed, but somehow the touchscreen's left-to-right is acting weird.  The cursor moves opposite to how I'm moving the pen, but only in the x-direction. It follows the pen up and down still. If I change the rotate option in to 270 instead of 90, the y-direction gets mirrored instead of the x. Is there an option to only mirror one axis?

Link to comment
Share on other sites

hi. i have orange pi lite and  http://www.waveshare.com/3.5inch-rpi-lcd-a.htm lcd .

i do all things you say . but i see a light white page. please help meeee. please

 

I have a problem when i show screen in lcd touch screen do not work. in other hand if i dont screen on lcd orange pi lite reconginiz touch screen. please help me . i think this problem become from spi.

Link to comment
Share on other sites

Thanks for the guide! I tried this, only for the touch screen since I am using an HDMI monitor, but it's not working.

 

It is a 5" waveshare clone (v2)

 

I scoped the spi bus and the interrupt pin. I see some strange characteristics.

 

SCLK is fine:

 

sclk

 

MOSI is only driven to ~1v

MOS

 

MISO is less than a volt:

 

MISO

 

And the interrupt on PA1 is ~0.5v

INT

 

I am using an orange pi pc plus on 4.14.84

 

Anyone have some idea of what might be going on?

 

Link to comment
Share on other sites

Hi everyone, I was able to get my lcd https://www.amazon.com/gp/product/B01IGBDT02/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1 to work Im running on Orange Pi zero H2 Armbian Bionic mainline based kernel 4.19.y. Ive tried everything here several times, but for some reason my touchscreen still doesnt work. Ive noticed that when Im running sudo make install in the ads7846 part Im getting something saying " WARNING: modules_install: missing 'System.map' file. missing Skipping depmod" . Is this normal? Other than that I dont understand what Im doing wrong. Also tried sudo modprobe ads7846_device model=7846 cs=1 gpio_pendown=1 keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900 . Gives me an error " modprobe: ERROR: could not insert 'ads7846_device': invalid arguement"  Im greatfull for any help.

Link to comment
Share on other sites

  ___  ____  _    ___
 / _ \|  _ \(_)  / _ \ _ __   ___
| | | | |_) | | | | | | '_ \ / _ \
| |_| |  __/| | | |_| | | | |  __/
 \___/|_|   |_|  \___/|_| |_|\___|

Welcome to Armbian 21.02.1 Focal with Linux 5.10.12-sunxi

System load:   29%              Up time:       0 min
Memory usage:  23% of 491M      IP:            192.168.101.15
CPU temp:      63°C             Usage of /:    11% of 30G

[ General system configuration (beta): armbian-config ]


root@orangepione:~/ds7846# ls
ads7846.c  Makefile
root@orangepione:~/ds7846# cat Makefile
obj-m := ads7846.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
        $(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
        $(MAKE) -C $(KDIR) M=$(PWD) clean
install:
        $(MAKE) -C $(KDIR) M=$(PWD) modules_install
root@orangepione:~/ds7846# sudo make
make -C /lib/modules/5.10.12-sunxi/build  M=/root/ds7846  modules
make[1]: *** /lib/modules/5.10.12-sunxi/build: No such file or directory.  Stop.
make: *** [Makefile:5: all] Error 2
root@orangepione:~/ds7846#

 

 

I am ending on this error, how to fix it? :( When my arm distro dont have this module loaded?

And what is correct wiring? I did this one: https://www.waveshare.com/3.5inch-rpi-lcd-a.htm screen is white os its look ok ...  

 

 

Link to comment
Share on other sites

28 minutes ago, locki said:

how to fix it?

 

For start, you might need to install kernel headers. 

 

armbian-config -> software -> install headers

 

Then try again. Regarding display connection or if the method is proper - no idea.

Link to comment
Share on other sites

after install drivers:

 

 

all works but my touch screen is inverted :( i tryex invert swap axes etc ... 

 

I tryed all also some tips from @olehs but no luck... any other tips?

root@orangepione:~# cat /etc/X11/xorg.conf.d/99-calibration.conf-35
Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "ADS7846 Touchscreen"
        Option  "Calibration"   "200 3933 170 3869"
        Option "SwapAxes" "0"
        Option "TransformationMatrix" "1 0 0 0 -1 1 0 0 1" # tip from olehs but also not working 
EndSection
 

Edited by locki
new update
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