ShiftLCD library gives an error

Hello everyone,

I recently downloaded the ShiftLCD library(http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html) to control my 16x2 LCD with a 74HCT595N shift register.

I have tried to compile some example sketches of the ShiftLCD library, but it always gives this error:

In file included from HelloWorld.cpp:55: D:\Programma's\Arduino-1.0\libraries\ShiftLCD/ShiftLCD.h:116: error: conflicting return type specified for 'virtual void ShiftLCD::write(uint8_t)' D:\Programma's\Arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

I'm using Arduino IDE 1.0.

What is going wrong here?

try changing the 'conflicting return type' void to size_t ( Print class changed in arduino 1.0 ) You will find it at D:\Programma's\Arduino-1.0\libraries\ShiftLCD/ShiftLCD.h line 116

Also the function will have to return some value to work. I would return the number of characters printed.

pYro_65: try changing the 'conflicting return type' void to size_t ( Print class changed in arduino 1.0 ) You will find it at D:\Programma's\Arduino-1.0\libraries\ShiftLCD/ShiftLCD.h line 116

Also the function will have to return some value to work. I would return the number of characters printed.

This is on line 116: virtual void write(uint8_t);

Do I need to remove 'virtual void' and replace it with size_t?

Do I need to remove 'virtual void' and replace it with size_t?

What happened when you tried?

PaulS:

Do I need to remove ‘virtual void’ and replace it with size_t?

What happened when you tried?

Another big error:

D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:6:22: error: WProgram.h: No such file or directory
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: In member function 'void ShiftLCD::init(uint8_t, uint8_t, uint8_t, uint8_t)':
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:54: error: 'OUTPUT' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:54: error: 'pinMode' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: In member function 'void ShiftLCD::begin(uint8_t, uint8_t, uint8_t)':
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:81: error: 'delayMicroseconds' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:83: error: 'LSBFIRST' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:83: error: 'B00000000' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:83: error: 'shiftOut' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:93: error: 'LOW' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: In member function 'void ShiftLCD::clear()':
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:143: error: 'delayMicroseconds' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: In member function 'void ShiftLCD::home()':
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:149: error: 'delayMicroseconds' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: At global scope:
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:252: error: prototype for 'void ShiftLCD::write(uint8_t)' does not match any in class 'ShiftLCD'
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\/ShiftLCD.h:116: error: candidate is: virtual size_t ShiftLCD::write(uint8_t)
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: In member function 'void ShiftLCD::updateBacklight()':
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:260: error: 'HIGH' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:260: error: 'digitalWrite' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:261: error: 'LSBFIRST' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:261: error: 'shiftOut' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:262: error: 'B00000000' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:263: error: 'LOW' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:265: error: 'HIGH' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:265: error: 'digitalWrite' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:266: error: 'LSBFIRST' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:266: error: 'shiftOut' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:267: error: 'LOW' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: In member function 'void ShiftLCD::write4bits(uint8_t, uint8_t)':
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:284: error: 'B00000010' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:285: error: 'B00000001' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:293: error: 'B11110000' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:295: error: 'HIGH' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:295: error: 'digitalWrite' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:296: error: 'LSBFIRST' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:296: error: 'shiftOut' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:297: error: 'LOW' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:298: error: 'delayMicroseconds' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp: In member function 'void ShiftLCD::write8bits(uint8_t, uint8_t)':
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:315: error: 'B00000010' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:316: error: 'B00000001' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:325: error: 'HIGH' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:325: error: 'digitalWrite' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:326: error: 'LSBFIRST' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:326: error: 'shiftOut' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:328: error: 'LOW' was not declared in this scope
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:336: error: 'delayMicroseconds' was not declared in this scope

This is the example code:

/*
  ShiftLCD Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The ShiftLCD 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:
 
 ---Shift Register 74HC595---
 * SR Pin 14 to Arduino pin 2
 * SR Pin 12 to Arduino pin 3
 * SR Pin 11 to Arduino pin 4
 * SR Pin  8 to Ground
 * SR Pin 16 to +5v
 * SR Pin 13 to Ground
 * SR Pin 10 to +5v
 -----Shift Reg to LCD--------
 * SR Pin 15 to D7
 * SR Pin 1  to D6
 * SR Pin 2  to D5
 * SR Pin 3  to D4
 * SR Pin 5  to MOSFET gate
 * SR Pin 6  to Enable
 * SR Pin 7  to RS
 -----LCD HD44780-------------
 * Vss to Ground
 * Vdd to +5V
 * Vo  to 10k Wiper
 * R/W to Ground
 * 5v  to +5v
 * Gnd to MOSFET Drain
 ------N Chanel MOSFET--------
 * Source to Ground
 * Gate   to SP Pin 5
 * Drain  to LCD Gnd
 * 1k Resistor Between gate and source
 
 For a more detailed schematic, please see my blog:
 
 http://cjparish.blogspot.com/2010/01/controlling-lcd-display-with-shift.html 
 
 Library modified from the original LiquidCrystal Library
 This example originaly by Tom Igoe, Jul 2009
 Example modified for use with ShiftLCD
 Chris Parish, January 12th 2010
 
 */

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

