Problem with sainsmart 1602 shield and interpreting the error code.

I am very new to Arduino and very rusty as regards C.

From this example sketch:

```
http://arduino.cc/en/Tutorial/LiquidCrystalBlink

*/

// include the library code:

#include <LCDKeypad.h>
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // Turn off the blinking cursor:
  lcd.noBlink();
  delay(3000);
  // Turn on the blinking cursor:
  lcd.blink();
  delay(3000);
}
```

I get this error:

In file included from Blink.ino:43:
C:\Users\seb\Documents\Arduino\libraries\LCDKeypad/LCDKeypad.h:18: error: expected class-name before '{' token

Looking for some guidance, please!

Remove the */ at the beginning of the code and the code compiles fine!! Good luck!!

I removed the */ and the code compiled OK!

My bad, I omitted some of the code:

/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */
#include <LCDKeypad.h>
// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

The compilation results and the error enlarged:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal C:\Users\seb\AppData\Local\Temp\build5415396205240828246.tmp\HelloWorld.cpp -o C:\Users\seb\AppData\Local\Temp\build5415396205240828246.tmp\HelloWorld.cpp.o

In file included from HelloWorld.ino:37:
C:\Program Files (x86)\Arduino\libraries\LiquidCrystal/LCDKeypad.h:18: error: expected class-name before '{' token

Why is this

#include <LCDKeypad.h>

included? It's not in the tutorial.

According to sainsmart, that library is required for their display shield to work.

Trying to compile this code without it brings many more errors.

The list exceeds the 9500 character posting limit.

seb21051:
According to sainsmart, that library is required for their display shield to work.

Trying to compile this code without it brings many more errors.

The list exceeds the 9500 character posting limit.

Why don't you post a link to the information about your specific device? From the clues you have given us this is likely to be some sort of LCD / Keypad shield but we really don't know for sure which one.

Don

Well, thanks for not posting all those errors. Don is right, it will sure help if you provide a link to the information you're citing.

If you follow the link in your program's comments http://www.arduino.cc/en/Tutorial/LiquidCrystal you'll see that the line I asked about is not in the original program.

Without the LCDKeypad.h, your code compiles fine for me. Dennis Miller says it compiles fine for him even with the LCDKeyPad reference - he must have that library installed. In any case, the only object you create is "lcd" and it is defined as an LIquidCrystal type from the LiquidCrystal library. Your program (as posted) does not use the LCDKeypad library.

Is it possible that by including LCDKeypad.h you're masking all those other errors? Meaning that getting fewer error message might look better to you but it's not. Do those millions of errors include ones about LiquidCrystal not found or not naming a type?

Apologies for taking up so much of your time unnecessarily! That is certainly not the intent.

So, here is the Sainsmart 1602 LCD Shield reference page with the link to its software:

Remove the 0 from the end of the link to find the sainsmart web page.

When you get this to compile, you will need to change the lcd constructor to LiquidCrystal lcd(8, 9, 4, 5, 6, 7) because that is the way the pins on the shield are configured to the lcd.

This is a common shield, and is similar to others with the Right push button label Rigth.

You do not need the LCDKeypad.h to get this running. That library is very simple and basically gives the analog read values for each button. You will learn more if you do not even use this library. You can use analog read to find the values for your actual shield and program the button selection accordingly.

Are you using the LiquidCrystal.h library which came with the IDE, or are you using something you downloaded.

I looked at that page but I don't see where your program came from. I didn't find it in the "Sample Code Download" and "Example Arduino sketch" is for an I2C 20x4 LCD. I'm not sure why Sainsmart thinks this example sketch has anything to do with a 4Bit mode parallel 16 by 2 display. Can you provide a link to your program?

According to sainsmart, that library is required for their display shield to work.

I couldn't find this, either.

Don't give up. You'll get it working.

Ok, thanks for the help so far.

