{"id":6,"date":"2016-02-20T10:27:00","date_gmt":"2016-02-20T10:27:00","guid":{"rendered":""},"modified":"2016-04-17T17:13:51","modified_gmt":"2016-04-17T17:13:51","slug":"installing-an-ads7864-based-raspberry-pi-tft-touchscreen-waveshare-3-5-lcd","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=6","title":{"rendered":"Installing an ads7846 based Raspberry Pi TFT touchscreen (Waveshare 3.5&#8243; LCD)"},"content":{"rendered":"<p>I have a Waveshare 3.5&#8243; 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.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter wp-image-215 size-large\" src=\"https:\/\/www.root42.de\/blog\/wp-content\/uploads\/2016\/02\/IMG_1808-1-1024x768.jpg\" alt=\"IMG_1808\" width=\"840\" height=\"630\" srcset=\"https:\/\/www.root42.de\/blog\/wp-content\/uploads\/2016\/02\/IMG_1808-1-1024x768.jpg 1024w, https:\/\/www.root42.de\/blog\/wp-content\/uploads\/2016\/02\/IMG_1808-1-300x225.jpg 300w, https:\/\/www.root42.de\/blog\/wp-content\/uploads\/2016\/02\/IMG_1808-1-768x576.jpg 768w, https:\/\/www.root42.de\/blog\/wp-content\/uploads\/2016\/02\/IMG_1808-1-1200x900.jpg 1200w, https:\/\/www.root42.de\/blog\/wp-content\/uploads\/2016\/02\/IMG_1808-1.jpg 1600w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/>First of all, you need to upgrade the kernel on your brand new Jessie installation:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">$ sudo rpi-update\r\n$ sudo power off\r\n<\/code><\/pre>\n<p>I had to do the power off, or else the Pi would show only a black screen after reboot. YMMV.<\/p>\n<p>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:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo\r\n<\/code><\/pre>\n<p>This chooses a smaller font for the framebuffer console and turns off the boot logo.<\/p>\n<p>Second, add the following lines to the end of \/boot\/config.txt:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">dtparam=audio=on\r\ndtparam=spi=on\r\ndtoverlay=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\r\ndtparam=i2c_arm=on\r\ndtoverlay=w1-gpio-pullup,gpiopin=4,extpullup=1\r\n<\/code><\/pre>\n<p>Next step is setting up all the kernel modules. Make sure \/etc\/modules contains exactly these line:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">spi-bcm2835\r\nsnd-bcm2835\r\ni2c-bcm2708\r\ni2c-dev\r\nads7846\r\nflexfb\r\nfbtft_device\r\n<\/code><\/pre>\n<p>The options for these modules have to be put in a file called \/etc\/modprobe.d\/lcd.conf:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">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\r\noptions fbtft_device debug=3 rotate=90 name=flexfb speed=16000000 gpios=reset:25,dc:24\r\noptions 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\r\n<\/code><\/pre>\n<p>Next up are the X11 configurations. First, add a file \/etc\/X11\/xorg.conf.d\/99-calibration.conf\u00a0with the following content:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">Section \"InputClass\"\r\n    Identifier \"calibration\"\r\n    MatchProduct \"ADS7846 Touchscreen\"\r\n    Option \"Calibration\" \"126, 3734, 3892, 199\"\r\n    Option \"SwapAxes\" \"1\"\r\nEndSection\r\n<\/code><\/pre>\n<p>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:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">Section \"Device\"\r\n        Identifier      \"Allwinner A10\/A13 FBDEV\"\r\n        Driver          \"fbturbo\"\r\n        Option          \"fbdev\" \"\/dev\/fb1\"\r\n        Option          \"SwapbuffersWait\" \"true\"\r\nEndSection\r\n<\/code><\/pre>\n<p>The change is setting the fbdev to \/dev\/fb1, which is the touchscreen, instead of \/dev\/fb0, which is the HDMI output.<\/p>\n<p>Last but not least, you may want to install the input calibration tool:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">$ sudo apt-get install xinput-calibrator\r\n<\/code><\/pre>\n<p>After all this, reboot and hopefully the Pi will reboot into a tiny X11 session on the touch screen.<\/p>\n<p>You can calibrate the display by running this, e.g. via an ssh session:<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: 'arial'; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">$ DISPLAY=:0 xinput_calibrator \r\nCalibrating EVDEV driver for \"ADS7846 Touchscreen\" id=6\r\n        current calibration values (from XInput): min_x=3932, max_x=300 and min_y=294, max_y=3801\r\n\r\nDoing dynamic recalibration:\r\n        Swapping X and Y axis...\r\n        Setting calibration data: 2763, 2763, 2942, 2978\r\n        --&gt; Making the calibration permanent \r\n  copy the snippet below into '\/etc\/X11\/xorg.conf.d\/99-calibration.conf' (\/usr\/share\/X11\/xorg.conf.d\/ in some distro's)\r\nSection \"InputClass\"\r\n        Identifier      \"calibration\"\r\n        MatchProduct    \"ADS7846 Touchscreen\"\r\n        Option  \"Calibration\"   \"2763 2763 2942 2978\"\r\n        Option  \"SwapAxes\"      \"1\"\r\nEndSection\r\n<\/code><\/pre>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a Waveshare 3.5&#8243; 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 &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=6\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Installing an ads7846 based Raspberry Pi TFT touchscreen (Waveshare 3.5&#8243; LCD)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6"}],"version-history":[{"count":4,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":227,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions\/227"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}