Pages: [1]   Go Down
Author Topic: 20x4 LCD is only working on 16 cols and 3 rows  (Read 3604 times)
0 Members and 1 Guest are viewing this topic.
FL
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm new to arduino, but I totally love this thang.
Anyways...
I'm writing a sketch that generates a random glyph -- it randomizes the binary used to build a custom character and creates an "alien-esque" letter or glyph.
The code then plots the glyph from left to right on a 20x4 LCD, with the glyph being erased 5 positions back.
I hooked up my LCD by using the ladyada tutorial for the 16x2 LCD.
It.... works... but stops in the 16th column, and doesn't generate on the 4th row.
I tried changing a bunch of things but nothing seems to work.

In the sketch is this code:
   LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
Initializing the LCD as the tutorial instructs.

I also changed the lcd.begin to:
   lcd.begin(20,4);
thinking this would be right for a 20x4 display.

My guess is that either of these two are messing me up somehow.
But I can't figure out how. And it's driving me nuts.
Anyone out there care to  have a look and see what I'm doing wrong?
Or if there are any things that could be done in a more practical way?
The entire code for the sketch is below.
Again, I'm new, so please be kind!!!!!!!

/*
=================================================
           ALIEN TEXT ~ Corey Kingsbury
=================================================
Creates a random "glyph" and then displays it on LCD screen.
Notes: connect button to PIN 2.
*/
#include <LiquidCrystal.h>

String message="Press button to";
String message2="generate glyphs.";
int button=2;
int buttonState=0;
int buttonSave=0;
int theDelay=200;
int glyph=0;
int act=0; // btn action
int col=0; // column 1 position
int row=0; // row position
int lag=5; // delay before deletion
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // setup the LCD

void setup(){
  lcd.begin(20,4);
  pinMode(button, INPUT);
//  Serial.begin(9600);
}

void loop(){
  buttonCheck();
  if(act==2){
    resetB();
    makeGlyph();
  }

  if (act==0){
    displayMessage();
  }
}

/*============================
   ------- FUNCTIONS -------
============================*/
//------- button operations
void buttonCheck(){
  buttonState=digitalRead(button);
  if(buttonState!=buttonSave){
    resetA();
    act++;
    if(act>3){
      resetA();
      act=0;
    }
  }
  buttonSave=buttonState;
}

//------- create the glyph
void makeGlyph(){
  //-- generate it
  byte bin[] = {B00000,B10000,B10111,B10110,B10101,B11000,B11011,B11010,B11001,B11100,B11110,B11111,B01111,B00111,B00011,B00001,B00010,B01110,B10011,B01101,B01010,B00101,B10010,B10100,B11101,B01001,B01011,B10001,B00110,B01000,B00100,B01100};
  byte setupGlyph[8] = {bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],bin[random(31)],};
  glyph++;
  if(glyph>20){
    glyph=1;
  }
  lcd.createChar(glyph, setupGlyph);

  //-- position
  if(col>19){
    resetC();
  }
  row=random(3);
  lcd.setCursor(col, row);

  //-- write it
  lcd.write(glyph);
  delay(theDelay);
  col++;
}

//------- push the btn msg
void displayMessage(){
  lcd.setCursor(0,0);
  lcd.print(message);
  lcd.setCursor(0,1);
  lcd.print(message2);
}

//------- clear the LCD
void resetA(){
  lcd.clear();
  col=0;
  row=0;
}

void resetB(){
  lcd.setCursor(col-lag,0);
  lcd.print(" ");

  lcd.setCursor(col-lag,1);
  lcd.print(" ");

  lcd.setCursor(col-lag,2);
  lcd.print(" ");

  lcd.setCursor(col-lag,3);
  lcd.print(" ");
}

void resetC(){
  lcd.clear();
  col=0;
  row=0;
}
Logged

~zd~

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 515
Posts: 31567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

All LCDs implement non contiguous space. Your best bet is to carry on printing to it for much longer than 16 characters, say 40 or 80 and see when they start filling up the other lines.
Logged

FL
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply Grumpy Mike.
I increased the delete lag variable, and it made the glyphs go across all the way.
Well, they are wrapping.
Funny thing is when I change this variable back to 5, it stops at 16th col.
At least I have an idea of where the problem might be.
Another question if I may be so bold...
I have the glyphs being randomly named (with a random number from 0-32).
When I go over 32, it ignores the random glyph and just prints a normal character.
Any idea why this is?
Logged

~zd~

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 515
Posts: 31567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When I go over 32, it ignores the random glyph and just prints a normal character.
Not all the characters on an LCD are user definable, that is stored in RAM, the rest are fixed and stored in ROM.
Logged

FL
Offline Offline
Newbie
*
Karma: 0
Posts: 21
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ahh, I see...
Thanks for taking the time to answer, I appreciate it!
Logged

~zd~

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

Quote
All LCDs implement non contiguous space. Your best bet is to carry on printing to it for much longer than 16 characters, say 40 or 80 and see when they start filling up the other lines.
For more about this aspect follow the LCD Addressing link at http://web.alfredstate.edu/weimandn.  I suggest sending exactly 80 successive printable ASCII codes.  Follow the 'expanded ASCII chart' link at the same url to help with this part.

Quote
Not all the characters on an LCD are user definable, that is stored in RAM, the rest are fixed and stored in ROM.
More specifically, there are only 8 available locations for user definable characters in the CGRAM.  They are mapped into CGROM addresses 00 - 08 and can also be accessed with foldback (redundant) addresses 09 - 0F.  

Don
Logged

Pages: [1]   Go Up
Jump to: