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).
1 2 3 4 5 |
# Update the apt cache sudo apt-get update # Download and install updated packages. sudo apt-get upgrade |
Step 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.
1 2 3 4 5 |
# Download and install the kernel + drivers sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update # Reboot the Raspberry Pi sudo reboot |
Step 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.
1 2 |
# Edit /etc/modprobe.d/raspi-blacklist.conf sudo nano /etc/modprobe.d/raspi-blacklist.conf |
File before editing:
1 2 3 4 5 6 |
# 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-wm8804 |
Then change the file to look like this:
1 2 3 4 5 6 |
# 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-wm8804 |
Save 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
1 2 |
# Edit /etc/modules sudo nano /etc/modules |
File contents before editing:
1 2 3 4 5 6 7 |
# /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 |
Edit 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):
1 2 3 4 5 6 7 8 |
# /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 |
Once 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).
1 2 |
# Edit /boot/cmdline.txt nano /boot/cmdline.txt |
File contents before editing:
1 |
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait |
Edit the file to look like this (remember that it one line and may be wrapper in your editor):
1 |
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fbcon=map:10 rootwait |
Ok you should now be able to test the changes. Save the file and exit nano. Then reboot the Raspberry Pi.
1 2 |
# Reboot sudo reboot |
When 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.
1 2 |
# Install fbdev video driver for X sudo apt-get install xserver-xorg-video-fbdev |
Next we need to create a new config file for X.
1 2 |
# Create fbdev config file sudo nano /usr/share/X11/xorg.conf.d/99-fbdev.conf |
Once nano has started enter the following details:
1 2 3 4 5 |
Section "Device" Identifier "myfb" Driver "fbdev" Option "fbdev" "/dev/fb1" EndSection |
Save and exit nano (“ctrl+x” followed by ‘y’). Now try and start X using the following command:
1 2 |
# Start X Windows startx |
Step 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.
1 2 |
# Edit /etc/modules sudo nano /etc/modules |
File contents before editing:
1 2 3 4 5 6 7 8 |
# /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 |
Change the file to look like this:
1 2 3 4 5 6 7 8 9 |
# /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=60 |
Once 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.
1 2 |
# Install some touch screen tools sudo apt-get install xinput evtest |
Finally you need to create a new touch screen calibration config file for X. Create the file with the following command:
1 2 |
# Create the calibration file for X windows sudo nano /usr/share/X11/xorg.conf.d/99-calibration.conf |
Enter the following details into the file:
1 2 3 4 5 6 |
Section "InputClass" Identifier "calibration" MatchProduct "ADS7846 Touchscreen" Option "Calibration" "3930 89 3920 141" Option "SwapAxes" "1" EndSection |
Save and exit nano. We now need to reboot the Raspberry Pi for the driver settings at the beginning of this step to take effect.
1 2 |
# Reboot sudo reboot |
Once 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.