{"id":64,"date":"2014-12-28T21:53:56","date_gmt":"2014-12-28T21:53:56","guid":{"rendered":"http:\/\/cooljc.me.uk\/?p=64"},"modified":"2015-11-05T10:07:55","modified_gmt":"2015-11-05T10:07:55","slug":"setting-up-tontec-3-5-inch-tft-using-the-fbtft-driver","status":"publish","type":"post","link":"https:\/\/cooljc.me.uk\/?p=64","title":{"rendered":"Setting up TonTec 3.5 Inch TFT using the fbtft driver"},"content":{"rendered":"<p>This is a follow up post to my other <a href=\"http:\/\/cooljc.me.uk\/?page_id=14\">page<\/a> 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 <a href=\"https:\/\/github.com\/notro\/fbtft\">fbtft<\/a> project it is simpler to use the kernel provided Notro. These instructions are for the Raspbian distribution for the Raspberry Pi.<\/p>\n<p><strong>Step 1 &#8211; Install Raspbain<\/strong><\/p>\n<p>I will not cover this step as there are plenty of other sites offering tutorials about this. Just google for &#8220;install Raspbian&#8221;.<\/p>\n<p><strong>Step 2 &#8211; Update the system<\/strong><\/p>\n<p>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).<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Update raspbian\"># Update the apt cache\r\nsudo apt-get update\r\n\r\n# Download and install updated packages.\r\nsudo apt-get upgrade<\/pre>\n<p><strong>Step 3 &#8211; Install fbtft kernel and modules<\/strong><\/p>\n<p>This step will install the latest kernel including the fbtft drivers and modules. Again from a terminal window issue the following command.<\/p>\n<pre class=\"lang:sh decode:true \" title=\"Install kernel and drivers\"># Download and install the kernel + drivers\r\nsudo REPO_URI=https:\/\/github.com\/notro\/rpi-firmware rpi-update\r\n\r\n# Reboot the Raspberry Pi\r\nsudo reboot<\/pre>\n<p><strong>Step 4 &#8211; Configure the driver<\/strong><\/p>\n<p>In this step we will need to edit some files. The easiest editor on the command line is &#8220;nano&#8221;. The files we will be editing are as follows:<\/p>\n<ul>\n<li>\/etc\/modprobe.d\/raspi-blacklist.conf &#8211; Used to prevent modules from loading<\/li>\n<li>\/etc\/modules &#8211; Used to load modules at boot time<\/li>\n<li>\/boot\/cmdline.txt &#8211; Used to customise kernel driver options during boot.<\/li>\n<\/ul>\n<p>First we will edit raspi-blacklist.conf. We need to prevent this from blacklisting &#8220;spi-bcm2708&#8221; as this is a dependency for fbtft. So type the following command in the terminal window.<\/p>\n<pre class=\"lang:default decode:true \" title=\"Edit \/etc\/modprobe.d\/raspi-blacklist.conf\"># Edit \/etc\/modprobe.d\/raspi-blacklist.conf\r\nsudo nano \/etc\/modprobe.d\/raspi-blacklist.conf<\/pre>\n<p>File before editing:<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Before editing: \/etc\/modprobe.d\/raspi-blacklist.conf\"># blacklist spi and i2c by default (many users don't need them)\r\n\r\nblacklist spi-bcm2708\r\nblacklist i2c-bcm2708\r\nblacklist snd-soc-pcm512x\r\nblacklist snd-soc-wm8804<\/pre>\n<p>Then change the file to look like this:<\/p>\n<pre class=\"lang:sh decode:true \" title=\"After editing\"># blacklist spi and i2c by default (many users don't need them)\r\n\r\n#blacklist spi-bcm2708\r\nblacklist i2c-bcm2708\r\nblacklist snd-soc-pcm512x\r\nblacklist snd-soc-wm8804<\/pre>\n<p>Save and exit nano using &#8220;ctrl+x&#8221; then press &#8216;y&#8217;. Next we need to edit\u00a0\/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.<\/p>\n<ul>\n<li>WZ9486-Pi-EXT -&gt; use name=tontec35_9486 for fbtft_device option<\/li>\n<li>WZ9481-Pi-EXT -&gt; use name=tontec35_9481 for the fctft_device option<\/li>\n<\/ul>\n<pre class=\"lang:sh decode:true\" title=\"Edit \/etc\/modules\"># Edit \/etc\/modules\r\nsudo nano \/etc\/modules<\/pre>\n<p>File contents before editing:<\/p>\n<pre class=\"lang:default decode:true \" title=\"default file contents: \/etc\/modules\"># \/etc\/modules: kernel modules to load at boot time.\r\n#\r\n# This file contains the names of kernel modules that should be loaded\r\n# at boot time, one per line. Lines beginning with \"#\" are ignored.\r\n# Parameters can be specified after the module name.\r\n\r\nsnd-bcm2835<\/pre>\n<p>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):<\/p>\n<pre class=\"lang:default decode:true\" title=\"file contents after editing\"># \/etc\/modules: kernel modules to load at boot time.\r\n#\r\n# This file contains the names of kernel modules that should be loaded\r\n# at boot time, one per line. Lines beginning with \"#\" are ignored.\r\n# Parameters can be specified after the module name.\r\n\r\nsnd-bcm2835\r\nfbtft_device name=tontec35_9486 rotate=90<\/pre>\n<p>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).<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Edit \/boot\/cmdline.txt\"># Edit \/boot\/cmdline.txt\r\nnano \/boot\/cmdline.txt\r\n<\/pre>\n<p>File contents before editing:<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Contents before editing: \/boot\/cmdline.txt\">dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=\/dev\/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait<\/pre>\n<p>Edit the file to look like this (remember that it one line and may be wrapper in your editor):<\/p>\n<pre class=\"lang:sh decode:true\" title=\"File contents after editing: \/boot\/cmdline.txt\">dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=\/dev\/mmcblk0p2 rootfstype=ext4 elevator=deadline fbcon=map:10 rootwait<\/pre>\n<p>Ok you should now be able to test the changes. Save the file and exit nano. Then reboot the Raspberry Pi.<\/p>\n<pre class=\"lang:sh decode:true \" title=\"Reboot\"># Reboot \r\nsudo reboot<\/pre>\n<p>When the Raspberry Pi reboots you should now see the console messages being printed on the display.<\/p>\n<p><strong>Step 5 &#8211; Configure X to use \/dev\/fb1<\/strong><\/p>\n<p>In this step we will configure X to use \/dev\/fb1. First we need to install the frame buffer drivers for X.<\/p>\n<pre class=\"lang:sh decode:true \" title=\"Install fbdev for X\"># Install fbdev video driver for X\r\nsudo apt-get install xserver-xorg-video-fbdev<\/pre>\n<p>Next we need to create a new config file for X.<\/p>\n<pre class=\"lang:default decode:true \" title=\"create fbdev config\"># Create fbdev config file\r\nsudo nano \/usr\/share\/X11\/xorg.conf.d\/99-fbdev.conf<\/pre>\n<p>Once nano has started enter the following details:<\/p>\n<pre class=\"lang:sh decode:true \" title=\"\/usr\/share\/X11\/xorg.conf.d\/99-fbdev.conf\">Section \"Device\"\r\n        Identifier \"myfb\"\r\n        Driver \"fbdev\"\r\n        Option \"fbdev\" \"\/dev\/fb1\"\r\nEndSection<\/pre>\n<p>Save and exit nano (&#8220;ctrl+x&#8221; followed by &#8216;y&#8217;). Now try and start X using the following command:<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Start X Windows\"># Start X Windows\r\nstartx<\/pre>\n<p><strong>Step 6 &#8211; Configure the touch screen drivers<\/strong><\/p>\n<p>Now you should have X running on your LCD. Next we will configure the\u00a0ads7846 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.<\/p>\n<pre class=\"lang:sh decode:true \" title=\"Edit \/etc\/modules\"># Edit \/etc\/modules\r\nsudo nano \/etc\/modules<\/pre>\n<p>File contents before editing:<\/p>\n<pre class=\"lang:sh decode:true \" title=\"Contents before editing\"># \/etc\/modules: kernel modules to load at boot time.\r\n#\r\n# This file contains the names of kernel modules that should be loaded\r\n# at boot time, one per line. Lines beginning with \"#\" are ignored.\r\n# Parameters can be specified after the module name.\r\n\r\nsnd-bcm2835\r\nfbtft_device name=tontec35_9486 rotate=90<\/pre>\n<p>Change the file to look like this:<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Contents after editing\"># \/etc\/modules: kernel modules to load at boot time.\r\n#\r\n# This file contains the names of kernel modules that should be loaded\r\n# at boot time, one per line. Lines beginning with \"#\" are ignored.\r\n# Parameters can be specified after the module name.\r\n\r\nsnd-bcm2835\r\nfbtft_device name=tontec35_9486 rotate=90\r\nads7846_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<\/pre>\n<p>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.\u00a0Issue the following command in the terminal window.<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Install touch screen tools\"># Install some touch screen tools\r\nsudo apt-get install xinput evtest<\/pre>\n<p>Finally you need to create a new touch screen calibration config file for X. Create the file with the following command:<\/p>\n<pre class=\"lang:sh decode:true\" title=\"Create touch screen calibration file\"># Create the calibration file for X windows\r\nsudo nano \/usr\/share\/X11\/xorg.conf.d\/99-calibration.conf<\/pre>\n<p>Enter the following details into the file:<\/p>\n<pre class=\"lang:sh decode:true\" title=\"99-calibration.conf\">Section \"InputClass\"\r\n        Identifier \"calibration\"\r\n        MatchProduct \"ADS7846 Touchscreen\"\r\n        Option \"Calibration\" \"3930 89 3920 141\"\r\n        Option \"SwapAxes\" \"1\"\r\nEndSection<\/pre>\n<p>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.<\/p>\n<pre class=\"lang:sh decode:true \" title=\"Reboot\"># Reboot\r\nsudo reboot<\/pre>\n<p>Once the Raspberry Pi has rebooted you can startx from the command line. The touch screen should now work as a mouse pointer.<\/p>\n<p><strong>Credits<\/strong><\/p>\n<ul>\n<li>Notro &#8211; for the excellent <a href=\"https:\/\/github.com\/notro\/fbtft\/\">fbtft<\/a> driver and providing <a href=\"https:\/\/github.com\/notro\/rpi-firmware\">pre-built kernels<\/a>.<\/li>\n<li>Greg &#8211; for the information related to X fbdev settings posted in the comments on\u00a0my other <a href=\"http:\/\/cooljc.me.uk\/?page_id=14\">page<\/a>.<\/li>\n<li>Minde &#8211; for the information related to X\u00a0ADS7846 Touchscreen settings also posted in the comments on my other <a href=\"http:\/\/cooljc.me.uk\/?page_id=14\">page<\/a>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a class=\"more-link\" href=\"https:\/\/cooljc.me.uk\/?p=64\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=\/wp\/v2\/posts\/64"}],"collection":[{"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=64"}],"version-history":[{"count":14,"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":78,"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions\/78"}],"wp:attachment":[{"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cooljc.me.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}