How to create a simple Touchscreen GUI || Arduino LCD & Touchscreen Tutorial

The Need for a Minimum of 16 Bits of Data to Set the Color for 1 Pixel

In order to set the color for one pixel, we need at least 16 bits of data. This means that our C code will require a minimum of 16 clock cycles to send over this data. On the other hand, if we are using an 8-bit interface, which requires 2 bytes per pixel, it would take 2 clock cycles. Alternatively, if we were to use a parallel interface with 16 bits, which would require only one clock cycle for each byte, it would be much faster. However, since we don't care too much about the frame rates when it comes to a graphical user interface, I initially wanted to use the serial interface as an example display because it is easy to hook up.

The Serial Interface: A Challenging Option

The problem with using the serial interface was that no matter how hard I tried, I could not get it to work correctly. The display would never warn me of any issues, which was truly frustrating. As a result, I decided to use the 8-bit parallel Tofu LCD as an alternative. This display is also easy to connect due to its shield form, but only leaves pin 5 unused on the Arduino Uno, which is not enough for most projects. For bigger projects, it is recommended to use an Arduino Mega.

The TFT LCD Library: A Convenient Solution

Once I opened up the datasheet of my LCD shield again, I realized that the while ring mentioned in the example sketch was actually referring to our own LCD shields. This was convenient because I only had to click upload and then enjoy the different appearing graphics on the LCD. The Adafruit library offers a couple of very handy functions that are essential for creating a graphical user interface. These include the fill screen, set cursor, text color, set Texas print line, and full rectangle functions.

Using the Adafruit Library

The color values needed for these functions require 16 bits each, which is a requirement for our LCD display. The rectangle function has x and y coordinates, pixel width and height, and of course a color value. It's worth noting that the zero comma zero pixel on the screen is in the top left corner, with the value increasing to 240 in the x-direction and 320 in the y-direction. With this knowledge, we can already create a black screen filled with two rectangles that state LED on and LED off.

Implementing Touchscreen Functionality

The LCD shield features a resistive touchscreen, which requires four wires connected to pins A1, A2, D6, and D7. These pins connect to a top resistive coating and a bottom resistive coating, whose connecting terminals are oriented in either the x-direction or y-direction. We can actually measure the resistance for these coatings through the pins and resistance is the keyword here because by powering them with 5 volts and grounds, we can then touch the display which connects the top and bottom layer and thus lets us measure the voltage of this x-direction voltage divider through one of the pins connected to an analog input. The same strategy can be applied to determine the Y point.

Using the Adafruit Touchscreen Code

Once again, we can utilize the Adafruit touchscreen codes as an example. We can use the TFT paint sketch, which only requires us to change the pins for our touchscreen and invert the minimum and maximum values for the x-direction and y-direction. Just like that, the TFT paint example works like a charm. However, you can always fine-tune the minimum and maximum values for the touchscreen using the serial monitor function of the code.

Implementing Touchscreen Functionality in Our Code

All we have to do now is check whether the x and y coordinates lace within the area of our rectangles and then either turn on or off an LED on pin A5. After uploading, you can see that by touching the corresponding rectangle, our LED turns on or off. Of course, you can get more creative when it comes to the design of the graphical user interface and also display sensor values if your project requires it.

