Screen stuck on same text

My display is stuck on the same screen and not looping! Could someone help me with where am i going wrong? I use U8GLIB... Please correct the code below

#include <Keypad.h>
#include "U8glib.h"
U8GLIB_ST7920_128X64_4X u8g(13, 12, 11);

const byte numRows= 4;
const byte numCols= 4;
char keymap[numRows][numCols]= {
                                 {'1', '2', '3', 'A'}, 
                                 {'4', '5', '6', 'B'}, 
                                 {'7', '8', '9', 'C'},
                                 {'*', '0', '#', 'D'}
                               };
byte rowPins[numRows] = {3,4,5,6};
byte colPins[numCols] = {7,8,9,10};
Keypad mykeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
char Password=1*2*3;

void setup()
{

    u8g.firstPage ();  
      do{
          welcome ();
        } while( u8g.nextPage () );
    delay(3000);
      u8g.setColorIndex (1);
}

void welcome(void)
{
    u8g.setFont(u8g_font_fub17);
    u8g.setPrintPos(16, 25); 
    u8g.setColorIndex(1);
    u8g.drawBox(0,0,128,64);  
    u8g.setColorIndex(0);   
    u8g.print("Welcome!");
}

void authentication()
{
    char uauth;
    u8g.setFont(u8g_font_helvR08);
    u8g.setPrintPos(16, 25); 
    u8g.print("Please enter device");
    u8g.setPrintPos(20, 46); 
    u8g.print("PASSWORD");
    uauth = mykeypad.waitForKey();
    if (uauth=Password)
      {
           u8g.firstPage();  
           do{
               MainMenu();
             } while( u8g.nextPage() );
      }
    u8g.setFont(u8g_font_fub17);
    u8g.setPrintPos(16, 25); 
    u8g.print("Invalid Password");
}

void MainMenu(void)
{
    int MainOption;
    u8g.setFont(u8g_font_helvR08);
    u8g.setPrintPos(2, 25); 
    u8g.print("Choose the options below");
    u8g.setFont(u8g_font_fub17);
    u8g.setPrintPos(16, 25); 
    u8g.print(" 1. First Option");
    u8g.setPrintPos(16, 25); 
    u8g.print(" 2. Second Option");
    u8g.setPrintPos(16, 25); 
    u8g.print(" 3. Third Option");
    MainOption = mykeypad.getKey();
    if(MainOption=1)
    {
        u8g.setFont(u8g_font_unifont);
        u8g.setPrintPos(64, 32); 
        u8g.print(MainOption);
    }
    else if(MainOption=2)
    {
        u8g.setFont(u8g_font_unifont);
        u8g.setPrintPos(64, 32); 
        u8g.print(MainOption);      
    }
    else if(MainOption=3)
    {
        u8g.setFont(u8g_font_unifont);
        u8g.setPrintPos(64, 32); 
        u8g.print(MainOption);      
    }
    else
    {
        u8g.setFont(u8g_font_unifont);
        u8g.setPrintPos(20, 26); 
        u8g.print("Invalid choice...");      
        u8g.setPrintPos(26, 48); 
        u8g.print("Try again!");      
    }   
}    


void loop(void)
{
    u8g.firstPage ();  
      do{
          authentication ();
        } while( u8g.nextPage () );
}
  //delay(500);

i have attached the photos!

Saturday_03_January_2015 11_48_25snap.jpg

Saturday_03_January_2015 11_46_03snap.jpg

Hi

You already opend a thread here: "Help needed with new LCD display - Displays - Arduino Forum"

From the title of this thread, it seems that your programm only displays one screen and then does not proceed.

I see two problems:

  1. You confused the "=" with the "==" operator. "=" is assignment and "==" is the check for equality.
  2. You must not nest the picture loop. This must also be fixed.

As a general advice: Do no use nested function calls. Use a global state variable. I also strongly suggest to write a specification for your menus: What is displayed and which other menues can be reached from there.
Create one function (which might call other functions), which checks the global state and draws screens, based on the global state variable.

Oliver

i can't get the word " You must not nest the picture loop "

What is the proper way of displaying an output for every menu?
For eg; in functions welcome() and authentication() how to display the output?

Hi

nested picture loop:

Do not do this:

    u8g.firstPage ();  
      do{
       u8g.firstPage ();  
         do{
            ...
          } while( u8g.nextPage () );
        } while( u8g.nextPage () );

