Displaying the text from an input on a 2.8 tft display

Hey everyone, thanks for your help in advance!

I'm just looking for some advice:

I am working on a concept for a geocache and am stuck. I have been working on this for over a week off and on and am going around in circles. I have researched this extensively and have not been able to find a good solution.

I am using an Arduino Mega hooked up to a keypad and a 2.8 tft screen (http://www.seeedstudio.com/depot/28-TFT-Touch-Shield-p-864.html). The Arduino will then be plugged into a Raspberry Pi.

The basic concept will be:

The user inputs 4 different three digit codes into the key pad. Once the passwords are confirmed, the Arduino prompts the user for their 10 digit cell phone number. The number is then passed to the Raspberry pi, turns a pin on the GPIO to high, and a text message is sent to the user's phone.

I have gotten the TFT screen to display the instructions. I have gotten the keypad to work. When I attempt to combine the two codes, the instructions cycle within the loop statement.

I just tried the following and I know it looks like gibberish but I got the screen to stop cycling.

I have looked at the examples from keypad, password, tft, and many other libraries. But I have yet to find an example showing how to display an input from a keypad into a TFT screen.

How would you do this?

Thanks again for your time!

#include <Password.h>
#include <Keypad.h>
#include <stdint.h>
#include <TouchScreen.h> 
#include <TFT.h>

Password password = Password( "A123B456C789D000" );

const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns

// Define the Keymap
char keys[ROWS][COLS] = 
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = { 35,37,39,41 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 49,51,53,52, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

const int buttonPin = 7;
int buttonState = 0;


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


#ifdef SEEEDUINO
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 14   // can be a digital pin, this is A0
  #define XP 17   // can be a digital pin, this is A3 
#endif

#ifdef MEGA
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 54   // can be a digital pin, this is A0
  #define XP 57   // can be a digital pin, this is A3 
#endif 

void setup()
{
 
 Serial.begin(9600);
 keypad.addEventListener(keypadEvent); //add an event listener for this keypad
 keypad.setDebounceTime(250);  

}

void loop()
{
  
Tft.init();  //init TFT library
Tft.drawString("Geocache Instructions",0,0,1,RED);
userInputOne();
userInputTwo();
 
}

void keypadEvent(KeypadEvent eKey)
{
  Tft.init();
  switch (keypad.getState())
  {
    case PRESSED:
      Serial.print("Pressed: ");
      Serial.println(eKey);
        switch (eKey)
        {
          case '#': checkPassword(); break;
//        case '#': password.reset(); break;
//        default: password.append(eKey);
        }
  }
}

void checkPassword()
{
  if (password.evaluate())
  {
    Serial.println("Success");
    //Add code to run if it works
  }
  else
  {
    Serial.println("Wrong");
    //add code to run if it did not work
  }
}


void userInputOne()
{
  Tft.drawString("For the final coordinates:",0,20,1,WHITE);
  Tft.drawString("Press A followed by",0,30,1,WHITE);
  Tft.drawString("3 digit code from stage 1",0,40,1,WHITE);
//keypad.getKey();
  password.append(keypad.getKey());
  password.append(keypad.getKey());
  while(password.evaluate() == 0) 
  { 
    char eKey;
char keypadEvent(KeypadEvent eKey);
    Tft.drawChar(eKey,0,110,1,WHITE);
  } // do nothing
}

void userInputTwo()
{
  Tft.drawString("For the final coordinates:",0,20,1,WHITE);
  Tft.drawString("Press B followed by",0,30,1,WHITE);
  Tft.drawString("3 digit code from stage 2",0,40,1,WHITE);
  keypad.getKey();
}
 
void userInputThree()
{
  Tft.drawString("For the final coordinates:",0,20,1,WHITE);
  Tft.drawString("Press C followed by",0,30,1,WHITE);
  Tft.drawString("3 digit code from stage 3",0,40,1,WHITE);
  keypad.getKey();
}
 
void userInputFour()
{
  Tft.drawString("For the final coordinates:",0,20,1,WHITE);
  Tft.drawString("Press D followed by",0,30,1,WHITE);
  Tft.drawString("3 digit code from stage 4",0,40,1,WHITE);
  keypad.getKey();
}


void userInputCell()
{
  Tft.drawString("Please enter your ",0,200,1,WHITE);
  Tft.drawString("10 digit cellphone number",0,210,1,WHITE); 
  keypad.getKey();
}

slashmarx:
I am working on a concept for a geocache and am stuck. I have been working on this for over a week off and on and am going around in circles.

I am sorry! I just couldn't resist...... But if you been going round in circles for the past week, perhaps you need a new gps? :stuck_out_tongue_closed_eyes: :stuck_out_tongue_closed_eyes:

Could you show the 2 pieces of code that work? Maybe that would help to show where the problem might be.

Personally, I don't have a 4x4 keypad to actually test this, so will need a bit more help with specifics. Like exactly what do you mean by

When I attempt to combine the two codes, the instructions cycle within the loop statement.

All instructions in loop are SUPPOSED to cycle! Am I misunderstanding something here?

For what it's worth, I thought your gibberish was well laid out :stuck_out_tongue:

My first comment would be, your

void userInputOne()

routine doesn't make much sense, it will never exit!? I am assuming you only did that for test purposes? So can you explain better exactly where you are having the problems?

Regards,

Graham

ghlawrence2000 - thank you and sorry for the delayed response!

Ironically enough, I had 2 of my GPS units stolen this year, maybe that IS part of the issue...

I decided to start from scratch with an LCD shield instead of the TFT display. Once I get the LCD working then I'll work on adding the TFT back into the equation.

As far as the looping was concerned I realized that the Tft.init() was clearing the screen which was causing the looping issue I had.

Once I get the guts of the program working and am ready to add the TFT back in, I'll update this post.

Thanks again!

Chris