I have a Waveshare 3.5″ TFT touch screen for the Raspberry Pi. Those displays come with some software to help set it up. Sadly, this only works for Raspbian based on Debian 7. The new Raspbian Debian 8 (Jessie) does not play well with this setup. So here is what I did to make it work.
First of all, you need to upgrade the kernel on your brand new Jessie installation:
$ sudo rpi-update
$ sudo power off
I had to do the power off, or else the Pi would show only a black screen after reboot. YMMV.
Next up, we need to change the boot parameters, i.e. the /boot/config.txt and /boot/cmdline.txt. Add the following to the end of /boot/cmdline.txt:
fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo
This chooses a smaller font for the framebuffer console and turns off the boot logo.
Second, add the following lines to the end of /boot/config.txt:
dtparam=audio=on
dtparam=spi=on
dtoverlay=ads7846,cs=1,penirq=17,penirq_pull=2,speed=1000000,keep_vref_on=1,swapxy=1,pmax=255,xohms=60,xmin=200,xmax=3900,ymin=200,ymax=3900
dtparam=i2c_arm=on
dtoverlay=w1-gpio-pullup,gpiopin=4,extpullup=1
Next step is setting up all the kernel modules. Make sure /etc/modules contains exactly these line:
spi-bcm2835
snd-bcm2835
i2c-bcm2708
i2c-dev
ads7846
flexfb
fbtft_device
The options for these modules have to be put in a file called /etc/modprobe.d/lcd.conf:
options flexfb width=320 height=480 regwidth=16 init=-1,0xb0,0x0,-1,0x11,-2,250,-1,0x3A,0x55,-1,0xC2,0x44,-1,0xC5,0x00,0x00,0x00,0x00,-1,0xE0,0x0F,0x1F,0x1C,0x0C,0x0F,0x08,0x48,0x98,0x37,0x0A,0x13,0x04,0x11,0x0D,0x00,-1,0xE1,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0xE2,0x0F,0x32,0x2E,0x0B,0x0D,0x05,0x47,0x75,0x37,0x06,0x10,0x03,0x24,0x20,0x00,-1,0x36,0x28,-1,0x11,-1,0x29,-3
options fbtft_device debug=3 rotate=90 name=flexfb speed=16000000 gpios=reset:25,dc:24
options ads7846_device model=7846 cs=1 gpio_pendown=17 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
Next up are the X11 configurations. First, add a file /etc/X11/xorg.conf.d/99-calibration.conf with the following content:
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "126, 3734, 3892, 199"
Option "SwapAxes" "1"
EndSection
You also need to edit /usr/share/X11/xorg.conf.d/99-fbturbo.conf. It should already exist, and you need to make it have this content:
Section "Device"
Identifier "Allwinner A10/A13 FBDEV"
Driver "fbturbo"
Option "fbdev" "/dev/fb1"
Option "SwapbuffersWait" "true"
EndSection
The change is setting the fbdev to /dev/fb1, which is the touchscreen, instead of /dev/fb0, which is the HDMI output.
Last but not least, you may want to install the input calibration tool:
$ sudo apt-get install xinput-calibrator
After all this, reboot and hopefully the Pi will reboot into a tiny X11 session on the touch screen.
You can calibrate the display by running this, e.g. via an ssh session:
$ DISPLAY=:0 xinput_calibrator
Calibrating EVDEV driver for "ADS7846 Touchscreen" id=6
current calibration values (from XInput): min_x=3932, max_x=300 and min_y=294, max_y=3801
Doing dynamic recalibration:
Swapping X and Y axis...
Setting calibration data: 2763, 2763, 2942, 2978
--> Making the calibration permanent
copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's)
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "2763 2763 2942 2978"
Option "SwapAxes" "1"
EndSection
You simply have to replace the calibration and swap axes lines into your /etc/X11/xorg.conf.d/99-calibration.conf, which we created earlier.
It just did not work on a Raspberry Pi 3b+running raspbian buster. I have tried this and other suggestions found on the web through Google. Either I am missing something or the ADS7846 Touchscreen I am using is broken.
Once again, the ads7846 screen no longer works, this time it is the move to Wayland under Bookworm that seems to be causing the issues… I am trying to get it to work and came across your post.