What is the proper way of displaying an output for every menu?

As suggested earlier: Create a global state variable. Based on this, draw the screen.
Still i suggest to create a specification for your menues.

Oliver

Really Excellent! Now everything makes a sense! :wink:
I will reply back once i see some progress! Thanks :wink:

ok,

Oliver

olikraus:
ok,

Oliver

I have put together all that you told me from that loop to ' == ' operator!
Thanks to you, now the screen successfully passed the first one!
Now i need to configure how to use waitForKey() function...
How do i make the program wait for the user to enter the required input?
what is the general way of wait for the user to enter input in Arduino, a
more like your Menu program in U8GLIB.....

Unfortunately i have no idea what "waitForKey()" does.

In general you should not wait, but just check regulary (poll) whether a key is pressed.
If such an event occurs, then you can change the output accordingly.

Oliver

I have already posted this same thread on programming section, but it seems that you can handle this easily!

Finally seeing some progress here!
And the answer for my question "How to make the program wait for user input" is
you have to use an event listener! and i was lucky enough to find out this!
Here is the coding i have developed after many trials and references!

#include <Password.h>
#include <Keypad.h>
#include "U8glib.h"
U8GLIB_ST7920_128X64_4X u8g(13,12,11);

Password password = Password( "1234" );
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = { 22,24,26,28 };
byte colPins[COLS] = { 30,32,34,36 };


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

void setup()
{
  keypad.addEventListener(keypadEvent);
  u8g.setFont(u8g_font_tpss);
  u8g.setColorIndex(1); 
  u8g.setPrintPos(16, 25); 
  u8g.firstPage ();  
      do{
  u8g.println("Please enter device");
  u8g.setPrintPos(37, 46); 
  u8g.println("PASSWORD");
        }while( u8g.nextPage () );
}

void loop()
{
  keypad.getKey();
}

void keypadEvent(KeypadEvent eKey)
{
  switch (keypad.getState())
  {
    case PRESSED:
  u8g.setFont(u8g_font_unifont);
  u8g.setPrintPos(0, 20);
  u8g.firstPage();  
  do {
      u8g.print("Pressed: ");
      u8g.println(eKey);
     } while( u8g.nextPage() );
  switch (eKey)
  {
  case '*': checkPassword(); break;
  case '#': password.reset(); break;
  default: password.append(eKey);
  }
  }
}

void checkPassword()
{
  if (password.evaluate())
  {
    u8g.setFont(u8g_font_unifont);
    u8g.setPrintPos(0, 20);
    u8g.firstPage();  
    do {
    u8g.setFont(u8g_font_fub17);
    u8g.setColorIndex(1);
    u8g.drawBox(0,0,128,64);  
    u8g.setColorIndex(0);   
    u8g.setPrintPos(16, 25); 
    u8g.print("Welcome");
    u8g.setPrintPos(20, 49); 
    u8g.print("user");
    } while( u8g.nextPage() );
    delay(1000);
    u8g.firstPage();  
    do {
    u8g.setFont(u8g_font_helvR08);
    u8g.setColorIndex(1);
    u8g.setPrintPos(2, 5); 
    u8g.print("Choose the options below");
    u8g.setFont(u8g_font_unifont);
    u8g.setPrintPos(16, 15); 
    u8g.print(" 1. option");
    u8g.setPrintPos(16, 30); 
    u8g.print(" 2. option");
    u8g.setPrintPos(16, 45); 
    u8g.print(" 3. option");
    }while( u8g.nextPage() );
  }
  else
  {
    u8g.setFont(u8g_font_unifont);
    u8g.setPrintPos(0, 20);
    u8g.firstPage();  
    do {
    u8g.println("Wrong");
       } while( u8g.nextPage() );
  }
}

And now i encounter a strange problem again!

  • What are these CR LF ?
  • Why do i get text continuously in "PASSWORDplease e"

Can you find any problem related to this error in my code above?
I have attached the output images of those errors....

I also acknowledged that ethernet shield with sd card has something to do with this! Is that true???
My setup is Arduino Mega 2560 attached with ethernet shield and then to keypad and ST7920 display...

err1.jpg

err2.jpg

Hi

Do not used u8g.println(). Just replace all u8g.println with u8g.print in your code.
println is there from the Arduino environment, but it is meaningles (or faulty) together with u8glib.

Oliver