I should go back and summarise the sequence of what I have done so far.
My description implies some shortcuts that would take overly long to document.

  1. This is where I started, downloading the software, installing it and getting the UNO board to work blinking the L led.
  1. Then I mounted the SainSmart keypadLCD Shield on the board, and tried to run the LiquidDisplay example "Blink"

  2. When I compiled the code, errors abounded, so I started looking for answers, by going to Sainsmart's product page.

http://www.sainsmart.com/sainsmart-1602-lcd-keypad-shield-for-arduino-duemilanove-uno-mega2560-mega1280.html#customer-reviews

  1. The product page gave me the example and library code, which I downloaded as keypad_lcd.zip , unzipped and picked the \keypad_lcd\LCD1602for_023\lcdkeypad folder and dropped it into the "Libraries" folder, and tried again, after including <lcdkeypad.h> in the "Blink." sketch, and making the corrections as detailed below. The errors reduced considerably.

I also found this in one of the product reviews:

To get the demo code to work, you need to replace
#include "WProgram.h"
with
#include "Arduino.h"
as that has now been updated, and as someone else mentioned this shield uses different pins from most others so you need to change
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
to
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

  1. From CattleDog:

Remove the 0 from the end of the link to find the sainsmart web page - DONE
When you get this to compile, you will need to change the lcd constructor to LiquidCrystal lcd(8, 9, 4, 5, 6, 7) because that is the way the pins on the shield are configured to the lcd. - DONE
This is a common shield, and is similar to others with the Right push button label Rigth. - OK - HANDY TO KNOW WHEN I GET THAT FAR.
You do not need the LCDKeypad.h to get this running. That library is very simple and basically gives the analog read values for each button. You will learn more if you do not even use this library. You can use analog read to find the values for your actual shield and program the button selection accordingly. - YOU'VE LOST ME, I JUST WANT TO GET THIS SHIELD TO BLINK.
Are you using the LiquidCrystal.h library which came with the IDE, or are you using something you downloaded - SOURCE IS GIVEN ABOVE.

Latest version of my modified "Blink" Code, with the compilation results:

/*
  LiquidCrystal Library - Blink
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the 
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD and makes the 
 cursor block blink.
 
 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
   * ends to +5V and ground
   * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe 
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/LiquidCrystalBlink
 
 */
#include <Arduino.h>

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

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // Turn off the blinking cursor:
  lcd.noBlink();
  delay(3000);
   // Turn on the blinking cursor:
  lcd.blink();
  delay(3000);
}

Results:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\standard -IC:\Program Files (x86)\Arduino\libraries\LCDKeypad -IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal C:\Users\seb\AppData\Local\Temp\build2937333908715505494.tmp\Blink_V1.cpp -o C:\Users\seb\AppData\Local\Temp\build2937333908715505494.tmp\Blink_V1.cpp.o
In file included from Blink_V1.ino:42:
C:\Program Files (x86)\Arduino\libraries\LCDKeypad/LCDKeypad.h:18: error: expected class-name before '{' token

Hopefully it gives the cognoscenti a clearer picture of my problem.

#include <LCDKeypad.h>

This is not needed for the sketch. Which libraries folder did you put it in? There are two libraries folders. One of them is in Program files x86/Arduino/Libraries and the other is under Users/you/MyDocuments/Arduino/libraries.

For now, take the library out of the folder it is in and place it some where else, like on the desktop. Delete the #include LCDKeypad.h, and let us know what you see when you compile the sketch.

