LCD 16 X 2 Only shows white box on line 1 n 2 ( no text shown)

Hai sterretje n all, i just brought a new lcd that is 16 x 2 . I run the code and found that the lcd 16x2 only shown white box in line 1 and line 2 with no text shown... now i really sad, the lcd broken again coz i unable find lcd 20x4 in my hometown only got 16x2 ... IT IS BROKEN AGAIN...?? SAD ... what is the problem occurs again :( :( :(

later i will upload the picture of my connection and the code (previous used for lcd 20 x4), hopefully u all can finds error which i missed... thx u all ..... sincerely thank u ... kindly need ur all help.... thx

code

#include <LiquidCrystal.h>


#define HASKEYPAD
#define LCD20X4
#define LCD16x2

#define ST_DISPLAY_MAINMENU 0
#define ST_WAIT 1
#define ST_SETSPEED 2
#define ST_SETTIMING 3

// options to control the motor
#define MOTOR_CONTINUE 0
#define MOTOR_START 1
#define MOTOR_FORCESTOP 2

int motorPin =3 ;

#include <LiquidCrystal.h>;
#ifdef HASKEYPAD
#include <Keypad.h>;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

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

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#else
#define NO_KEY 0
#endif

// initialize the library with the numbers of the interface pins
#ifdef LCD20X4
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
#else
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
#endif


// the state of our application; start with main menu display
byte currentState = ST_DISPLAY_MAINMENU;

// speed and timing variables
// both are global so we can display them in the main menu
int theSpeed = 0;
long theTiming = 0;


void setup() {
  Serial.begin(9600);

  pinMode(motorPin, OUTPUT);
  // set up the LCD's number of columns and rows:
#ifdef LCD20X4
  lcd.begin(20, 4);
  Serial.println("20x4 display");
#else
  lcd.begin(16, 2);
  Serial.println("16x2 display");
#endif
}

void loop()
{
  // single key from keypad
  char key;
  // text from keypad
  char *text;

  // let the motor do what it was doing
  runMotor(MOTOR_CONTINUE);

  //Serial.print("Speed: "); Serial.println(theSpeed);

  switch (currentState)
  {
    case ST_DISPLAY_MAINMENU:
      // display main menu
      displayMenu();
      // switch to wait state
      currentState = ST_WAIT;
      break;
    case ST_WAIT:
      // get key
      key = getKeyWithEcho();
      // if speed setting selected
      if (key == '1')
      {
        // display speed 'menu'
        displaySpeedMenu();
        // change to state where user can enter speed
        currentState = ST_SETSPEED;
      }
      // if timing setting selected
      if (key == '2')
      {
        // display 'timing' menu
        displayTimingMenu();
        // change to state where user can enter timing
        currentState = ST_SETTIMING;
      }
      // Note: state does not change if entry is not '1' or '2'
      break;
    case ST_SETSPEED:
      // get the text entered on the keypad
      text = getKeypadText();
      // if text complete
      if (text != NULL)
      {
        // if user did enter a speed
        if (text[0] != '\0')
        {
          theSpeed = atoi(text);
        }
        currentState = ST_DISPLAY_MAINMENU;
      }
      break;
    case ST_SETTIMING:
      // get the text entered on the keypad
      text = getKeypadText();
      // if text complete
      if (text != NULL)
      {
        // if user did enter a speed
        if (text[0] != '\0')
        {
          theTiming = atoi(text);
          runMotor(MOTOR_START);
        }
        currentState = ST_DISPLAY_MAINMENU;
      }
      break;
  } // end_of_switch

}


/*
  display a title on the first line of the display; it always clears the LCD
*/
void displayTitle()
{
  // clear the lcd
  lcd.clear();

  // print the project title on the first line
  lcd.setCursor(0, 0);
  lcd.print("Speed Controller");
}

/*
  display main menu
*/
void displayMenu()
{
  // current line where to write on LCD; every time that we write, currentLine will be incremented
  byte currentLine = 0;
  // text buffer for 20 characters and string terminator
  char textbuffer[21];

  // display the title on the first line and update currentLine
  displayTitle();
  currentLine = 1;

  // print the current settings on the second line
  lcd.setCursor(0, currentLine++);
  sprintf(textbuffer, "S = %d, T = %d", theSpeed, theTiming);
  lcd.print(textbuffer);

#ifdef LCD20X4
  // print the first menu option on the third line
  lcd.setCursor(0, currentLine++);
  lcd.print("1 Set speed");

  // print the second menu option on the fourth line
  lcd.setCursor(0, currentLine++);
  lcd.print("2 Set time");
#endif
}

/*
  display a 'menu' where the user can enter a speed
*/
void displaySpeedMenu()
{
  // display the title on the 1st line
  displayTitle();
#ifdef LCD20X4
  // display additional info on 3rd line
  lcd.setCursor(0, 2);
  lcd.print("#Finish, *Cancel");
#endif
  // prompt user to set speed (2nd line)
  lcd.setCursor(0, 1);
  lcd.print("Set speed: ");
}

/*
  display a 'menu' where the user can enter a timing
*/
void displayTimingMenu()
{
  // display the title on the 1st line
  displayTitle();
#ifdef LCD20X4
  // display additional info on 3rd line
  lcd.setCursor(0, 2);
  lcd.print("#Finish, *Cancel");
#endif
  // prompt user to set speed (2nd line)
  lcd.setCursor(0, 1);
  lcd.print("Set time: ");
}

continues code

/*
  get a keystroke from the keypad
  echo the key that was pressed to the LCD
  the echo will be on the current position of the LCD
  returns
    the key that was pressed or NO_KEY
*/
char getKeyWithEcho()
{
  // read a key
#ifdef HASKEYPAD
  char key = keypad.getKey();
#else
  char key;
  if (Serial.available() > 0)
  {
    key = Serial.read();
  }
  else
  {
    key = NO_KEY;
  }

#endif
  // if no key pressed
  if (key != NO_KEY)
  {
    // for debugging, output to serial monitor
    Serial.print("Key: "); Serial.println(key);
    // display on current position of LCD
    lcd.print(key);
  }
  return key;
}

/*
  get a text from the keypad (max 20 characters)
  '#' finishes the entry of data
  '*' cancels the entry of data
  returns
    NULL if not complete
    empty text if canceled
    entered tet (might be empty)
*/
char *getKeypadText()
{
  // a buffer for 20 keypresses and one
  static char keypadbuffer[21];
  // index in above buffer
  static char index = 0;

  // read a key
  char key = getKeyWithEcho();
  // if nothing pressed
  if (key == NO_KEY)
  {
    // indicate no complete data
    return NULL;
  }
  // if 'cancel' key
  if (key == '*')
  {
    // reset index
    index = 0;
    // create empty text
    keypadbuffer[index] = '\0';
    // return text
    return keypadbuffer;
  }
  // if 'enter' key
  if (key == '#')
  {
    // add a string terminator
    keypadbuffer[index] = '\0';
    // reset index for next time
    index = 0;
    // return the text
    Serial.println(keypadbuffer);
    return keypadbuffer;
  }
  // check for buffer overflow
  if (index >= sizeof(keypadbuffer))
  {
    // add a string terminator
    keypadbuffer[sizeof(keypadbuffer) - 1] = '\0';
    // reset index for next time
    index = 0;
    // return the text
    return keypadbuffer;
  }

  // add the character to the buffer
  keypadbuffer[index++] = key;

  // indicate that text is not complete
  return NULL;
}


/*
  starts or stops the motor or runs the motor for a given time
  parameter
    option: option to control motor
    MOTOR_FORCESTOP: force an (emergency) stop; oberrides any other options
    MOTOR_START: if not started, start it; if already started, it's ignored
    for any other option value, motor keeps on doing what it was doing
*/
void runMotor(byte options)
{
  // the 'time' that the motor started running
  static unsigned long motorRunStarttime = 0;

  // if FORCESTOP received
  if ((options & MOTOR_FORCESTOP) == MOTOR_FORCESTOP)
  {
    // for debugging
    Serial.println("FORCESTOP received");
    // stop the motor
    analogWrite(motorPin, 0);
    // reset start 'time'
    motorRunStarttime = 0;
    // nothing more to do
    return;
  }

  // if START received and motor not started yet
  if ((options & MOTOR_START) == MOTOR_START && motorRunStarttime == 0)
  {
    // for debugging
    Serial.println("START received while motor was not running");
    Serial.print("Speed: "); Serial.println(theSpeed);
    Serial.print("Timing: "); Serial.println(theTiming);

    // set the start 'time'
    motorRunStarttime = millis();
    // display the start time
    Serial.print("Time: "); Serial.println(motorRunStarttime);
  }

  // if the motor has run for the specified duration
  if (millis() - motorRunStarttime >= (theTiming * 1000UL))
  {
    // inform the user that motor has stopped
    if (motorRunStarttime != 0)
    {
      Serial.println("Motor stopped");
      Serial.print("Time: "); Serial.println(millis());
    }
    // stop the motor;
    analogWrite(motorPin, 0);
    // reset the start 'time'
    motorRunStarttime = 0;
  }
  else
  {
    // set the motor speed
    if (theSpeed >= 0 && theSpeed <= 255)
    {
      analogWrite(motorPin, theSpeed);
    }
  }
}

Instead of trying a huge complicated program just run the Liquid Crystal HelloWorld program. Does it work ?

The all diagrams

dig 1.jpg

dig 2.jpg

ya, i try it ored... the output still be the same... i never pm someone for help...so u can no worry coz i not the kind that will disturd ppl ... thx

the new Lcd I brought broken again?! OMG....

what is the problem again if u guys look at my connection to arduino.... or my new lcd 16 x2 need other wiring connection with resistor with any pins i miss out.... thx

Hi,

just post the “Hello World” code which you tried as @UKHeliBob suggested.
And: the wiring …
Let’s get that work first and see if you really bought a broken one, what I don’t think.

In 90% of the cases the problem sits about 40cm in front of the PC display :wink:
(including me sometimes …)

In 90% of the cases the problem sits about 40cm in front of the PC display

Indeed. There have been many PEBKAC moments here over the years.

Hai rpt007, I try the code below… as suggested by UKHeliBob…

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print(" Help ");
  lcd.setCursor(0, 1);
  lcd.print(" Me ... T.T ");
}

In 90% of the cases the problem sits about 40cm in front of the PC display

what this mean?

and this

Indeed. There have been many PEBKAC moments here over the years.

PEBKAC

help me ... why this cant solved problem... i juz brought new lcd 16x2 to replace 20x4 for my project and now broken again.... :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :(

what really happen?

KIndly need all ur professional n helping hands..... :( :( :( :( :( :(

My dear, you are repeating what you said already, but don’t update with information what you did, what the reaction was etc.

Pls, again:

  1. show us exactly how you connected your LCD with Arduino (handwritten is ok)
  2. show us (in </> code tags) the sketch you have used for the test of the LCD

Without that you can’t expect that somebody would invest his/her precious (free) time, ok?

HI rpt007,… I already post it out… just cover up mu post of other comment

i will repost my code n photo

thx

 // include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.setCursor(0,0);
  lcd.print(" Help ");
  lcd.setCursor(0, 1);
  lcd.print(" Me ... T.T ");
}

void loop() {
 
}

dig 1.jpg

dig 2.jpg

I am convinced you have a wiring problem. I am running the code posted in #9 and just repeated in the previous post.

If I disconnect the power, open any one of the 4 data lines, and reconnect power I can duplicate your problem shown in LCD 16x2 white box.jpg. If I open RS, RW, or E it only shows one row of very white boxes.

The photographs are not clear enough for me to completely follow, but I think the connections look correct for the pins they are supposed to be going to. If you can post better photographs it would help.

My vote is for a broken wire, poor solder joint, bad bread board connection, etc.

Adjust the contrast pot until the rectangles are barely visible.

Check your wiring so it is similar to this:

Hi cattledog, below i attach more clearly photo to u for check my soldering and the wire …

thx u so much …

Do not use the same coloured wires for GND and +5v.

Crank the contrast pot down so the white rectangles just dissapear !

Edit Wire the back light as in the tutorial I posted.

.

HI LarryD, i try ur advise and change my lcd pins yet the output still the same.... what is the problem now? i try it out many test...

now i wait the answer from cattledog.

now i wait the answer from cattledog

Did you crank the contrast pot down?

Don't listen to advice then :smiling_imp:

.