arduino lcd screen tutorial made in china
In this Arduino touch screen tutorial we will learn how to use TFT LCD Touch Screen with Arduino. You can watch the following video or read the written tutorial below.
For this tutorial I composed three examples. The first example is distance measurement using ultrasonic sensor. The output from the sensor, or the distance is printed on the screen and using the touch screen we can select the units, either centimeters or inches.
The third example is a game. Actually it’s a replica of the popular Flappy Bird game for smartphones. We can play the game using the push button or even using the touch screen itself.
As an example I am using a 3.2” TFT Touch Screen in a combination with a TFT LCD Arduino Mega Shield. We need a shield because the TFT Touch screen works at 3.3V and the Arduino Mega outputs are 5 V. For the first example I have the HC-SR04 ultrasonic sensor, then for the second example an RGB LED with three resistors and a push button for the game example. Also I had to make a custom made pin header like this, by soldering pin headers and bend on of them so I could insert them in between the Arduino Board and the TFT Shield.
Here’s the circuit schematic. We will use the GND pin, the digital pins from 8 to 13, as well as the pin number 14. As the 5V pins are already used by the TFT Screen I will use the pin number 13 as VCC, by setting it right away high in the setup section of code.
I will use the UTFT and URTouch libraries made by Henning Karlsen. Here I would like to say thanks to him for the incredible work he has done. The libraries enable really easy use of the TFT Screens, and they work with many different TFT screens sizes, shields and controllers. You can download these libraries from his website, RinkyDinkElectronics.com and also find a lot of demo examples and detailed documentation of how to use them.
After we include the libraries we need to create UTFT and URTouch objects. The parameters of these objects depends on the model of the TFT Screen and Shield and these details can be also found in the documentation of the libraries.
Next we need to define the fonts that are coming with the libraries and also define some variables needed for the program. In the setup section we need to initiate the screen and the touch, define the pin modes for the connected sensor, the led and the button, and initially call the drawHomeSreen() custom function, which will draw the home screen of the program.
So now I will explain how we can make the home screen of the program. With the setBackColor() function we need to set the background color of the text, black one in our case. Then we need to set the color to white, set the big font and using the print() function, we will print the string “Arduino TFT Tutorial” at the center of the screen and 10 pixels down the Y – Axis of the screen. Next we will set the color to red and draw the red line below the text. After that we need to set the color back to white, and print the two other strings, “by HowToMechatronics.com” using the small font and “Select Example” using the big font.
Now we need to make the buttons functional so that when we press them they would send us to the appropriate example. In the setup section we set the character ‘0’ to the currentPage variable, which will indicate that we are at the home screen. So if that’s true, and if we press on the screen this if statement would become true and using these lines here we will get the X and Y coordinates where the screen has been pressed. If that’s the area that covers the first button we will call the drawDistanceSensor() custom function which will activate the distance sensor example. Also we will set the character ‘1’ to the variable currentPage which will indicate that we are at the first example. The drawFrame() custom function is used for highlighting the button when it’s pressed. The same procedure goes for the two other buttons.
So the drawDistanceSensor() custom function needs to be called only once when the button is pressed in order to draw all the graphics of this example in similar way as we described for the home screen. However, the getDistance() custom function needs to be called repeatedly in order to print the latest results of the distance measured by the sensor.
Here’s that function which uses the ultrasonic sensor to calculate the distance and print the values with SevenSegNum font in green color, either in centimeters or inches. If you need more details how the ultrasonic sensor works you can check my particular tutorialfor that. Back in the loop section we can see what happens when we press the select unit buttons as well as the back button.
Ok next is the RGB LED Control example. If we press the second button, the drawLedControl() custom function will be called only once for drawing the graphic of that example and the setLedColor() custom function will be repeatedly called. In this function we use the touch screen to set the values of the 3 sliders from 0 to 255. With the if statements we confine the area of each slider and get the X value of the slider. So the values of the X coordinate of each slider are from 38 to 310 pixels and we need to map these values into values from 0 to 255 which will be used as a PWM signal for lighting up the LED. If you need more details how the RGB LED works you can check my particular tutorialfor that. The rest of the code in this custom function is for drawing the sliders. Back in the loop section we only have the back button which also turns off the LED when pressed.
In order the code to work and compile you will have to include an addition “.c” file in the same directory with the Arduino sketch. This file is for the third game example and it’s a bitmap of the bird. For more details how this part of the code work you can check my particular tutorial. Here you can download that file:
I assume you mean the "New Liquidcrystal library" which is a replacement for, not an accessory to, the library that comes with the Arduino IDE. You must follow the installation instructions for this library which you can get here. I believe they also come packaged with the library. Basically you have to remove all traces of any other LiquidCrystal libraries for this one to compile.
I assume that you are referring to this ArduinoInfo page, and to the device he calls "I2C LCD DISPLAY VERSION 1:" That tutorial is actually the one I used when I was tinkering with my adapter which looks like that one and also came on a slow boat from the far east, Banggood in my case.
You also have to deal with the connections between the chip on the IC and the pins that go to the LCD module. These are specific to each pc board and the tutorial gives you the constructor that goes with each of the boards pictured. There is a "guesser" sketch available here if you want to go that route.
What you need is a "genuine" distributor that will provide correct data for the devices that they are selling. You might try Terry"s shop since he went to the trouble of producing that informative tutorial. He used to be a frequent contributor to this forum but I have a feeling he is staying away now to avoid any hint of a conflict of interest.
"C:\\Users\\David Prentice\\AppData\\Local\\Arduino15\\packages\\STM32\\tools\\arm-none-eabi-gcc\\6-2017-q2-update/bin/arm-none-eabi-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_687817/graphicstest.ino.elf"
I suspected the pinout. Got another LCD and used a loupe to see if I could find anything and well, there were numbering of pinout printed, and to my strange they were different from what on all documentation I found (and on link of Sparkfun on this LCD):
Now when I connect PIN1 to vcc 3.3v and PIN2 which must be RESET, to GND, the LCD turns on in pale blue. If at this time I connect the BL to anything from 3.3 to 6.5 nothing changes! Also nothing other than pale blue comes up at all.
Now if, say, Chinese printed wrong and pinout is the same, or say, they both printed pinout differently, and set up wiring differently as it is a copy LCD, then PIN 1 and 2 which I considered VCC and RESET are actually BL + and -, but well, connecting them to 6.5v, burns out the LCD! At the same time, connecting power to pin 9 and 10 if we suppose they are real BL + and - won"t change anything!
@Railroader Thanks for your advice, although I felt that it was a little patronising. But I guess that since the Arduino is primarily targeted at schoolchildren and for educational purposes, that"s a fair enough assumption of my age and career.
I am aware that there are better alternatives for screens that can be found for under £15. I was curious what was in a £15 quid projector and bought it for that reason. Disassembling it was fun and has already netted me lenses, heatsinks, and LEDs etc. for other projects which is worth more than its cost. The reason I asked was because a) I am loathe to bin the LCD and hence contribute to our electronic waste problems, and b) I am specifically looking for LEDs (most of the displays on eBay and Amazon are OLEDs) as I want to make an ESP32-controlled projector as a project. Non-OLEDs are difficult to find on eBay/Amazon nowadays. Hence I was asking on the off-chance that this screen might be similar to something else in Occidental part of the world that I could use.
From what you say it feels its very unlikely for there to be a shortcut and I"ll have decode the signals manually. Designing and manufacturing (or finding a 30 pin adapter) is not a problem but I can"t justify to myself spending the better part of my weekends in a month to decode the signals just to use it when I can spend £10 buying an SPI LCD from eBay which does the exact same thing. I"ll probably bite the bullet and do that.
Shame about having to bin the screen though. I have found the schematics for the GM8284DD chip and probably with a magnifying glass would be able to make out the LCD connections (RGB input etc.) on the circuit board but again, I"m not sure if its that cost-efficient spending that many weekends working on it...
I obtained the lib from their google code, put the ITDB02.h in my lib directory under Arduino hardware folder, and compiled the program there, and failed. I"ve got this error:
Next I copied the tutorial from the end of the same thread, and did as instructed there: "The code for 8 bit mode~ connect the DB9-DB16 to the Arduino D0-D7 . pull the DB1-DB8 to GND."
again failed: LCD is turned on, code compiled and uploaded, but nothing changes, a white screen. I"m sure the LCD is ok (I have two of them brand new, both have the same behavior).
Many of the newer devices have 16 pins, but two of them are for a backlight which really doesn"t have much to do with the LCD except to make it more visible. So what you are left with is the basic 14 pin interface that has been around for decades. Of those 14 pins two are used for power and one for contrast and they do not connect to your Arduino. So you are now left with an 11 pin interface. Three of those (RS, R/W, and E) are control lines but only two (RS and E) are essential - the R/W pin can be grounded without giving up much. This leaves a 10 pin interface of which 2 are control and 8 are data. The chip is capable of being used with only 4 data lines but the programming is more complicated than if all 8 are used. BUT if you are using a prewritten library, where someone else has done that complicated programming, there is really no reason not to use the 4-bit option. So the bottom line is that you need to use 6 I/O pins to interface your Arduino to a character mode LCD.
I don"t know much about librarys, used to run the screen, I have read there are different kinds of libraries and some are better than others... 4-bit, 8-bit...
The LiquidCrystal library provided with Arduino v0018 is the only library you need to use. It works with either the 4-bit or the 8-bit data interface and you can also connect the R/W line although the current library does not implement any of the features requiring this connection.
Just go to the tutorial in the playground (http://arduino.cc/en/Tutorial/LiquidCrystal), connect your LCD as shown, cut and paste the example code and you are on your way.
Many drawing and writing primitives are provided: single pixel plotting, lines, circles, triangles, rectangles (with square and rounded corners), and corresponding filled shapes. Text and numeric values, may be placed anywhere on the screen in a variety of sizes. Bitmapped shapes can be scrolled or moved about the screen and the whole screen can be rotated.
Points are defined by their Cartesian co-ordinates, (x, y). The origin (0, 0) is at the top left of the screen. Increasing the y value moves down the screen. The addressable dimensions of the SSD1306 screen are 128 pixels left to right (0, 1, 2, …, 127) and 64 pixels from top to bottom (0, 1, 2, …, 63). The pixel in the bottom right corner is (127, 63).
None of these instructions will produce a change on the screen without a display.display(); method. If your script does not appear to be working check you have included this line at the bottom of your screen changing code.
Since the use of an LCD requires many microcontroller pins, we will reduce that number using serial communication, which is basically sending "packages" of data one after another, using only two pins of our microcontroller , pins SDA and SCL which are the analog pins A4 and A5 of the Arduino NANO or pro mini.
First of all we connect i2c pins module as shown in the schematic. Power the LCD module to 5 volts and connect the ground as well. The SDA pin of the i2c module conected to arduinio A5 and the SCL pin to A4. We connect the arduino to USB and we are ready to program. In order to make the LCD work we need to inport the LCD library for arduino.
This post is an introduction to the Nextion display with the Arduino. We’re going to show you how to configure the display for the first time, download the needed resources, and how to integrate it with the Arduino UNO board. We’ll also make a simple graphical user interface to control the Arduino pins.
Nextion is a Human Machine Interface (HMI) solution. Nextion displays are resistive touchscreens that makes it easy to build a Graphical User Interface (GUI). It is a great solution to monitor and control processes, being mainly applied to IoT applications.
Connecting the Nextion display to the Arduino is very straightforward. You just need to make four connections: GND, RX, TX, and +5V. These pins are labeled at the back of your display, as shown in the figure below.
You can power up the Nextion display directly from the Arduino 5V pin, but it is not recommended. Working with insufficient power supply may damage the display. So, you should use an external power source. You should use a 5V/1A power adaptor with a micro USB cable. Along with your Nextion display, you’ll also receive a USB to 2 pin connector, useful to connect the power adaptor to the display.
The best way to get familiar with a new software and a new device is to make a project example. Here we’re going to create a user interface in the Nextion display to control the Arduino pins, and display data.
The user interface has two pages: one controls two LEDs connected to the Arduino pins, and the other shows data gathered from the DHT11 temperature and humidity sensor;
All components have an attribute called objname. This is the name of the component. Give good names to your components because you’ll need them later for the Arduino code. Also note that each component has one id number that is unique to that component in that page. The figure below shows the objname and id for the slider.
You should trigger an event for the touchable components (the buttons and the slider) so that the Arduino knows that a component was touched. You can trigger events when you press or when you release a component.
Notice that we have labels to hold the units like “ºC”, “ºF” and “%”, and empty labels that will be filled with the readings when we have our Arduino code running.
Once the GUI is ready, you need to write the Arduino code so that the Nextion can interact with the Arduino and vice-versa. Writing code to interact with the Nextion display is not straightforward for beginners, but it also isn’t as complicated as it may seem.
A good way to learn how to write code for the Arduino to interact with the Nextion display is to go to the examples folder in the Nextion library folder and explore. You should be able to copy and paste code to make the Arduino do what you want.
The first thing you should do is to take note of your components in the GUI that will interact with the Arduino and take note of their ID, names and page. Here’s a table of all the components the code will interact to (your components may have a different ID depending on the order you’ve added them to the GUI).
In this post we’ve introduced you to the Nextion display. We’ve also created a simple application user interface in the Nextion display to control the Arduino pins. The application built is just an example for you to understand how to interface different components with the Arduino – we hope you’ve found the instructions as well as the example provided useful.