Pages: [1]   Go Down
Author Topic: How to display many lines on lcd 16x2?  (Read 1804 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
New
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello..
I working to finishing my Arduino project name mathematics game and I have some trouble to display many lines on LCD display 16x2.
What should I do?
I want to display this.
Code:
lcd.setCursor(0, 1);
 
  char key = keypad.getKey();
  if (key != NO_KEY)
  {
    lcd.print(key);
    if (key == '*')
    {
      // When it picks up the "*" then it starts gathering the digits
      //delay(100);
      lcd.print("  **KIDS MATH");
      lcd.print(" QUIZ GAME!**");
      lcd.print("******MENU******");
      lcd.print("[1] Addition");
      lcd.print("[2] Subtraction");
      lcd.print("[3] Exit");
      lcd.print("Enter Your Choice: ");
     
      delay(2000);
      if (key == '1')
      {
        Addition();
      }
      else if (key == '2')
      {
        Subtraction();
      }
      else if (key == '3')
      {
        Exit();
      }
      else
      {
        lcd.print("Please Choose 1 or 2 or 3.");
      }
    }
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor

You need to change the line.

Cheers,
Kari


EDIT.
Please, provide the whole code. What parameters you have in the lcd.begin?
« Last Edit: March 14, 2011, 04:27:31 am by GaryP » Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 4324
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Please, provide the whole code. What parameters you have in the lcd.begin?
You will not be able to use anything except the first line of a 16x2 display if you do not have an lcd.begin() statement.  This is due to an unfortunate 'feature' of the Liquid Crystal library.

One of the parameters that has to be set up when initializing an LCD controller is the 'number of lines'.  Unfortunately the term 'lines' does NOT refer to  how many lines of characters there are on the physical display, it refers to how many lines of controller memory are used.  Virtually all LCD modules are configured to require the use of 2 lines of controller memory.  This includes the majority of 16x1 displays which internally are configured as 8x2.  When configured for the use of 1 line of controller memory nothing can be displayed on the right side of most 16x1 displays or on any except the first line of the multi-line displays.  Unfortunately the default configuration used by the LiquidCrystal library, unless overridden with an lcd.begin() statement, is to use 1 line of controller memory.

For more information about this follow the LCD Addressing link at http://web.alfredstate.edu/weimandn


Don
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don,
Feel free to educate me if I'm talking nonsense. Anytime.

How come this "easy" thing seems to create so much problems? Is it internal timing and too hurry programmer, or is it so that this is as good standard as RS-232 15-25 years ago? Everybody talks about how their staff is made by standards, but very often there were too many questions...

Cheers,
Kari
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 4324
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Feel free to educate me if I'm talking nonsense.
What you said about the lcd.begin was quite appropriate since he would get exactly the situation he described if the lcd.begin information was wrong or missing.

Quote
How come this "easy" thing seems to create so much problems? Is it internal timing and too hurry programmer
This is part of it.  The data sheet is not easy to follow and many (actually almost all) of the programs that I have seen published do not adhere to it properly.  Such programs will work with some/many/most LCD modules but will not work with all of them.

Quote
or is it so that this is as good standard as RS-232 15-25 years ago
That's a whole different story.  The RS-232 standard is fine when you use it as originally intended.  DTE <--> DCE <.......> DCE <---> DTE, where the dashes are local connections and the dots are the long distance connections.  The problems arise when DTE <--> DTE connections are implemented and/or where the handshaking is not fully implemented.  So the situation is not the same.  With the LCD modules the standard is inadvertently not being followed, with RS-232 it is deliberately not being followed.

The really amazing thing is how many people are successful with their Arduino projects considering the fact that so many of them do not have a technical background.  A lot of them seem to try, and succeed with, projects that no sane engineer would even attempt.

Don
« Last Edit: March 14, 2011, 02:33:54 pm by floresta » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
New
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here some of the whole code..
Code:
#include <Keypad.h>
#include <LiquidCrystal.h>


LiquidCrystal lcd(5, 4, 3, 2, 1, 0);

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

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

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


int answer;
int correct = 0;
int wrong = 0;

long i;
long j;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//NewSoftSerial mySerial = NewSoftSerial(14,15);  // Soft Serial naming of analog Pin1

void setup()
{
  lcd.print(16, 2);
  lcd.print("Welcome");  // Initial dispaly
  lcd.print("Press * to start");       
}

void loop()
{
  lcd.setCursor(0, 1);
 
  char key = keypad.getKey();
  if (key != NO_KEY)
  {
    lcd.print(key);
    if (key == '*')
    {
      // When it picks up the "*" then it starts gathering the digits
      //delay(100);
      lcd.print("  **KIDS MATH");
      lcd.print(" QUIZ GAME!**");
      lcd.print("******MENU******");
      lcd.print("[1] Addition");
      lcd.print("[2] Subtraction");
      lcd.print("[3] Exit");
      lcd.print("Enter Your Choice: ");
     
      delay(2000);
      if (key == '1')
      {
        Addition();
      }
      else if (key == '2')
      {
        Subtraction();
      }
      else if (key == '3')
      {
        Exit();
      }
      else
      {
        lcd.print("Please Choose 1 or 2 or 3.");
      }
    }
     
    else
    {
      lcd.print("please enter * to start");
    }
  }
}

void Addition()
{
  lcd.print(254, BYTE);
  delay(100);
  lcd.print(1,BYTE);
  delay(100);
 
  i = random(10);
  j = random(10);
 
  if ((i<=1 && j<=9) || (i<=9 && j<=1))
  {
    lcd.print("What is ");
    lcd.print(i);
    lcd.print(" + ");
    lcd.print(j);
    lcd.print(" = ");
    answer = i + j;
   
    char key = keypad.getKey();
    if (key != NO_KEY)
    {
      if (key == answer)
      {
        lcd.print("Great Job!!!");
        correct++;
      }
      else
      {
        lcd.print("Sorry.. ");
        lcd.print(i);
        lcd.print(" + ");
        lcd.print(j);
        lcd.print(" = ");
        lcd.print(answer);
        wrong++;
      }
      lcd.print("You got ");
      lcd.print(correct);
      lcd.print(" right and ");
      lcd.print(wrong);
    }
  }
 
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't see lcd.begin anywhere...

Cheers,
Kari
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 4324
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don't see lcd.begin anywhere...
Which is why only the first line works.  See the first sentence of reply #2.  He will also have to readjust his contrast after he adds the missing statement.

Don
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
New
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ops sorry..actually,
Code:
lcd.print(16,2)
is
Code:
lcd.begin(16,2)
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 4324
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We can't see your display so you will have to tell us if it works.

Don
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ops sorry..actually,
Code:
lcd.print(16,2)
is
Code:
lcd.begin(16,2)

Now that's a start! And then...?

Kari
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Port Elizabeth, South Africa
Offline Offline
Full Member
***
Karma: 3
Posts: 168
Life's to short to be an adult!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


The really amazing thing is how many people are successful with their Arduino projects considering the fact that so many of them do not have a technical background.  A lot of them seem to try, and succeed with, projects that no sane engineer would even attempt.

Don

That is by far the funniest comment I have ever heard on this forum or in the field of "engineered projects vs garden shed projects" mind you. Thanks floresta...I think your comment should be placed on the homepage of Arduino.cc so that everyone can get a true feel for what can be done.
Logged

"The really amazing thing is how many people are successful with their Arduino projects considering the fact that so many of them do not have a technical background.  A lot of them seem to try, and succeed with, projects that no sane engineer would even attempt." - floresta commenting on the proper use of LCD displays

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7197
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would suggest you use my phi_prompt library to display a menu. It automatically updates displays menu items as you press up and down to browse the menu and returns the item selected if you press OK. There's a lot more to it that you may want to use, like input a number, as you're making a math game.
There is also going to be features that will auto scroll contents that are too long.

here is a play list of most of its features:

http://www.youtube.com/view_play_list?p=B983E9145E4348FA
Logged


Pages: [1]   Go Up
Jump to: