{"id":809,"date":"2015-03-21T11:09:51","date_gmt":"2015-03-21T09:09:51","guid":{"rendered":"http:\/\/lallafa.de\/blog\/?p=809"},"modified":"2015-03-21T11:09:51","modified_gmt":"2015-03-21T09:09:51","slug":"fbtft-setup-on-modern-raspbian","status":"publish","type":"post","link":"https:\/\/lallafa.de\/blog\/2015\/03\/fbtft-setup-on-modern-raspbian\/","title":{"rendered":"fbTFT Setup on modern Raspbian"},"content":{"rendered":"<p>I am a big fan of those small TFT displays in the size of the Raspi. They even come with a resistive touch panel and allow you to realize small applications with full UI control. With the fine <a href=\"https:\/\/github.com\/notro\/fbtft\/wiki\">fbtft<\/a> drivers from notro you can access them as regular framebuffers and use all software that runs otherwise only on &#8220;big screens&#8221; via HDMI.<\/p>\n<p>While setting up the TFT support in a Raspbian system was quite complex and includes compiling an own patched kernel, nowadays things got really simple. In this post I&#8217;ll give you a overview on the setup and how easy it has become&#8230;<\/p>\n<p>(And it works for good ol&#8217; Model A\/B, A+\/B+, and shiny new Model B2!)<\/p>\n<p><!--more--><\/p>\n<h3>1. Kernel Update and DT Overlay Setup<\/h3>\n<p>notro has merged his drivers to the upstream kernel tree and therefore you get the fbtft drivers already with the current Raspbian kernel sources. Just make sure to get an updated kernel:<\/p>\n<pre>&gt; sudo -s\r\n# rpi-update\r\n# reboot<\/pre>\n<p>Check the linux version:<\/p>\n<pre>&gt; uname -a\r\nLinux bert 3.18.9+ #768 PREEMPT Sun Mar 15 18:59:03 GMT 2015 armv6l GNU\/Linux<\/pre>\n<p>Don&#8217;t forget to reboot before checking your kernel version. Version <strong>3.18.9+<\/strong> and later are all suitable. These kernels use the <a href=\"http:\/\/devicetree.org\/\">DeviceTree<\/a> to configure external devices. This allows to add a new device by simply writing a configuration file (here a DT overlay) that describes what drivers to load and what resources to acquire.<\/p>\n<p>You have to find a suitable DT overlay for your display. The overlays are stored in\u00c2\u00a0<strong>\/boot\/overlays<\/strong>. I have a Watterott <a href=\"http:\/\/www.watterott.com\/de\/RPi-Display\">rpi-display<\/a>\u00c2\u00a0and there is already an overlay available:<\/p>\n<pre>&gt; ls \/boot\/overlays\/rpi*\r\n\/boot\/overlays\/rpi-display-overlay.dtb<\/pre>\n<p>Now let&#8217;s activate the display by adding this overlay: Open <strong>\/boot\/config.txt<\/strong> (as root) with your favorite editor<\/p>\n<pre>&gt; sudo vi \/boot\/config.txt<\/pre>\n<p>add (at the end) of the file:<\/p>\n<pre>dtoverlay=rpi-display<\/pre>\n<p>Note: do not write the <em>-overlay.dtb<\/em>\u00c2\u00a0postfix of the filename here!<\/p>\n<p>Now its time for a reboot:<\/p>\n<pre>&gt; sudo reboot<\/pre>\n<p>You can check the existence of your new display by looking at the framebuffer devices available on the system:<\/p>\n<pre>&gt; ls \/dev\/fb*dev\/fb0 \u00c2\u00a0\/dev\/fb1<\/pre>\n<p><strong>\/dev\/fb1<\/strong> is your TFT!<\/p>\n<h3>2. Boot console on the TFT<\/h3>\n<p>Typically you want to see your device booting on the TFT. I.e. your boot console must be mapped to \/dev\/fb1.<\/p>\n<p>Open <strong>\/boot\/cmdline.txt<\/strong> as root:<\/p>\n<pre>&gt; sudo vi \/boot\/cmdline.txt<\/pre>\n<p>and add at the end of the first line:<\/p>\n<pre>fbcon=map:10 fbcon=font:VGA8x8 logo.nologo<\/pre>\n<p>This maps the boot console to framebuffer 1, selects a smaller font, and disables the Raspberry Pi logo on the top left as it consumes too much space on such a small display.<\/p>\n<p>Now reboot and enjoy the boot messages \ud83d\ude42<\/p>\n<h3>3. X11 on the TFT<\/h3>\n<p>My applications mostly run on X11 therefore I need to launch X11 on the TFT.<\/p>\n<p>Nowadays this is done by editing\u00c2\u00a0<strong>\/usr\/share\/X11\/xorg.conf.d\/99-fbdev.conf<\/strong> (as root):<\/p>\n<pre>&gt; sudo vi\u00c2\u00a0\/usr\/share\/X11\/xorg.conf.d\/99-fbdev.conf<\/pre>\n<p>Change the \/dev\/fb0 entry to <strong>\/dev\/fb1:<\/strong><\/p>\n<pre>Section \"Device\"\r\n  Identifier \"bla\"\r\n  Driver \"fbdev\"\r\n  Option \"fbdev\" \"\/dev\/fb1\"\r\nEndSection<\/pre>\n<p>If you start X11 now you should see it on your TFT:<\/p>\n<pre>&gt; startx<\/pre>\n<p>If you touch the display with your fingers then you should already see the mouse pointer moving, but in the wrong direction&#8230; Thus we need calibration next!<\/p>\n<h3>4. Calibrate touch on X11<\/h3>\n<p>To calibrate the touch panel on X11 we need a tool called <strong>xinput_calibrator<\/strong> that is unfortunately not available as a Raspbian package, yet. We compile it from source:<\/p>\n<pre>&gt; apt-get install x11proto-input-dev x11proto-input-dev\r\n&gt;\u00c2\u00a0git clone https:\/\/github.com\/tias\/xinput_calibrator.git\r\n&gt; cd xinput_calibrator\r\n&gt; .\/autogen.sh\r\n&gt; .\/configure\r\n&gt; make\r\n&gt; sudo make install<\/pre>\n<p>Next step is to run X11 and the xinput_calibrator there. I suggest to use a remote shell (via ssh) to run these commands. The calibrator will ask you to tip on some corners of the display. Use a pen to hit the crosses with high precision.<\/p>\n<pre>&gt; startx &amp;\r\n&gt; \/usr\/local\/bin\/xinput_calibrator\r\n&gt; pkill x<\/pre>\n<p>On your remote shell console the calibrator tool will print your display&#8217;s calibration data that looks like this:<\/p>\n<pre>Section \"InputClass\"\r\n  Identifier \"calibration\"\r\n  MatchProduct \"ADS7846 Touchscreen\"\r\n  Option \"Calibration\" \"210 3955 3775 260\"\r\n  Option \"SwapAxes\" \"1\"\r\nEndSection<\/pre>\n<p>Open a new file (as root) in\u00c2\u00a0<strong>\/usr\/share\/X11\/xorg.conf.d\/99-calib.conf<\/strong> and copy the contents of the above section (Section &#8230; EndSection) into it.<\/p>\n<p>If you start X11 again then the mouse pointer will follow your touch movements very closely.<\/p>\n<h3>5. Setup your X11 Application<\/h3>\n<p>I usually configure my Raspi so that it runs a fullscreen X11 application automatically in startup.<\/p>\n<p>First we need to create a file called <strong>$HOME\/.xinitrc<\/strong> and make it executable. There you state the X11 programs that will be run automatically after a startx.<\/p>\n<pre>&gt; vi $HOME\/.xinitrc\r\n&gt; chmod 755 $HOME\/.xinitrc<\/pre>\n<p>The file typically looks like:<\/p>\n<pre>xset s off # don't activate screensaver\r\nxset -dpms # disable DPMS (Energy Star) features.\r\nxset s noblank # don't blank the video device\r\nexec $HOME\/raspi\/piradio\/piradio.py<\/pre>\n<p>Note that the last line uses <strong>exec<\/strong> to launch your X11 application! The <strong>xset<\/strong>\u00c2\u00a0command are used to disable blanking of the TFT display. You can omit or adjust these if you want to have blanking.<\/p>\n<p>Test with startx&#8230; It will run your application full screen. BTW:\u00c2\u00a0Make sure to add some UI to exit your application otherwise you can&#8217;t leave X11 \ud83d\ude42 (or use pkill x from a remote shell)<\/p>\n<pre>&gt; startx<\/pre>\n<h3>6. Autorun X11<\/h3>\n<p>The final step is to launch X11 automatically. While raspbian already has this feature I don&#8217;t use it as it runs lightdm as a display manager and is IMHO too bulky for the startup. I disable automatic startup in raspi-config (if its enabled) first.<\/p>\n<p>Edit\u00c2\u00a0<strong>\/etc\/rc.local<\/strong> as root and add this line:<\/p>\n<pre>su -l chris -c startx &amp;<\/pre>\n<p>Note: My username is chris on the Rapsi. If you use the default user pi then adapt the line accordingly.<\/p>\n<p>On the next reboot you will see your application on the TFT right after some seconds of booting&#8230;<\/p>\n<p>That&#8217;s it! I hope this post helps you to get started with your TFT quickly!<\/p>\n<p>Have fun!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am a big fan of those small TFT displays in the size of the Raspi. They even come with a resistive touch panel and allow you to realize small applications with full UI control. With the fine fbtft drivers &hellip; <a href=\"https:\/\/lallafa.de\/blog\/2015\/03\/fbtft-setup-on-modern-raspbian\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[16,9],"tags":[],"class_list":["post-809","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-software"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/piBMF-d3","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/comments?post=809"}],"version-history":[{"count":9,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/809\/revisions"}],"predecessor-version":[{"id":818,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/809\/revisions\/818"}],"wp:attachment":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/media?parent=809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/categories?post=809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/tags?post=809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}