// initialize the library with the numbers of the interface pins
ShiftLCD lcd(2, 4, 3);

void setup() {
  // set up the LCD's number of rows and columns: 
  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);
}

Search the forum. The WProgram.h error comes up every couple of days.

Ok so I replaced the ‘virtual void’ with size_t like I did before and I also replaced WProgram.h with Arduino.h in ShiftLCD.ccp.
Now I get this error:

D:\Programma’s\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:252: error: prototype for ‘void ShiftLCD::write(uint8_t)’ does not match any in class ‘ShiftLCD’
D:\Programma’s\Arduino-1.0\libraries\ShiftLCD/ShiftLCD.h:116: error: candidate is: virtual size_t ShiftLCD::write(uint8_t)

That's because you removed the virtual declaration. Put it back.

That library like so many others was broken by the Arduino 1.0 release Go get a different SR library that works with Arduino 1.0 There are several others out there: Here are some links: https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home http://code.google.com/p/arduinoshiftreglcd/ http://code.google.com/p/shiftreglcd123/ http://www.3guys1laser.com/blog-cheap-arduino-2-wire-lcd-display-0

I'm partial to Malpartida's library as it supports many different interfaces plus I've been working on it and have tested it quite a bit. Very soon (within a week or so) a new major update should be available. But it definitely works with 1.0 and pre 1.0 Arduino.

-- bill

Okay I will try what PaulS said, and if that doesn't work, then I will download another library like bperrybap said.

Thank you for the help guys!

edit:

If I add 'virtual' it gives this error:

D:\Programma's\Arduino-1.0\libraries\ShiftLCD\ShiftLCD.cpp:253: error: prototype for 'void ShiftLCD::write(uint8_t)' does not match any in class 'ShiftLCD'
D:\Programma's\Arduino-1.0\libraries\ShiftLCD\/ShiftLCD.h:116: error: candidate is: virtual size_t ShiftLCD::write(uint8_t)

If I add 'virtual void' it gives this error:

In file included from HelloWorld.cpp:55:
D:\Programma's\Arduino-1.0\libraries\ShiftLCD/ShiftLCD.h:116: error: variable or field 'size_t' declared void
D:\Programma's\Arduino-1.0\libraries\ShiftLCD/ShiftLCD.h:116: error: expected ';' before 'write'
HelloWorld.pde:-1: error: cannot declare variable 'lcd' to be of abstract type 'ShiftLCD'
D:\Programma's\Arduino-1.0\libraries\ShiftLCD/ShiftLCD.h:87: note:   because the following virtual functions are pure within 'ShiftLCD':
D:\Programma's\Arduino-1.0\hardware\arduino\cores\arduino/Print.h:48: note:     virtual size_t Print::write(uint8_t)

So maybe it's better that I download another library.

Look at the messages. They are telling you EXACTLY what the problem is.

You have a method, write(), in the implementation that takes an argument of type uint8_t, and returns a void. The only method in the class declaration that is named write() takes an argument of type uint8_t and is supposed to return a size_t.

Fix the source file to match the header file!

I appreciate your help, but I do not really understand it all. Since it's broken since Arduino 1.0, then it's maybe a better choise to download a compatible library.

There are two lines of code to change: In the header, change

virtual void write(...

to

virtual size_t write(...

In the source file, change

void ShiftLCD::write(...

to

size_t ShiftLCD::write(...

At the end of the ShiftLCD::write() method, add

   return 1;

Thank you, I will try this tomorrow.

It works fine now!
Thank you man!

Hello I tried to use this library but I did not succeed. Specifically, I managed to make two changes, but I have not understood what to do here:

PaulS: At the end of the ShiftLCD::write() method, add

   return 1;

I am still in the period of acquiring skills and writing codes are still many things to learn. Thanks for your patience.

Hey b97joe,

I have the library working, so I'll send you a PM with mine in a few minutes.

Hi, you can also try the "LCD Library", aka, the New LiquidCrystal library. It is a plug-and-play replacemente with the support of a wide range of LCD drivers: I2C, 4bit, 8bit, and a wide range of ShiftRegister configurations. It is a lot more performant than the stock library and has been well tested.

You can find the library documentation here:https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

In the schematics section, you will find a wide range of drivers (I2C, SR, 4bit, 8bit, ...), their corresponding schematic and how to initialize them.

The other nice thing about the library is that if you wish to migrate from a 4bit LCD to an I2C or SR you don't need to change the code of your project, just the object creation (variable creation).

In the same wiki you will find a nice benchmark of a few of the supported configurations.

Thank you TiboJ. Now I have an LCD connected to the Arduino only 3 wires. @ fm Is very interesting and this version also. I will try as soon as my time allows to see which is easier to use. Thanks a lot.

b97joe: Thank you TiboJ. Now I have an LCD connected to the Arduino only 3 wires. @ fm Is very interesting and this version also. I will try as soon as my time allows to see which is easier to use. Thanks a lot.

No problem, have fun!