lcd 4-bit library

Hello all!
I’ve gone out and bought an LCD (liquid crystal display) today. I set it up using the library shown here:

http://arduino.cc/en/Tutorial/LiquidCrystal

It did not work, so after lots of tweaking and fiddling I gave up and tried
a different library, shown here:

http://www.arduino.cc/playground/Code/LCD4BitLibrary

That did not work either. After more tweaking, I ended up with the
following code:

#include <LCD4Bit.h> 
LCD4Bit lcd = LCD4Bit(1); 
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.clear();
  lcd.print("hello, world!");
}

void loop() {}

and the following error messages:

sketch_dec18a.cpp:2:22: error: LCD4Bit.h: No such file or directory
sketch_dec18a:2: error: ‘LCD4Bit’ does not name a type
sketch_dec18a:3: error: ‘LiquidCrystal’ does not name a type
sketch_dec18a.cpp: In function ‘void setup()’:
sketch_dec18a:6: error: ‘lcd’ was not declared in this scope

These messages are confusing me…

sketch_dec18a.cpp:2:22: error: LCD4Bit.h: No such file or directory

suggests to me that the code cannot find the library, when it is saved here:
arduino21/libraries/LCD4Bit

The rest makes no sense.

Any help is greatly appreciated!
Thanks, Onions.

After installing the LCD4bit library, did you stop and re-start the IDE?

Are you able to import the library into a blank sketch using Sketch + Import Library...?

Take care of the library issues, and the rest of the error messages will go away.

After installing the LCD4bit library, did you stop and re-start the IDE?

It might be a stupid question, but what is the IDE? [smiley=embarassed.gif] [smiley=embarassed.gif] [smiley=embarassed.gif]

The IDE is the Arduino application interface (Interactive Design Editor or something like that) where you type your sketch and trigger the compiler.

It did not work,

What did it do?

The LCD4bit library is a bit antiquated, poorly written, and the LCD initialization is not completely correct as I recall.

#include <LCD4Bit.h>
LCD4Bit lcd = LCD4Bit(1);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
...

You are invoking the LCD4Bit library and then are using LiquidCrystal commands.

I suggest you start again and follow the tutorial at Arduino Tutorial - connecting a parallel LCD. Don’t skip any steps especially this one “This means you've got the logic, backlight and contrast all worked out. Don't keep going unless you've got this figured out!” about halfway down, just before the Bus Wiring section.

Also, don’t forget to deal with LCD pin 5 (R/W).

Don

What did it do?

Absolutely nothing, just showed some error messages.

Do you know the pin assignments for your display, mine uses LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

Do you know the pin assignments for your display

I set it up how it showed in the schematic: http://arduino.cc/en/uploads/Tutorial/LCD_schem.png so it should be right, but I will check that out...

well the lcd pin define looks ok for that pinout, i would say drop the 4-bit library and just go with the liquidcrystal library that comes with the Arduino IDE, it works.

a couple of things first, when you switch power on do you get a black bar across one line of the lcd but not the other line, if yes, the lcd's not initialised, if no black bar, check your contrast control pot

i would say drop the 4-bit library and just go with the liquidcrystal library that comes with the Arduino IDE

That’s what I’ve done. At first, the program would not download onto the
board at all. I imported the LiquidCrystal library and ended up with two,
but the program did download:

#include <LiquidCrystal (2).h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {}

when you switch power on do you get a black bar across one line of the lcd but not the other line, if yes, the lcd’s not initialised

That seems to be the problem:

How do I initialise it?

Wiring looks ok but it's hard too tell, i usually use longer wires it's easier to trace, red, black power, blue data, green control, but thats just me, Liquidcrystal Library should go here arduino-0021\libraries having 2 includes of the same library may not be helping, if all else fails load the blink sketch with nothing connected and make sure your board is working.

Hard to see but are all the data lines 2,3,4,5 in the right positions

i usually use longer wires it's easier to trace, red, black power, blue data, green control

I only had the pink ones lying around ( with a few acceptions), otherwise I would do something similar.

Your LCD wiring is most likely exactly backwards. Most of the modules that I have seen have pin 1 near the outside edge of the PC board.

Did you follow the tutorial that I recommended previously. If not you are wasting a lot of time.

Don

Did you follow the tutorial that I recommended previously

Yes, I did. Maybe I will have to try it again...

I think I have to stick to one concept per post.

You didn't comment about the first part of reply #12. (It's the important part, which is why it was first.)

Don

Yes, I did. Maybe I will have to try it again...

How far did you get before things did not work as depicted in the tutorial?

Don

That should just work if you follow the tutorial as suggested on the Adafruit web site.

Ditch the 4bit code. Use the LCD library as included with the Arduino IDE. Follow Ladyada's instructions carefully.

You didn't comment about the first part of reply #12.

Your LCD wiring is most likely exactly backwards. Most of the modules that I have seen have pin 1 near the outside edge of the PC board.

I have tried it the other way but it does nothing, not even showing the rectangles.

How far did you get before things did not work as depicted in the tutorial?

I got up to the step "Connect the Arduino up to power, you'll notice the backlight lights up". I was not sure if my LCD had a backlight, so I carried on. "Now turn on the Arduino, you'll see the backlight light up (if there is one), and you can also twist the pot to see the first line of rectangles appear." This did not work either (after I wired it up the other way).

I will try again soon with the LCD wired up the first way round.

I was not sure if my LCD had a backlight

The LCD interface uses 14 pins. Since your board has 16 pins it has a backlight. Did you look for pin number identification on both sides of the pc board? How about posting some nice clear photos of both sides of the board?

I suggest you disconnect everything and start again. Hook up only the backlight, the power, and the potentiometer (pins 1, 2, 3, 15, and 16. I really think that you should start by considering pin 1 to be near the edge of the board. Keep working at it until you see the black boxes. No amount of programming will help until you get this step working. You may possibly have one of the offbeat modules with the +5V and GND pins reversed . There is also a possibility that your LCD requires a negative voltage at pin 3.

Don