raspberry pi lcd touch screen adafruit tutorial free sample

Hey guys, its Nick again, welcome to educ8s.tv a channel that is all about DIY electronics projects with Arduino, Raspberry Pi, ESP8266 and other popular boards. Today we are going to take a look at how to use the inexpensive, ILI9325 driver based, 2.8” touchscreen display designed for Arduino and at the end of this tutorial, you should be able to determine ifthis Touch Screen is a good option for your Arduino projects.

I first came across this touchscreen which offers a resolution of 320×240 pixels, and an easy to use micro SD slot among several other great features on banggood.com and decided to buy it for use in some of my projects since it was inexpensive as it only costs around $11.

As shown in the video above, we will be performing simple tasks with the display to demonstrate how it works such that, When we press a button on the screen, a message will be displayed it. This means we will learn both how to create a button on the screen such that it can be touched and how to display messages on the screen.

As demonstrated the touch screen is working fine! Finally, we can start building projects with a touch screen which are much more interesting and easier to use.

One of the few downsides to this display is that it uses almost all of the digital and analog pins of the Arduino Uno which means when using this shield, we are left with only 2 digital pins and 1 analog pin for connections to other components that the project we are building might require.

Fortunately, this display works fine with the Arduino Mega, so when working on projects with more pin requirements and size is not really an issue, we can use the Arduino Mega instead of the Arduino Uno. Unfortunately, this display does not work with some other Arduino Uno form factor based boards like the Arduino Due or the Wemos D1 ESP8266 board due to pin compatibility and library Issues.

In order to use this Arduino Touch Screen easily, we will need three libraries. We will need a modified version of the Adafruit TFTLCD library, the familiar Adafruit GFX library, and the Touchscreen library. All these libraries can be downloaded by following the links below.

With the Libraries installed, we can test the display by trying out the examples which came with the libraries. Two favorite examples are the graphicstext example and the tftbmp example whose demonstration can be seen in the tutorial video.

To explore the Touchscreen functionality of the display, I have developed a sample code, which you can extend for use in any of your projects. it can be downloaded via the download link below.

To use the touchscreen functionality of this display, there is a need for the display to be calibrated. To do this after uploading the code, Open the Serial Monitor and click (touch) on the top left corner of the display and write down the X and Y values displayed on the serial monitor. Then we edit the code to reflect those values. The X value goes to the TS_MAXX variable and the Y value goes to the TS_MAXY variable. We follow the same procedure for the other two variables. We click on the bottom right corner of the display and we enter the values we get in the TS_MINX and TS_MINY variables. With this done our display is now calibrated and ready for use.

Next, we declare the colors to be used with their hexadecimal values after which we create an object of the Adafruit TFTLCD library class indicating the variables used to represent the pins to which the screen is connected on the Arduino.

We start the function by initializing the serial monitor and the LCD, after which we set the orientation of the LCD and fill the screen with a black color to serve as the background.

Next, we draw a white frame on the display then set the cursor to the desired location, change the text color to white, and print the “Hello” text on the screen. By following the same procedure, we display the red YouTube text as well.

Next, we create the red youtube subscribe button. We do this by Creating a red rectangle and for our size requirements, we set the x and y pixel coordinates of the top left corner point of this rectangle to (60,180) after which we define the width for 200 pixels and the height as 40 pixels and  set the bottom right pixel coordinates of the rectangle to (260, 220). To make the rectangle look like a button, we then draw a similar white rectangle on the red rectangle and write the “subscribe” text on it.

With the setup function all done, we move to the loop function, the algorithm in operation for the loop section is simple, each time the user clicks on the screen, we convert the point coordinates of the touch point into pixels using the Map function. After conversion, If that point is inside the red rectangle area, it means that the user has pressed the button, so we disable the button by setting this variable to false and we clear the screen so as to display the “thank you for subscribing” message on the screen.

That’s it for today’s tutorial guys, thanks for reading/watching. If you get stuck at any point while building this project, feel free to reach out to me via the comment section, I will be glad to answer whatever questions you might have. Don’t forget to share, like and subscribe on youtube. Thanks!

raspberry pi lcd touch screen adafruit tutorial free sample

Is this not the cutest little display for the Raspberry Pi? It features a 2.8" display with 320x240 16-bit color pixels and a capacitive touch overlay. That"s right, instead of a resistive touchscreen, which requires a fingernail or stylus, you can now use a fingerpad.

This updated design fits perfectly onto the Pi Zero, Pi 3, Pi 2 or Model A+, B+! (Any Pi with a 2x20 connector) Not for use with an old Pi 1 with 2x13 connector. This version also has all 40 pins GPIO pins brought out so you can connect a 40-pin GPIO cable underneath.

The display and touchscreen uses the hardware I2C Pins (SDA & SCL), SPI pins (SCK, MOSI, MISO, CE0) as well as GPIO #25 and #24. All other GPIO are unused and you can still share the I2C pins with sensors, LED drivers, etc. Since we had a tiny bit of space, there"s 4 slim tactile switches wired to four GPIOs, that you can use if you want to make a basic user interface. For example, you can use one as a power on/off button.

Use it for console access or easily pop up X11 onto the PiTFT for a mini monitor, although its rather small at 320x240. Instead, we recommend using PyGame or other SDL-drawing programs to write onto the frame buffer.

Please note at this time the Pi Kernel we have does not come with support for built-in Pi 3 Bluetooth.There is no ETA when Adafruit will have this fixed.

raspberry pi lcd touch screen adafruit tutorial free sample

I"d love to use adafruit"s touch-tft for a project, but startx needs a lot of resources. Of course it would be cool to have the touch-functionality too.

be sure FRAMEBUFFER=/dev/fb1 startx is running correctly on the TFT screen, I have my TV plugged in the HDMI port, this way I can use the bash on the TV screen and run x on the TFT

You should now see a bouncing ball on your TFT while the HDMI output still displays the BASH on your TV (but it isn"t active of course) touching the screen will exit the game if you completed step 6

Why I"m doing this? This way you can display a simple GUI with e.g. buttons to do some action, like turn your lights on/off if you use your RPI for home-control.