0 Replies Latest reply on Jun 28, 2014 2:40 AM by matoo

    Interfacing keypad and TFT LCD with Arduino Uno


      Hi, i am new to arduino and i need some help on how to interface a 4x3 keypad and a TFT lcd with arduino uno. I want to display the values i pressed on the keypad to the lcd. Can someone help me with that?

      Here is my code:


      #include <Keypad.h>

      #include <TFT.h>

      #include <SPI.h>



      // pin definition for the Uno

      #define cs   10

      #define dc   9

      #define rst  8



      // create an instance of the library

      TFT TFTscreen = TFT(cs, dc, rst);

      // char array to print to the screen

      char sensorPrintout[4];



      const byte ROWS = 2; //four rows

      const byte COLS = 3; //three columns

      char keys[ROWS][COLS] = {




      byte rowPins[ROWS] = {2, 3}; //connect to the row pinouts of the keypad

      byte colPins[COLS] = {5, 6, 7}; //connect to the column pinouts of the keypad



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



      void setup(){


        // Put this line at the beginning of every sketch that uses the GLCD:


        // clear the screen with a black background

        TFTscreen.background(0, 0, 0);



        // write the static text to the screen

        // set the font color to white

        TFTscreen.stroke(255, 255, 255);

        // set the font size


        // write the text to the top left corner of the screen

        TFTscreen.text("Sensor Value :\n ", 0, 0);

        // ste the font size very large for the loop





      void loop(){

        char key = keypad.getKey();



        if (key != NO_KEY){




        // Read the value of the sensor on A0

        String sensorVal = String(analogRead(A2));



        // convert the reading to a char array

        sensorVal.toCharArray(sensorPrintout, 4);



        // set the font color

        TFTscreen.stroke(255, 255, 255);

        // print the sensor value

        TFTscreen.text(sensorPrintout, 0, 20);

        // wait for a moment


        // erase the text you just wrote

        TFTscreen.stroke(0, 0, 0);

        TFTscreen.text(sensorPrintout, 0, 20);