/*
LiquidCrystal Library - Hello World

Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.

This sketch prints "Hello World!" to the LCD
and shows the time.

The circuit:

  • LCD RS pin to digital pin 12
  • LCD Enable pin to digital pin 11
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • LCD R/W pin to ground
  • 10K resistor:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)

Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe

This example code is in the public domain.

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

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}``

I also tried your latest code on a Sainsmart Mega 2560 with a Sainsmart 1602 lCD display, and "hello world!" with a blink, blink,blink, blink then a long off, blinking cursor is diplayed.

Does the LCD work fine with another board?

Dennis Miller:

The original poster refuses to believe that he doesn't need "#include <LCDKeypad.h>"

You've said twice that you've verified his code works and I'm sure he appreciates your help but you've failed to mention that you removed the reference to LCDKeypad.h that he doesn't need. It would help if you noted that you removed this library and then compiled the program.

@Dennis
You have to highlight the material that is code before you use the '#' code button.

Don

Hi guys, thanks for the help so far.

More and more I get the impression that I have a path problem, with multiple locations of libraries, etc.

I shall uninstall everything related to Arduino, and start again, or even do it on another PC, then report back.

Again, thanks!

Success! I cleaned everything out, then reinstalled the software.

Replaced the pin designations (LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

And Voila - Hello World!

Thanks, Guys!

Right, now that the LCD works,

what do I do to get the keypad to work . . .

Not to worry, I found this example on the DF Robot site that works:

This example will test the LCD panel and the buttons.When you push the button on the shield?the screen will show the corresponding one.
Connection: Plug the LCD Keypad to the UNO(or other controllers)
/*************************************************************************************

  Mark Bramwell, July 2010

  This program will test the LCD panel and the buttons.When you push the button on the shield?
  the screen will show the corresponding one.
 
  Connection: Plug the LCD Keypad to the UNO(or other controllers)

**************************************************************************************/

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);           // select the pins used on the LCD panel

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;

#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons(){               // read the buttons
    adc_key_in = analogRead(0);       // read the value from the sensor 

    // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
    // we add approx 50 to those values and check to see if we are close
    // We make this the 1st option for speed reasons since it will be the most likely result

    if (adc_key_in > 1000) return btnNONE; 

    // For V1.1 us this threshold
    if (adc_key_in < 50)   return btnRIGHT;  
    if (adc_key_in < 250)  return btnUP; 
    if (adc_key_in < 450)  return btnDOWN; 
    if (adc_key_in < 650)  return btnLEFT; 
    if (adc_key_in < 850)  return btnSELECT;  

   // For V1.0 comment the other threshold and use the one below:
   /*
     if (adc_key_in < 50)   return btnRIGHT;  
     if (adc_key_in < 195)  return btnUP; 
     if (adc_key_in < 380)  return btnDOWN; 
     if (adc_key_in < 555)  return btnLEFT; 
     if (adc_key_in < 790)  return btnSELECT;   
   */

    return btnNONE;                // when all others fail, return this.
}

void setup(){
   lcd.begin(16, 2);               // start the library
   lcd.setCursor(0,0);             // set the LCD cursor   position 
   lcd.print("Push the buttons");  // print a simple message on the LCD
}
 
void loop(){
   lcd.setCursor(9,1);             // move cursor to second line "1" and 9 spaces over
   lcd.print(millis()/1000);       // display seconds elapsed since power-up

   lcd.setCursor(0,1);             // move to the begining of the second line
   lcd_key = read_LCD_buttons();   // read the buttons

   switch (lcd_key){               // depending on which button was pushed, we perform an action

       case btnRIGHT:{             //  push button "RIGHT" and show the word on the screen
            lcd.print("RIGHT ");
            break;
       }
       case btnLEFT:{
             lcd.print("LEFT   "); //  push button "LEFT" and show the word on the screen
             break;
       }    
       case btnUP:{
             lcd.print("UP    ");  //  push button "UP" and show the word on the screen
             break;
       }
       case btnDOWN:{
             lcd.print("DOWN  ");  //  push button "DOWN" and show the word on the screen
             break;
       }
       case btnSELECT:{
             lcd.print("SELECT");  //  push button "SELECT" and show the word on the screen
             break;
       }
       case btnNONE:{
             lcd.print("NONE  ");  //  No action  will show "None" on the screen
             break;
       }
   }
}

Thanks again! I should now be able to noodle along. First project is a chronograph.

The problem with the original code is that the LCDKeypad include occurs before the LiquidCrystal include. The LCDKeypad include references a class declared in the LiquidCrystal include, so it can't find it. Including LiquidCrystal before LCDKeypad solves the problem.

Wrong:
#include <LCDKeypad.h>
#include <LiquidCrystal.h>

Correct:
#include <LiquidCrystal.h>
#include <LCDKeypad.h>