WEBVTTKind: captionsLanguage: enwhen it comes to inputting and outputting information regarding my Arduino projects then I've always kept it a bit simple that means push buttons or rotary encoders for the inputs and in the best case an ordinary 16 by 2 LCD for the outputs but we live in the year 2018 and nowadays everyone including myself expects a colorful and shop LCD screen for the outputs and a touchscreen for the input thankfully though such LCD screens with touchscreen functionality - also exist for the Arduino we have a budget-friendly price point so in this video we will learn a bit about the theory of such TFT LCDs and resistive touchscreens and ultimately create an example GUI aka graphical user interface for Arduino projects let's get started this video is sponsored by JL CPCB upload your 'kappa files to get custom piece beasts easily their professional PCB production has the most competitive price in the world so feel free to test out their fast delivery and high quality PCBs today to offer a bit of right here I got myself a three slightly different 2.4 inch TFT LCDs with a resolution of 240 by 320 so to start off let's talk very briefly about the theory of such TFT LCDs also known as liquid crystal displays as the name suggests they consist of an array of liquid crystal segments and since our LCDs have resolution of 240 by 320 year we got a total of seventy six thousand eight hundred little crystal segments now controlling each segment individually it would be impossible due to the big number of them that is why the segment's split up a two-dimensional matrix with 240 rows and 320 columns this way we can control each one of them individually by multiplexing them and if you are scratching your head right now we're asking yourself what is multiplexing then make sure to watch my video about the subject anyway here now we can control all liquid crystal segments but what are we actually controlling of them well since those segments cannot emit light by themselves they get back light and all we can do is control a red green and blue filter in order to mix the color that we desire that means since we have to control the RGB values for each row we do not have 240 of them but 720 of them in stats to prove that I set a white image on one of the LCD screens and put it under my microscope which clearly showcases that each row consists of an our G and P pixel so what our microcontroller will later do is going through the segment rows and lines and setting the RGB values for each pixel in order to create the picture that we want to display now of course we could dive deeper into the theory with the different timing signals that such an LCD requires for now let's keep it simple and let's ask ourselves how the hell can we provide a total of 1040 control lines for the LCD with the Arduino well the answers we can't and we don't have to since such an LCD year is always built around in IC in this case the il i-93 you for one which is a TFT LCD a single chip driver and offers a total of 1278 pins by the way the datasheet of this ICU consists of 233 pages so if you bought one day then this could be an interesting reads but anyway what is important for us now is the ICS micro controller unit interface which supports parallel 8 9 16 and 18 bit data and a 3/4 serial line interface and this interface is actually the big difference between my 3 LCD boards the first one has a four wire serial interface with the serial data pins Syria clock chip selects and the data slash commands selection the second one cut an eight bits parallel interface with LCD d0 with two t7 and the third one cut a 16 bits parallel interface with DP 0 2 DB 15 so basically all the three displays can do the same but they all offer a different frame rate for example we need a minimum of 16 bits of data to set the color for 1 pixel which means our C will interface require 16 clock cycles to send over that data while the 8 bits per interface requires 2 clock cycles and the 16 bits parallel interface requires one clock cycle but since we do not care that much about the frame rates when it comes to a graphical user interface I initially wanted to use the serial interface as the example display because it is easy to hook up only problem was that no matter how hard I tried talking to this display it never warned to work correctly which was truly frustrating so as the alternative I will be using the 8 bits parallel T of T LCD which is also easy to connect due to its shield form but only Leafs the analog pin 5 unused on the Arduino Uno which is for most projects not really enough that is why I recommend using an Arduino mega for bigger projects but nevertheless the datasheet once again tells us what lines we have to pull high or low to read and write data and what sequence of bits we have to send over to control the color of each pixel but to decrease our workload I rather utilized the TFT LCD library from Adafruit after opening up its example sketch I realized that the while ring mentioned in the sketch is the same as our LCD shields which was convenient since I only had to click uploads and then enjoy the different appearing graphics on the LCD now the Adafruit library offers a couple of very handy functions of which the fill screen said cursor set text color set Texas print line and full rekts are the most important ones for our graphical user interface I think all of them are pretty self-explanatory but it is mentionable that the color values need to be 16 bits and the rectangle function has x and y star pixel a width and height value and of course a color value the zero comma zero pixel on the screen is in the top left corner and then the value increases to 240 and the x-direction and 320 in the y-direction and with this knowledge we can already create a black screen filled with two rectangles that state LED on and LED off all that is left to implement for this graphical user interface is the touch screen functionality this LCD shields features a resistive touchscreen were four wires which are connected to pin a1 a2 d6 and d7 those pins connect to a top resistive coating and a bottom resistive coating who's connecting terminals are oriented either in the y direction or X direction you can actually measure the resistance for those coatings through the pins and resistance is the keyword hue because by powering for example the expense will 5 volts and grounds we can then touch the display which connects the top and bottom layer and thus lets us measure the voltage of this x-direction voltage divider through one by pin that is connected to an analog inputs the same strategy can then be applied to determine the Y point which ultimately gives us the x and y coordinates of our touch point and to keep things simple once again we can utilize the Adafruit touchscreen codes as an example we can use the TFT paint sketch in which we only have to change the pins for our touch screen and invert the minimum and maximum values for the x-direction and just like that the TFT paint example works like a charm but you can always utilize the serial monitor function of the codes in order to fine tune the minimum and maximum values for the touchscreen in order to get even better results now all we have to do to implement the touchscreen functionality in our codes is to check whether the x and y coordinates lace in the area of our rectangles and then either turn on or off an LED on pin a5 and after uploading you can see that by touching the corresponding rectangle our LED turns on or off of course you can get more creative when it comes to the design of the graphical user interface and also display sensor values if your project requires it but for now you should be familiar with the basics of TFT LCDs and resistive touchscreens and you should be able to utilize them in on projects and as a reference you can also download my example sketches for which you can find the link in the video description below as always I hope you enjoyed this video and maybe even learnt something new if so don't forget to Like share and subscribe stay creative and I will see you next timewhen it comes to inputting and outputting information regarding my Arduino projects then I've always kept it a bit simple that means push buttons or rotary encoders for the inputs and in the best case an ordinary 16 by 2 LCD for the outputs but we live in the year 2018 and nowadays everyone including myself expects a colorful and shop LCD screen for the outputs and a touchscreen for the input thankfully though such LCD screens with touchscreen functionality - also exist for the Arduino we have a budget-friendly price point so in this video we will learn a bit about the theory of such TFT LCDs and resistive touchscreens and ultimately create an example GUI aka graphical user interface for Arduino projects let's get started this video is sponsored by JL CPCB upload your 'kappa files to get custom piece beasts easily their professional PCB production has the most competitive price in the world so feel free to test out their fast delivery and high quality PCBs today to offer a bit of right here I got myself a three slightly different 2.4 inch TFT LCDs with a resolution of 240 by 320 so to start off let's talk very briefly about the theory of such TFT LCDs also known as liquid crystal displays as the name suggests they consist of an array of liquid crystal segments and since our LCDs have resolution of 240 by 320 year we got a total of seventy six thousand eight hundred little crystal segments now controlling each segment individually it would be impossible due to the big number of them that is why the segment's split up a two-dimensional matrix with 240 rows and 320 columns this way we can control each one of them individually by multiplexing them and if you are scratching your head right now we're asking yourself what is multiplexing then make sure to watch my video about the subject anyway here now we can control all liquid crystal segments but what are we actually controlling of them well since those segments cannot emit light by themselves they get back light and all we can do is control a red green and blue filter in order to mix the color that we desire that means since we have to control the RGB values for each row we do not have 240 of them but 720 of them in stats to prove that I set a white image on one of the LCD screens and put it under my microscope which clearly showcases that each row consists of an our G and P pixel so what our microcontroller will later do is going through the segment rows and lines and setting the RGB values for each pixel in order to create the picture that we want to display now of course we could dive deeper into the theory with the different timing signals that such an LCD requires for now let's keep it simple and let's ask ourselves how the hell can we provide a total of 1040 control lines for the LCD with the Arduino well the answers we can't and we don't have to since such an LCD year is always built around in IC in this case the il i-93 you for one which is a TFT LCD a single chip driver and offers a total of 1278 pins by the way the datasheet of this ICU consists of 233 pages so if you bought one day then this could be an interesting reads but anyway what is important for us now is the ICS micro controller unit interface which supports parallel 8 9 16 and 18 bit data and a 3/4 serial line interface and this interface is actually the big difference between my 3 LCD boards the first one has a four wire serial interface with the serial data pins Syria clock chip selects and the data slash commands selection the second one cut an eight bits parallel interface with LCD d0 with two t7 and the third one cut a 16 bits parallel interface with DP 0 2 DB 15 so basically all the three displays can do the same but they all offer a different frame rate for example we need a minimum of 16 bits of data to set the color for 1 pixel which means our C will interface require 16 clock cycles to send over that data while the 8 bits per interface requires 2 clock cycles and the 16 bits parallel interface requires one clock cycle but since we do not care that much about the frame rates when it comes to a graphical user interface I initially wanted to use the serial interface as the example display because it is easy to hook up only problem was that no matter how hard I tried talking to this display it never warned to work correctly which was truly frustrating so as the alternative I will be using the 8 bits parallel T of T LCD which is also easy to connect due to its shield form but only Leafs the analog pin 5 unused on the Arduino Uno which is for most projects not really enough that is why I recommend using an Arduino mega for bigger projects but nevertheless the datasheet once again tells us what lines we have to pull high or low to read and write data and what sequence of bits we have to send over to control the color of each pixel but to decrease our workload I rather utilized the TFT LCD library from Adafruit after opening up its example sketch I realized that the while ring mentioned in the sketch is the same as our LCD shields which was convenient since I only had to click uploads and then enjoy the different appearing graphics on the LCD now the Adafruit library offers a couple of very handy functions of which the fill screen said cursor set text color set Texas print line and full rekts are the most important ones for our graphical user interface I think all of them are pretty self-explanatory but it is mentionable that the color values need to be 16 bits and the rectangle function has x and y star pixel a width and height value and of course a color value the zero comma zero pixel on the screen is in the top left corner and then the value increases to 240 and the x-direction and 320 in the y-direction and with this knowledge we can already create a black screen filled with two rectangles that state LED on and LED off all that is left to implement for this graphical user interface is the touch screen functionality this LCD shields features a resistive touchscreen were four wires which are connected to pin a1 a2 d6 and d7 those pins connect to a top resistive coating and a bottom resistive coating who's connecting terminals are oriented either in the y direction or X direction you can actually measure the resistance for those coatings through the pins and resistance is the keyword hue because by powering for example the expense will 5 volts and grounds we can then touch the display which connects the top and bottom layer and thus lets us measure the voltage of this x-direction voltage divider through one by pin that is connected to an analog inputs the same strategy can then be applied to determine the Y point which ultimately gives us the x and y coordinates of our touch point and to keep things simple once again we can utilize the Adafruit touchscreen codes as an example we can use the TFT paint sketch in which we only have to change the pins for our touch screen and invert the minimum and maximum values for the x-direction and just like that the TFT paint example works like a charm but you can always utilize the serial monitor function of the codes in order to fine tune the minimum and maximum values for the touchscreen in order to get even better results now all we have to do to implement the touchscreen functionality in our codes is to check whether the x and y coordinates lace in the area of our rectangles and then either turn on or off an LED on pin a5 and after uploading you can see that by touching the corresponding rectangle our LED turns on or off of course you can get more creative when it comes to the design of the graphical user interface and also display sensor values if your project requires it but for now you should be familiar with the basics of TFT LCDs and resistive touchscreens and you should be able to utilize them in on projects and as a reference you can also download my example sketches for which you can find the link in the video description below as always I hope you enjoyed this video and maybe even learnt something new if so don't forget to Like share and subscribe stay creative and I will see you next time