Arduino Mega HMI touch screen calibration and programming
Description:
In this project, we will learn how to use the TFT LCD Touch Screen to create an Arduino or Mega based HMI system. This is a very basic tutorial in which we will control a led and display in seconds the On Controller Time.
While I’m using this HMI touch screen in my upcoming tutorials
- To view data from sensors on this screen
- To make a real-time map tracking system, I will integrate this with the Neo 6 M GPS unit.
- To manage multiple loads
- I’m also going to use this RFID touch screen to display images.
We will use this with the fingerprint module to create a voting system for our upcoming tutorial. And so on and so forth. In so many other things I’m going to use this touch screen. So sign up for my website and YouTube channel right now, so you’ll never miss any of my upcoming tutorials.
Nowadays, the HMI Touch screens are most commonly used in the control and monitoring industries. This removes the need to change hardware. In addition, it’s easy to use the HMI touch screen. It is possible to add new functions, the interface configuration can be changed at any time. Specific pages can be configured for electrical device or sensor control and monitoring.
The HMI touch screens are used with PLC ‘S in Industries and such HMIC touch screens are expensive. The aim of this tutorial is to support you guys, how you can use a 5-inch TFT touch screen to build your own HMI control system for the Arduino Mega.
The Amazon Purchase links are given below:
ITDB02 Arduino mega shield 2.1: https://amzn.to/2T3quE9
7 Inch TFT LCD Touch Screen: https://amzn.to/35r6Fcl
Arduino Uno: https://amzn.to/39aq6ZT
Mega 2560: https://amzn.to/2SszMsI
lm7805 Voltage Regulator: https://amzn.to/2ERYoTJ
330-ohm resistors pack: https://amzn.to/2Qj1Igg
female DC power jack socket: https://amzn.to/377Pg9M
470uf capacitors: https://amzn.to/2MrN3xR
5×7 cm Vero board: https://amzn.to/37b7KWO
female headers: https://amzn.to/350w6RE
connection wires: https://amzn.to/2MvOJXd
Super Starter kit for Beginners: https://amzn.to/398dliF
Jumper Wires: https://amzn.to/2SrnBwo
Bread Board: https://amzn.to/2MxV5FM
12v Adaptor: https://amzn.to/2MuOlZk
PCB plate: https://amzn.to/2MuwNMB
Variable Supply: https://amzn.to/39d0KdP
Digital Multimeter: https://amzn.to/34WbVoa
Vero Board / stripboard: https://amzn.to/39nL9Zg
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2PVwexF
Solder wire: https://amzn.to/2QlOvTS
Wire Stripper: https://amzn.to/353tYJa
wirecutter: https://amzn.to/2tV2lFj
PCB small portable drill machine: https://amzn.to/2MvQqnx
DISCLAIMER:
Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
HMI Touch screen Breakout board soldering:
Touch screen break-out board
As you can currently see, this module can not be used with output devices such as relays, led’s, etc. We will have to make some changes for external hardware interfacing, we must solder some wires with the appropriate pins so that electronic signals can be transferred to the controlling circuit.
I started by soldering with the ground some jumper wires and 13,12,11 and 10 pins. After the solder is done, carry out the short circuit test and ensure that there is no soldering bridge. Also check the continuity of the jumper wires, sometimes the wires are broken inside the jumper wires. I say this from my practical experience, because so many times this has happened to me.
It will use this breakout board with Mega. As you can see, the breakout board occupies all the pin’s of the mega, so that’s why we had to solder the breakout jumper wires. Now, with the breakout board, any sensor you want to use will need to solder wires. So, our HMI touch screen setup is finished for now.
Numbers images:
The following is the number of pictures I used to show the numbers.
HMI TOUCH SCREEN Programming:
First of all, make sure you download all the necessary libraries before you start the programming. The functions used in this program are explained in the downloadable pdf files by clicking on the links below.
Download: UTFT: UTFT
Download: UTFT_Buttons: UTFT_Buttons
Download: UTouch: UTouch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
#include <UTouch.h> #include <UTouchCD.h> #define TOUCH_ORIENTATION LANDSCAPE #include <UTFT_Buttons.h> #include <UTFT.h> extern uint8_t SmallFont[]; extern uint8_t BigFont[]; extern uint8_t SevenSegNumFont[]; int button1on = 0; // USED AS A FLAG int x, y; int led=13; char stCurrent[20]=""; int stCurrentLen=0; char stLast[20]=""; // variables for displaying seconds // Interval is how long we wait // add const if this should never change int interval= 1 ; // in secs // Tracks the time since last event fired unsigned long previousMillis=0; int previoussecs = 0; int currentsecs = 0; int bg[] = { 0, 0, 255}; int fg[] = { 255, 255, 255}; UTFT myGLCD(ITDB50, 38,39,40,41); // Remember to change the model parameter to suit your display module! UTouch myTouch(6,5,4,3,2); // Finally we set up UTFT_Buttons :) void drawButtons() { // Draw the upper row of buttons myGLCD.setColor(bg[0], bg[1], bg[2]); myGLCD.fillRoundRect (90, 180, 220, 230); myGLCD.setColor(fg[0], fg[1], fg[2]); myGLCD.drawRoundRect (90, 180, 220, 230); myGLCD.print(" ON", 115, 195); myGLCD.setBackColor (0, 0, 0); myTouch.InitTouch(); myTouch.setPrecision(PREC_MEDIUM); } void setup() { int led=13; Serial.begin(9600); pinMode(led,OUTPUT); // Initial setup myGLCD.InitLCD(); myGLCD.clrScr(); myTouch.InitTouch(); myTouch.setPrecision(PREC_MEDIUM); myGLCD.setFont(BigFont); myGLCD.setBackColor(0, 0, 255); drawButtons(); } void loop() { while (true) { if (myTouch.dataAvailable()) { myTouch.read(); x=myTouch.getX(); y=myTouch.getY(); if ((x>=90 && x<=220 && y >=180 && y<=230)&&(button1on == 0) ) // Button: Enter { waitForIt(90, 180, 220, 230); myGLCD.setColor(bg[0], bg[1], bg[2]); myGLCD.fillRoundRect (90, 180, 220, 230); myGLCD.setColor(fg[0], fg[1], fg[2]); myGLCD.drawRoundRect (90, 180, 220, 230); myGLCD.print(" OFF", 115, 195); myGLCD.setBackColor (0, 0, 0); Serial.println("ON"); digitalWrite(led,HIGH); button1on = 1; x=0; y=0; delay(1000); } if ((x>=90 && x<=220 && y >=180 && y<=230)&&(button1on == 1) ) // Button: Enter { waitForIt(90, 180, 220, 230); myGLCD.setColor(bg[0], bg[1], bg[2]); myGLCD.fillRoundRect (90, 180, 220, 230); myGLCD.setColor(fg[0], fg[1], fg[2]); myGLCD.drawRoundRect (90, 180, 220, 230); myGLCD.print(" ON", 115, 195); myGLCD.setBackColor (0, 0, 0); Serial.println("off"); digitalWrite(led,LOW); button1on = 0; x=0; y=0; delay(1000); } } // Get snapshot of time unsigned long currentMillis = millis(); currentsecs = currentMillis / 1000; // How much time has passed, accounting for rollover with subtraction! if ((unsigned long)(currentsecs - previoussecs) >= interval) { // It's time to do something! myGLCD.setColor(fg[0], fg[255], fg[0]); // set font color myGLCD.setFont(SevenSegNumFont); myGLCD.printNumI(currentsecs, CENTER, 300); // write code here for anything you want to control on //timely basis // Use the snapshot to set track time until next event previoussecs = currentsecs; } myGLCD.setColor(fg[0], fg[0], fg[255]); // set font color myGLCD.setFont(BigFont); myGLCD.print("Electronic Clinic", CENTER, 400); } } void waitForIt(int x1, int y1, int x2, int y2) { myGLCD.setColor(255, 0, 0); myGLCD.drawRoundRect (x1, y1, x2, y2); while (myTouch.dataAvailable()){ } delay(20); // list all files in the card with date and size myGLCD.setColor(fg[0], fg[1], fg[2]); myGLCD.drawRoundRect (x1, y1, x2, y2); } |