<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>sudo Sergeant 13: Driving a TFT Screen Using GPIO</title><link>https://community.element14.com/challenges-projects/element14-presents/sudosergeant/w/documents/3442/sudo-sergeant-13-driving-a-tft-screen-using-gpio</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>sudo Sergeant 13: Driving a TFT Screen Using GPIO</title><link>https://community.element14.com/challenges-projects/element14-presents/sudosergeant/w/documents/3442/sudo-sergeant-13-driving-a-tft-screen-using-gpio</link><pubDate>Mon, 13 Aug 2018 22:56:27 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:19f95a3d-ef99-46a0-9cf1-678333586cad</guid><dc:creator>tariq.ahmad</dc:creator><comments>https://community.element14.com/challenges-projects/element14-presents/sudosergeant/w/documents/3442/sudo-sergeant-13-driving-a-tft-screen-using-gpio#comments</comments><description>Current Revision posted to Documents by tariq.ahmad on 8/13/2018 10:56:27 PM&lt;br /&gt;
&lt;table cellpadding="0" cellspacing="0" style="padding:0px;margin:0px;background-color:#c4e3ed;width:100%;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td rowspan="3" style="vertical-align:bottom;"&gt;&lt;a href="/e14/assets/legacy/2017/FelixExcLeft1.png"&gt;&lt;img alt="image" class="nolightbox" src="/e14/assets/legacy/2017/FelixExcLeft1.png"  /&gt;&lt;/a&gt;&lt;/td&gt;&lt;td rowspan="3" style="vertical-align:top;padding:8px 13px 13px 8px;"&gt;&lt;p style="margin:0;font-size:18px;font-weight:bold;padding-bottom:6px;"&gt;&lt;a class="jivecontainerTT-hover-container jive-link-community-small" href="/challengesprojects/element14-presents/benheck/"&gt;element14&amp;#39;s The Ben Heck Show&lt;/a&gt;&lt;/p&gt;&lt;p style="margin:0;padding-bottom:6px;line-height:18px;"&gt;&lt;strong&gt;Join the Ben Heck team every week for amazing hacks!&lt;/strong&gt; Watch them build and mod community-inspired projects using electronics!&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;a href="/challengesprojects/element14-presents/benheck/"&gt;Back to The Ben Heck Show homepage &lt;img loading="lazy" alt="image" src="/e14/assets/legacy/gen/LinkArrow.gif"  /&gt;&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;td style="padding:13px 10px 13px 13px;background-color:#004156;vertical-align:middle;" width="30%"&gt;&lt;a class="" href="https://www.element14.com/community/community/experts/benheck/sudosergeant?ICID=SS-episodedoc-topban"&gt;&lt;span style="color:#ffffff;text-decoration:none;"&gt;sudo Sergeant&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding:13px 10px 13px 13px;background-color:#005973;vertical-align:middle;"&gt;&lt;a class="" href="https://www.element14.com/community/community/experts/benheck/thelearningcircuit?ICID=SS-episodedoc-topban"&gt;&lt;span style="color:#ffffff;text-decoration:none;"&gt;The Learning Circuit&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td style="padding:13px 10px 13px 13px;background-color:#006f91;vertical-align:middle;"&gt;&lt;a class="jive-link-wiki-small" href="/challenges-projects/element14-presents/benheck/ben-heck-exclusive/w/documents/9678/the-ben-heck-show-episode-archive"&gt;&lt;span style="color:#ffffff;text-decoration:none;"&gt;See All Episodes&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;table style="width:80%;display:block;margin:0 auto;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="padding-bottom:12px;"&gt;&lt;span&gt;&lt;a href="https://www.youtube.com/watch?v=SqR6esRByzY"&gt;www.youtube.com/watch&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;p style="margin:0;border:1px solid #b8d7e5;background-color:#e9f6fc;padding:8px;max-width:634px;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:justify;"&gt;Felix shows you how to install retropie through terminal and how to drive a TFT screen with the GPIO of a Raspberry Pi. He configures SSH to login and modify some files, adds a custom device tree source file, compiles the device tree source file, and adds some additional lines to the config.txt file in order to get the kernel and operating system working together to drive the TFT screen with GPIO. &lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;&lt;span&gt;The first thing you want to do is download your disk image of retropie at &lt;/span&gt;&lt;a class="" href="https://retropie.org.uk/"&gt;https://retropie.org.uk/&lt;/a&gt;&lt;span&gt;.&amp;nbsp; You’ll have two different downloads to chose from.&amp;nbsp; One is for the Raspberry Pi Zero or the first Raspberry Pi and the other is for Raspberry Pi 2 and 3. Felix downloads the version for Raspberry Pi Zero.&amp;nbsp; Once it downloads Felix takes a look at it in terminal. It will show up in the image directory of terminal as retropie-4.3-rp1_zero.img.gz.&amp;nbsp; The gz extension at the end means it is a compressed file.&amp;nbsp; To expand it to an uncompressed file: &lt;/span&gt;&lt;/p&gt;&lt;blockquote class="jive-quote"&gt;&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;"&gt;$&amp;nbsp; gunzip -k -v retropie-4.3-rpi1_zero.img.gz &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;Felix shows a comparison between the compressed and the uncompressed file in terminal.&amp;nbsp; To find out where the SD card is he uses:&lt;/p&gt;&lt;blockquote class="jive-quote"&gt;&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;"&gt;$ lsblk&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;He uses the dd utility for converting and copying a file.&amp;nbsp; He goes over the man page for the dd utility to go over the various operands he needs to send to it.&amp;nbsp; He enters the following in terminal:&lt;/p&gt;&lt;blockquote class="jive-quote"&gt;&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;"&gt;$ sudo ./retropie=4.3-rpi1_zero.img of=/dev/sdd bs=10M status=progress&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;Felix suggests leaving off sudo initially to make sure you’re not writing to the wrong disk.&amp;nbsp; You’ll see the progress of the operating system moving to the SD card through terminal. Now that the operating system is in the SD card they can attach it to the Raspberry Pi.&amp;nbsp; As this is the Pi 1,&amp;nbsp; he’ll also hook it up a USB hub with Ethernet on it, before connecting the hub to a keyboard. Once Retropie boots on the Pi, press F4 and that will take you to terminal.&amp;nbsp; In terminal you will enter: $ sudo raspi –config This will take you into the configuration menu. Go to interfacing Options.&amp;nbsp;&amp;nbsp; From there go down to SSH and enable it.&amp;nbsp; Next go into localization options and change local. You’re going to want to switch it to whatever your local region is.&amp;nbsp; Felix finds and selects the region code for the US. He also goes over how to set your Timezone, Keyboard Layout, and Wi Fi country.&amp;nbsp; Next, Felix goes into the Advanced Options where he selects the option to Expand the file system to ensure that all of the SD card storage is available to the OS. After you do all that, reboot the Pi. Felix consults the man page for nmap and uses the nmap utility to find the ip address of the Raspberry Pi through terminal.&amp;nbsp;&amp;nbsp; In his case it looks like:&lt;/p&gt;&lt;blockquote class="jive-quote"&gt;&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;"&gt;$ nmap 102.1.48.1.*&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;This will scan the network and spit back what it finds. The nmap utiplity reports that the device is connected to the network.&amp;nbsp; He’s scanning for devices that have SSH Open and there is only one device listed.&amp;nbsp; Before connecting to the IP address he’ll need to modify the default SSH. To do this he logs in as Pi and edits the SSH config so that he can login as root.&amp;nbsp; The reason he needs to login as root is so that he can remotely access files on the root directory.&amp;nbsp; He uses the following command:&lt;/p&gt;&lt;blockquote class="jive-quote"&gt;&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;"&gt;$ sudo nano /etc/ssh/sshd_config&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;He uncomments the option to permit root access.&amp;nbsp; Now that he’s modified the SSH config file, he’ll need to restart the SSH service:&lt;/p&gt;&lt;blockquote class="jive-quote"&gt;&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;"&gt;$ sudo systemctl restart ssh.service He’ll also $ sudo systemctl restart sshswitch.service&lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;Before logging in as root he’ll need to login as pi and set the password for root:&lt;/p&gt;&lt;blockquote class="jive-quote"&gt;&lt;p style="margin:0;"&gt;&lt;span style="color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;"&gt;$ sudo passwd root &lt;/span&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;Once this is done he logs back in as root. The reason he wants to login as root is so that he can use the dolphin file browser and transfer files to the root directory.&amp;nbsp; Once he logs in as Pi he goes to the boot directory and edits the config.txt file. You’ll need to do this in order to add some custom lines for the TFT screen.&amp;nbsp; The TFT screen is going to be driven by a device tree overlay.&amp;nbsp; You can find documentation on the device tree overlay at &lt;a class="jive-link-external-small" href="https://www.raspberrypi.org/documentation/configuration/device-tree.md" rel="nofollow ugc noopener" target="_blank"&gt;https://www.raspberrypi.org/documentation/configuration/device-tree.md&lt;/a&gt;.&amp;nbsp; There you can read up on device tree overlays and parameters.&amp;nbsp; The device tree overlay will be compiled in the boot directory.&amp;nbsp; On Felix’s local machine he’s able to login the Raspberry Pi over the fish protocol which uses SSH on the backend.&lt;/p&gt;&lt;p style="margin:0;margin-bottom:15px;color:#000000;font-family:&amp;#39;Open Sans&amp;#39;, Arial, sans-serif;text-align:left;"&gt;Since he’s logged in as root he can drag and edit files in the boot directory.&amp;nbsp; He drag over are the gpio-tft-16bit-565.dts which is the source file that once compiled will create the DT –blob.bin file. When the system boots the config.txt file has some configuration lines that refer to the DT –blob.bin file and that enables the Raspberry Pi to drive the TFT screen directly with the GPIO.&amp;nbsp;&amp;nbsp; Felix walks you through the process of setting that up. Once he’s copied the lines he needs he goes back into terminal to edit the config file.&amp;nbsp; At the bottom of the file he pastes the lines that he’s copied. He’s commented a compile script which he also drags over to the Pi. He compiles the DTS file and that produces a bin file.&amp;nbsp; The bin file tells the kernel, the operating system, and everything how to interface with the TFT screen over the GPIO.&amp;nbsp;&amp;nbsp; At this point you should be able to reboot the Raspberry Pi and the TFT screen should be working.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: dts file, sudo sergeant, terminal, tft screen, compile, gpio, rpibeginner, raspberry pi zero, ssh, raspberry pi, rpiexpert, retropie, boot, device tree overlay, sudo, sudosergeant, linux, man pages&lt;/div&gt;
</description></item></channel></rss>