Arduino Mega HMI touch screen
Table of Contents
Description:
Arduino Mega HMI touch screen- In this tutorial, you will learn how to make an Arduino or Mega based HMI system using TFT LCD Touch Screen. This is an Introductory tutorial, in which we will be controlling an led and display the On the time of controller in seconds.
While in my Upcoming tutorials I will use this HMI touch screen for
- To display sensors data on this screen,
- I will interface this with the Neo 6M GPS module for making a real-time map tracking system.
- For controlling multiple loads
- I will also use this touch screen with the RFID for displaying the images.
we will also be using this with a fingerprint module for making a voting system. and so on.I will be using this touch screen in so many other projects. so Subscribe right now to my website and YouTube channel, so that you never miss any of my upcoming tutorials.
The HMI Touch screens are nowadays most commonly used in industries for control and monitoring. It eliminates the need for the hardware switches. Moreover, the HMI touch screen is easy to use. New functions can be added, the interface application can be modified at any time. Different pages can be designed for the control and monitoring of electrical machines and sensors.
In Industries the HMI touch screens are used with PLC’S and such HMIC touch screens are really expensive. So the purpose of this tutorial is to help you guys, how you can make your own HMI control system for the Arduino Mega using a 5 inch TFT touch screen. For the complete explanation, you can watch a video available at the end of this Article.
Amazon Links:
ITDB02 Arduino mega shield 2.1:
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
HMI Touch screen Breakout board soldering:
Breakout board for the touch screen
As you can see currently this module cannot be used with the output devices like for example relays, led’s, etc, for the external hardware interfacing we will need to make some changes, we will Solder some wires with the desired pins so that it can pass digital signals to the controlling circuit.
I started by soldering some jumper wires with the ground and other pins 13,12,11 and 10. After the Solder is has done then perform the short circuit test and make sure there is no solder bridge, also make sure you check the continuity of the jumper wires, sometimes the jumpers wires are broken inside. I am saying this from my practical experience because this has happened to me so many times.
This breakout board will be used with Mega. As you can see all the pin’s of the mega are occupied by the breakout board, so that’s why we had to solder jumper wires with the breakout. Now any sensor you want to use you will need to solder wires with the breakout board. So, for now, our HMI touch screen setup is completed.
Numbers images:
The following are the number of images that I used for displaying the numbers.
Arduino Mega HMI Programming:
Before you start the programming first of all make sure that you download all the necessary libraries. The functions used in this program are explained in the pdf files which you can download by clicking on the links given below.
Download: UTFT
Download: UTFT_Buttons
Download: 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); } |
I think other site proprietors should take this web site as an model, very clean and fantastic user genial style and design, as well as the content. You’re an expert in this topic!
One more thing I would like to state is that as an alternative to trying to suit all your online degree training on days that you complete work (considering that people are fatigued when they return home), try to obtain most of your classes on the week-ends and only a couple courses in weekdays, even if it means a little time off your end of the week. This is fantastic because on the weekends, you will be extra rested as well as concentrated upon school work. Many thanks for the different guidelines I have learned from your site.
I need a Arduino program for automatic Traffic signal.