Go Down

Topic: 3.2" LCD Display a Number enter from Numeric Keypad (Read 216 times) previous topic - next topic


Hello Forum
I am using arduino atmega2560 with non touch 3.2" 480*320 TFT LCD display interfaced with numeric keypad 4*4.
I have used following code to display the number enter through numeric keypad

#define LCD_CS A3
#define LCD_CD A2   
#define LCD_WR A1   
#define LCD_RD A0   

#define LCD_RESET A4

#define   BLACK           0x0000
#define   BLUE            0x001F
#define   RED             0xF800
#define   GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF

//#include "TFTLCD.h"
#include <Keypad.h>
#include <UTFT.h>
extern uint8_t SmallFont[];
const byte ROWS = 4;
const byte COLS = 4;
char buffer;
long lastUpdate = 0;
int x;

UTFT myGLCD(CTE32HR,38,39,40,41);

char keys[ROWS][COLS] =

byte rowPins[ROWS] = {6,7,8,9}; //connect to row pinouts
byte colPins[COLS] = {10,11,12,13}; //connect to column pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(void)
  Serial.println("8 Bit LCD test!");


void loop(void)
  char key = keypad.getKey();

  if (key != NO_KEY)
   delay(1000); */
  if((millis() - lastUpdate) > 100)  // has it been >1 second since the last update?
    testtext(BLACK);  // update display
    lastUpdate = millis();
  x=x+8;  // remember the time

//int y = (10*x);
// for TFT screen display letters
void testtext(uint16_t color)
// myGLCD.setCursor(50, 20);
// myGLCD.setTextColor(RED);
//  myGLCD.setTextSize(2);
  myGLCD.print("HI TEXTS BELOW" , CENTER ,10);
//  myGLCD.setCursor(x, 50);
// myGLCD.setTextSize(4);
  myGLCD.print(buffer , CENTER, 30);


But when I have enter the number from keypad  display is showing some junk value.
Please suggest how to display the correct number enter from keypad.


First off.   Tidy up your code.   Remove obsolete lines.   Indent it nicely. (ctrl-T)
Then copy-paste it into a CODE window.   (top left icon)

I guess that you should get an Error for  myGLCD.print(buffer , CENTER, 30);
At least there would be a Warning.

Read the UTFT documentation to see what methods are available for printing char[], char, integer, floats.
Life is easier if you choose intuitive names for variables.  e.g char letter, char buffer[], char *str, ...



Thanks David for your quick reply
I have tried with different printNumI  then it starts displaying its ASCII value, then I used ASCII to integer conversion function against it starts to display junk values. What could be a reasons?


May 18, 2017, 08:36 am Last Edit: May 18, 2017, 09:24 am by david_prentice
What do do want to display?  printNumI will show "65" for the letter 'A'
There does not appear to be method for displaying a single char.   Only for char[ ]

So you should write your char to strbuffer[0] and NUL to strbuffer[1]
Then you can display the one-letter string in buffer with print(strbuffer, x, y)

UTFT has unintuitive methods.   Hey-ho,   that is the library that you have chosen.
Even more confusing.   The method for showing a char[ ] or String is called print() instead of printString().

Most Arduino libraries inherit from Stream and Print classes.   So you are used to the idea of an overloaded Serial.print()  working for char, byte,  int, long, float, char[ ], String ...   It all appears to work by magic.   You have to study the docs for Stream, Print, ... to see what is available.

UTFT does not inherit from any other classes.   So if the method is not declared in UTFT.h it does not exist.
This makes life easy to understand.   You just have to get your head around the peculiar set of methods.


Edit.  While I was walking my dog,   I realised that you can convert anything to a String.   e.g. char letter;  ...   GLCD.print(String(letter));
I presume you are using a Mega.   So the extra bloat from String is no problem.



Hello Forum

A new problem is encountered in my project is as follow,

1.   I would like to display the numbers entered from numeric keypad in a sequential manner like what, it can be done with 16*2 LCD module. But here I am using 3.2" TFT LCD module , where I am not able to print all numbers enter from numeric keypad.

2.   Suggest some method of functions through which I can display all numbers sequentially appended by some character like Hz,KHz, MHz and so on.

3. We are making front panel for radio application though which entered frequency will be display over TFT LCD modules as well as at the same time value should print over serial port.

Go Up