This is a follow up post to my other page describing how I managed to get the Tontec 3.5 inch TFT to work using a modified fbtft driver. Now my changes have been accepted to the fbtft project it is simpler to use the kernel provided Notro. These instructions are for the Raspbian distribution for the Raspberry Pi.
Step 1 – Install Raspbain
I will not cover this step as there are plenty of other sites offering tutorials about this. Just google for “install Raspbian”.
Step 2 – Update the system
Before you install the fbtft drivers it is wise to update the system. This step needs to be performed on the Raspberry Pi from a terminal window (or ssh from a remote computer).
# Update the apt cache
sudo apt-get update
# Download and install updated packages.
sudo apt-get upgradeStep 3 – Install fbtft kernel and modules
This step will install the latest kernel including the fbtft drivers and modules. Again from a terminal window issue the following command.
# Download and install the kernel + drivers
sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update
# Reboot the Raspberry Pi
sudo rebootStep 4 – Configure the driver
In this step we will need to edit some files. The easiest editor on the command line is “nano”. The files we will be editing are as follows:
- /etc/modprobe.d/raspi-blacklist.conf – Used to prevent modules from loading
- /etc/modules – Used to load modules at boot time
- /boot/cmdline.txt – Used to customise kernel driver options during boot.
First we will edit raspi-blacklist.conf. We need to prevent this from blacklisting “spi-bcm2708” as this is a dependency for fbtft. So type the following command in the terminal window.
# Edit /etc/modprobe.d/raspi-blacklist.conf
sudo nano /etc/modprobe.d/raspi-blacklist.confFile before editing:
# blacklist spi and i2c by default (many users don't need them)
blacklist spi-bcm2708
blacklist i2c-bcm2708
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804Then change the file to look like this:
# blacklist spi and i2c by default (many users don't need them)
#blacklist spi-bcm2708
blacklist i2c-bcm2708
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804Save and exit nano using “ctrl+x” then press ‘y’. Next we need to edit /etc/modules. Before editing this file you need to know which TonTec display you have. There are currently 2 different models available. You can find this printed on the back of the LCD PCB.
- WZ9486-Pi-EXT -> use name=tontec35_9486 for fbtft_device option
- WZ9481-Pi-EXT -> use name=tontec35_9481 for the fctft_device option
# Edit /etc/modules
sudo nano /etc/modulesFile contents before editing:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835Edit the file to look like this (remember to set the correct name=* option for your display. The rotate option can be 0, 90, 180 or 270. If not specified it will default to 0):
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
fbtft_device name=tontec35_9486 rotate=90Once you have changed the file save and exit nano. Finally we will add a new parameter to /boot/cmdline.txt. This new option will tell the kernel to map the console output to frame buffer 1 (/dev/fb1).
# Edit /boot/cmdline.txt
nano /boot/cmdline.txtFile contents before editing:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwaitEdit the file to look like this (remember that it one line and may be wrapper in your editor):
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fbcon=map:10 rootwaitOk you should now be able to test the changes. Save the file and exit nano. Then reboot the Raspberry Pi.
# Reboot
sudo rebootWhen the Raspberry Pi reboots you should now see the console messages being printed on the display.
Step 5 – Configure X to use /dev/fb1
In this step we will configure X to use /dev/fb1. First we need to install the frame buffer drivers for X.
# Install fbdev video driver for X
sudo apt-get install xserver-xorg-video-fbdevNext we need to create a new config file for X.
# Create fbdev config file
sudo nano /usr/share/X11/xorg.conf.d/99-fbdev.confOnce nano has started enter the following details:
Section "Device"
Identifier "myfb"
Driver "fbdev"
Option "fbdev" "/dev/fb1"
EndSectionSave and exit nano (“ctrl+x” followed by ‘y’). Now try and start X using the following command:
# Start X Windows
startxStep 6 – Configure the touch screen drivers
Now you should have X running on your LCD. Next we will configure the ads7846 device. First we need to configure the ads7846 driver module. This is done using the ads7846_device helper module through the /etc/modules file. Open this file for editing using nano.
# Edit /etc/modules
sudo nano /etc/modulesFile contents before editing:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
fbtft_device name=tontec35_9486 rotate=90Change the file to look like this:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
fbtft_device name=tontec35_9486 rotate=90
ads7846_device cs=1 speed=2000000 model=7846 pressure_max=255 y_min=190 swap_xy=1 y_max=3850 gpio_pendown=4 x_max=3850 x_min=230 x_plate_ohms=60Once you have edited the file save and exit nano. Next you need to install some additional tools for accessing the touch screen from X. Issue the following command in the terminal window.
# Install some touch screen tools
sudo apt-get install xinput evtestFinally you need to create a new touch screen calibration config file for X. Create the file with the following command:
# Create the calibration file for X windows
sudo nano /usr/share/X11/xorg.conf.d/99-calibration.confEnter the following details into the file:
Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "3930 89 3920 141"
Option "SwapAxes" "1"
EndSectionSave and exit nano. We now need to reboot the Raspberry Pi for the driver settings at the beginning of this step to take effect.
# Reboot
sudo rebootOnce the Raspberry Pi has rebooted you can startx from the command line. The touch screen should now work as a mouse pointer.
Credits
- Notro – for the excellent fbtft driver and providing pre-built kernels.
- Greg – for the information related to X fbdev settings posted in the comments on my other page.
- Minde – for the information related to X ADS7846 Touchscreen settings also posted in the comments on my other page.