Go Down

### Topic: How to display many lines on lcd 16x2? (Read 3343 times)previous topic - next topic

#### teddycute

##### Mar 14, 2011, 09:14 am
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: [Select]
`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.");      }    }`

#### GaryP

#1
##### Mar 14, 2011, 10:25 amLast Edit: Mar 14, 2011, 10:27 am by GaryP Reason: 1
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?
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

#### floresta

#2
##### Mar 14, 2011, 03:36 pm
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.

Don

#### GaryP

#3
##### Mar 14, 2011, 07:01 pm
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
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

#### floresta

#4
##### Mar 14, 2011, 08:31 pmLast Edit: Mar 14, 2011, 08:33 pm by floresta Reason: 1
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

#### teddycute

#5
##### Mar 14, 2011, 11:38 pm
here some of the whole code..
Code: [Select]
`#include <Keypad.h>#include <LiquidCrystal.h>LiquidCrystal lcd(5, 4, 3, 2, 1, 0);const byte ROWS = 4;  // four rowsconst byte COLS = 4;  // four columnschar 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 keypadbyte colPins[COLS] = {10, 11, 12, 13}; //connect to the column pinouts of the keypadint 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 Pin1void 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);    }  }  `

#### GaryP

#6
##### Mar 14, 2011, 11:46 pm
I don't see lcd.begin anywhere...

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

#### floresta

#7
##### Mar 15, 2011, 12:38 am
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

#### teddycute

#8
##### Mar 15, 2011, 11:51 pm
ops sorry..actually,
Code: [Select]
`lcd.print(16,2)` is
Code: [Select]
`lcd.begin(16,2)`

#### floresta

#9
##### Mar 16, 2011, 01:32 am
We can't see your display so you will have to tell us if it works.

Don

#### GaryP

#10
##### Mar 16, 2011, 07:54 am

ops sorry..actually,
Code: [Select]
`lcd.print(16,2)` is
Code: [Select]
`lcd.begin(16,2)`

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

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

#### fanjanc@gmail.com

#11
##### May 10, 2011, 11:04 pm

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.
"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

#### liuzengqiang

#12
##### May 11, 2011, 03:36 am
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: