Add to Reference for LiquidCrystal w/ 4 data lines

When using 4 data lines to connect to an LCD, the data lines should be connected to D4, D5, D6 and D7, not D0-D3 as you would think.

This web page shows a nice picture on how to connect a LCD to a PIC chip. Ignore the pic chip, look at the pins being used on the LCD panel.

http://www.rentron.com/PicBasic-LCD.htm

There is a diagram in the playground here Arduino Playground - HomePage

That should work for this sketch:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 6, 7, 8, 9, 10);

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

void loop() {}

I cannot get the LCD to work. Details in the following post. (I am a new member and hence cannot post links in my first post).

Hi, I am really confused, because I am using this lcd module: http://www.sparkfun.com/datasheets/LCD/GDM1602K.pdf and the pinout is different from the diagram you have linked (in fact completely opposite). However, I think that the one in the original datasheet is more likely to be correct, especially because I have the backlight working using that. Unfortunately, nothing else works. I tried the following sketch:

#include <LiquidCrystal.h>

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d0, d1, d2, d3 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()
{
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{
}

The comments tell me to connect d0-d3, but the documentation at http://arduino.cc/en/Reference/LiquidCrystalConstructorsay something else. I tried both, but have not managed to get even the cursor on the screen. For the contrast, I don't have a potentiometer (yet), but I tried constant 5, 0 and 3.3 and none of them worked. Is there something obvious I am missing here?

You want to use d4, d5, d6, d7. The comment in the example is wrong and will be corrected in the next release of the software. Sorry about that.

Also, it might be the missing potentiometer that's the problem. Sometimes the LCD can be very picky about the contrast voltage.

Thanks. Yeah, it seems like it was a missing potentiometer. I bought one, and now I see only square blocks on my LCD, but not "Hello World"

I have the same square blocks on one row...
it's the same when you do the proper connections and when you power up only the LCD and the backlight.

My LCD is this one http://www.datasheet4u.com/html/Y/M/1/YM1602C_Dalian.pdf.html

Has anyone else run into this and solved it? I still get a row of black squares, and cannot get my LCD to display words.

Try this example

http://www.skpang.co.uk/content/view/29/42/

Download the sketch at the bottom of the page.


Arduino boards from the UK http://www.skpang.co.uk/catalog/

Hello,

I would like to see an option in the 4bit LiquidCrystal library to disable the rw pin.

Cheers
KiWiX

I modified my liquidcrystal library as such..
I put this if statement around the rw pin commands

#include "LiquidCrystal.h"

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "WProgram.h"

// When the display powers up, it is configured as follows:
//
// 1. Display clear
// 2. Function set: 
//    DL = 1; 8-bit interface data 
//    N = 0; 1-line display 
//    F = 0; 5x8 dot character font 
// 3. Display on/off control: 
//    D = 0; Display off 
//    C = 0; Cursor off 
//    B = 0; Blinking off 
// 4. Entry mode set: 
//    I/D = 1; Increment by 1 
//    S = 0; No shift 
//
// Note, however, that resetting the Arduino doesn't reset the LCD, so we
// can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called).

// If not using rw pin set it to 255 so it doesn't occupy a pin, changes below..

LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
  uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) :
  _four_bit_mode(0), _rs_pin(rs), _rw_pin(rw), _enable_pin(enable)
{
  _data_pins[0] = d0;
  _data_pins[1] = d1;
  _data_pins[2] = d2;
  _data_pins[3] = d3; 
  _data_pins[4] = d4;
  _data_pins[5] = d5;
  _data_pins[6] = d6;
  _data_pins[7] = d7; 
  
  pinMode(_rs_pin, OUTPUT);
[glow]//change here allows disabling rw pin
  if(_rw_pin!=255)
  {
  pinMode(_rw_pin, OUTPUT);
  }[/glow]
  pinMode(_enable_pin, OUTPUT);
  
  for (int i = 0; i < 8; i++)
    pinMode(_data_pins[i], OUTPUT);
 
  command(0x38);  // function set: 8 bits, 1 line, 5x8 dots  i think 28==2 line not 1..  30 should be 1 line
  command(0x0C);  // display control: turn display on, cursor off, no blinking
  command(0x06);  // entry mode set: increment automatically, display shift, right shift
  clear();
}

LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
  uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) :
  _four_bit_mode(1), _rs_pin(rs), _rw_pin(rw), _enable_pin(enable)
{
  _data_pins[0] = d0;
  _data_pins[1] = d1;
  _data_pins[2] = d2;
  _data_pins[3] = d3; 
  
  pinMode(_rs_pin, OUTPUT);
[glow]//change here allows disabling rw pin
  if(_rw_pin!=255)
  {
  pinMode(_rw_pin, OUTPUT);
  }[/glow]
  pinMode(_enable_pin, OUTPUT);
  
  for (int i = 0; i < 4; i++)
    pinMode(_data_pins[i], OUTPUT);


  command(0x28);  // function set: 4 bits, 1 line, 5x8 dots  i think 28==2 line not 1..  20 should be 1 line
  command(0x0C);  // display control: turn display on, cursor off, no blinking
  command(0x06);  // entry mode set: increment automatically, display shift, right shift
  clear();
}

void LiquidCrystal::clear()
{
  command(0x01);  // clear display, set cursor position to zero
  delayMicroseconds(2000);
}

void LiquidCrystal::home()
{
  command(0x02);  // set cursor position to zero
  delayMicroseconds(2000);
}

void LiquidCrystal::setCursor(int col, int row)
{
  int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
  command(0x80 | (col + row_offsets[row]));
}

void LiquidCrystal::command(uint8_t value) {
  send(value, LOW);
}

void LiquidCrystal::write(uint8_t value) {
  send(value, HIGH);
}

void LiquidCrystal::send(uint8_t value, uint8_t mode) {
  digitalWrite(_rs_pin, mode);
[glow]//change here allows disabling rw pin
  if(_rw_pin!=255)
  {
  digitalWrite(_rw_pin, LOW);
  }[/glow]

  if (_four_bit_mode) {
    for (int i = 0; i < 4; i++) {
      digitalWrite(_data_pins[i], (value >> (i + 4)) & 0x01);
    }
    
    digitalWrite(_enable_pin, HIGH);
    digitalWrite(_enable_pin, LOW);
    
    for (int i = 0; i < 4; i++) {
      digitalWrite(_data_pins[i], (value >> i) & 0x01);
    }

    digitalWrite(_enable_pin, HIGH);
    digitalWrite(_enable_pin, LOW);
  } else {
    for (int i = 0; i < 8; i++) {
      digitalWrite(_data_pins[i], (value >> i) & 0x01);
    }

    digitalWrite(_enable_pin, HIGH);
    digitalWrite(_enable_pin, LOW);
  }
}

then just specify 255 for the rw pin and it is 'disabled'..