Pages: 1 [2]   Go Down
Author Topic: 16 Char LCD module  (Read 2631 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Both of my lcd are hd44780-compliant and both work identically with lcd4bit.

I have tried reversing the DB pins and swapping rs and enb between the 3 selected pins to no effect.  I even pinned out directly like the liquidcrystal helloworld sketch without mods to no effect..

Here is the pinout for my 8x2 (My 16x2 has 2 extra pins for backlight)

1 VSS [ch65293] Power Supply (0V, GND)
2 VDD [ch65293] Power Supply for Logic
3 V0 [ch65293] Power Supply for LCD Drive
4 RS H / L Register Select Signal
5 R/W H / L Read/Write Select Signal H : Read L : Write
6 E H / L Enable Signal (No pull- up Resister)
7 DB0 H / L Data Bus Line / Non- connection at 4- bit operation
8 DB1 H / L Data Bus Line / Non- connection at 4- bit operation
9 DB2 H / L Data Bus Line / Non- connection at 4- bit operation
10 DB3 H / L Data Bus Line / Non- connection at 4- bit operation
11 DB4 H / L Data Bus Line
12 DB5 H / L Data Bus Line
13 DB6 H / L Data Bus Line
14 DB7 H / L Data Bus Line

I have db0-3 tied to ground
enb on 3
rs on 9
rw tied to GND
Contrast on 10k pot dialed to optimal viewing when using lcd4bit

my liquidcrystal sketch:
Code:
#include <LiquidCrystal.h>

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
//LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
LiquidCrystal lcd(9, 8, 3, 4, 5, 6, 7);

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

void loop()
{
  delay(1000);
  lcd.print("hello, world!");
}

my lcd4bit sketch:
Code:
//example use of LCD4Bit library

#include <LCD4Bit.h>
//create object to control an LCD.  
//number of lines in display=1
LCD4Bit lcd = LCD4Bit(1);

//some messages to display on the LCD
char msgs[6][15] = {"apple", "banana", "pineapple", "mango", "watermelon", "pear"};
int NUM_MSGS = 6;

void setup() {
  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat

  lcd.init();
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
}

void loop() {  
  digitalWrite(13, HIGH);  //light the debug LED

  //pick a random message from the array
  int pick = random(NUM_MSGS);
  char* msg = msgs[pick];
  
  lcd.clear();
  lcd.printIn(msg);
  delay(1000);
  digitalWrite(13, LOW);
  
  //print some dots individually
  for (int i=0; i<3; i++){
    lcd.print('.');
    delay(100);
  }
  //print something on the display's second line.
  //uncomment this if your display HAS two lines!
  /*
  lcd.cursorTo(2, 0);  //line=2, x=0.
  lcd.printIn("Score: 6/7");
  delay(1000);
  */
  
  //scroll entire display 20 chars to left, delaying 50ms each inc
  lcd.leftScroll(20, 50);
}
Scrap from my LCD4bit library:
Code:
//RS, RW and Enable can be set to whatever you like
int RS = 9;
int RW = 8;
int Enable = 3;
//DB should be an unseparated group of pins  - because of lazy coding in pushNibble()
int DB[] = {4, 5, 6, 7};  //wire these to DB4~7 on LCD.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I bought a brandless 2x20 LCD with no marking on the PCB.  My setup is the same as dnear1 except I'm using output from 9, 10, 11, 12 of the arduino connected to DB4-7.  A 10k pot is connected with the centre connected to pin 3 of the LCD.  So far only tried using LCD4bit.

I only have the back light on but no pixel come on.

Anything I can try to solve this?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I looked at the datasheet for the hd44780 on Sparkfun's website..

It looks like maybe LiquidCrystal doesn't init the LCD correctly compared to lcd4bit..

I will post my mods if I can get it to work correctly..  
Logged

Greenfield, NH
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't seem to get any output either.  I am using the LCD4bit library on build 13.  Should I try with a pre-12 build maybe?  And yes, I have good contrast, everything is wired correctly and the R/W pin is grounded.  
« Last Edit: March 02, 2009, 02:37:23 pm by jgueydan » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Brought my arduino and went back to the shop to purchase a 2x16 LCD. Fix up the new LCD to the ardino and ran the LiquidCrystal example.  This time, it works!  Followed the example code and tie RW to one of the pins on arduino (pin 11 or something).

Will try using LCD4bit again tonight.

Strange thing is, even a new piece of 2x20 LCD didn't work while i'm at the shop.  Don't know what's wrong.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did and redid and did over again my wiring, sketch, etc..

I finally got half-working with this sketch..
It uses the unmodified LiquidCrystal library..
rs on pin 9
e on pin 3
DB4-7 on pins 4-7
and RW tied to ground but pin 8 'implied' just to get it working..

The LCD4bit and LiquidCrystal library differ majorly in the 'set cursor' functions..
in lcd4bit it is .cursorTo(x,y-1)
in liquidcrystal it is .setCursor(y,x-1)
so in order to go to first line you set (0,0) in liquidcrystal and (1,0) in lcd4bit
and for line 2 in liquidcrystal it is (0,1) and (2,0) in lcd4bit.. confusing!
Code:
#include <LiquidCrystal.h>

//example use of LCD4Bit library

//#include <LCD4Bit.h>
//create object to control an LCD.  
//number of lines in display=1
//LCD4Bit lcd = LCD4Bit(2);
LiquidCrystal lcd(9,8,3,4,5,6,7);

//some messages to display on the LCD
char msgs[6][15] = {"apple", "banana", "pineapple", "mango", "watermelon", "pear"};
int NUM_MSGS = 6;

void setup() {
  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat

  //lcd.init();
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  lcd.command(0x0F);//cursor on, display on, blink on.  (nasty!)
}

void loop() {  
  digitalWrite(13, HIGH);  //light the debug LED

  //pick a random message from the array
  int pick = random(NUM_MSGS);
  char* msg = msgs[pick];
  
  lcd.clear();
  lcd.print(msg);
  delay(1000);
  digitalWrite(13, LOW);
  
  //print some dots individually
  for (int i=0; i<3; i++){
    lcd.print('.');
    delay(100);
  }
  //print something on the display's second line.
  //uncomment this if your display HAS two lines!
  
  lcd.setCursor(0, 1);  //x=0, line=2.
  //lcd.setCursor(2, 0);  //line=2, x=0.
  lcd.print("Score: 6/7");
  delay(1000);
  
  
  //scroll entire display 20 chars to left, delaying 50ms each inc
  for(int i=0;i<20;i++)
  {
    lcd.command(0x18);
    delay(50);
  }
  //lcd.leftScroll(20, 50);
}
« Last Edit: March 03, 2009, 08:32:57 pm by dnear1 » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One wierd thing I noticed with liquidcrystal is this..

Usually the sketch won't display the first time the arduino is powered up.. if the arduino is already running and you upload a sketch or press the reset button it works fine..
if you unplug the usb, wait a few secs and plug back, the top line lights solid or sometimes you can barely read some text behind the top row..

like it needs more delay built into the init so that it resets properly and accepts the init..
« Last Edit: March 03, 2009, 09:47:40 pm by dnear1 » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This modification to the liquidcrystal library seems to work.
don't forget to delete the liquidcrystal.o file before compiling the sketch next time..
liquidcrystal.h=
Code:
#ifndef LiquidCrystal_h
#define LiquidCrystal_h

#include <inttypes.h>
#include "Print.h"

class LiquidCrystal : public Print {
public:
  LiquidCrystal(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t);
  LiquidCrystal(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t,
    uint8_t, uint8_t, uint8_t, uint8_t);
  void clear();
  void home();
  void init();
  void setCursor(int, int);
  /*
  void shiftDisplayLeft();
  void shiftDisplayRight();
  */
  virtual void write(uint8_t);
  void command(uint8_t);
private:
  void send(uint8_t, uint8_t);
  
  uint8_t _four_bit_mode;
  uint8_t _rs_pin; // LOW: command.  HIGH: character.
  uint8_t _rw_pin; // LOW: write to LCD.  HIGH: read from LCD.
  uint8_t _enable_pin; // activated by a HIGH pulse.
  uint8_t _data_pins[8];
};

#endif

liquidcrystal.cpp=
Code:
#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).

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;
 //delay(250);
  pinMode(_rs_pin, OUTPUT);
  if(_rw_pin!=255)
  {
    pinMode(_rw_pin, OUTPUT);
  }
  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
  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;
 //delay(250);
  pinMode(_rs_pin, OUTPUT);
  if(_rw_pin!=255)
  {
     pinMode(_rw_pin, OUTPUT);
  }
  pinMode(_enable_pin, OUTPUT);
  for (int i = 0; i < 4; i++)
    pinMode(_data_pins[i], OUTPUT);
//delay(250);
  /*command(0x28);  // function set: 4 bits, 1 line, 5x8 dots
  delay(5);
  command(0x28);  // function set: 4 bits, 1 line, 5x8 dots
  delayMicroseconds(100);
  command(0x28);  // function set: 4 bits, 1 line, 5x8 dots
  delay(5);
  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::init()
{
  if (_four_bit_mode==1) {
  delay(5);
  command(0x03);  // function set: 4 bits, 1 line, 5x8 dots
  delay(5);
  command(0x03);  // function set: 4 bits, 1 line, 5x8 dots
  delayMicroseconds(100);
  command(0x03);  // function set: 4 bits, 1 line, 5x8 dots
  delay(5);
  command(0x02);  // function set: 4 bits, 1 line, 5x8 dots
delay(1);
  command(0x02);  // function set: 4 bits, 1 line, 5x8 dots
delay(1);
  command(0x28);  // function set: 4 bits, 1 line, 5x8 dots
delay(1);
}
else
{
  command(0x38);  // function set: 8 bits, 1 line, 5x8 dots
}
delay(1);
  command(0x0C);  // display control: turn display on, cursor off, no blinking
delay(1);
  command(0x06);  // entry mode set: increment automatically, display shift, right shift
delay(1);
  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);
  if(_rw_pin!=255)
  {
  digitalWrite(_rw_pin, LOW);
  }
  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);
  }
}

my test sketch=
Code:
#include <LiquidCrystal.h>

//example use of LCD4Bit library

//#include <LCD4Bit.h>
//create object to control an LCD.  
//number of lines in display=1
//LCD4Bit lcd = LCD4Bit(2);
LiquidCrystal lcd(8,255,3,4,5,6,7);

//some messages to display on the LCD
char msgs[6][15] = {"apple", "banana", "pineapple", "mango", "watermelon", "pear"};
int NUM_MSGS = 6;

void setup() {
  pinMode(13, OUTPUT);  //we'll use the debug LED to output a heartbeat

  lcd.init();
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.command(0x0e);//cursor on, display on, blink on.  (nasty!)
}

void loop() {  
  digitalWrite(13, HIGH);  //light the debug LED

  //pick a random message from the array
  int pick = random(NUM_MSGS);
  char* msg = msgs[pick];
  
  lcd.clear();
//delay(1);
  lcd.print(msg);
  delay(1000);
  digitalWrite(13, LOW);
  
  //print some dots individually
  for (int i=0; i<3; i++){
    lcd.print('.');
    delay(100);
  }
  //print something on the display's second line.
  //uncomment this if your display HAS two lines!
  
  lcd.setCursor(0, 1);  //line=2, x=0.
  lcd.print("Score: 6/7");
  delay(1000);
  
  
  //scroll entire display 20 chars to left, delaying 50ms each inc
  for(int i=0;i<20;i++)
  {
    lcd.command(0x18);
    delay(50);
  }
  //lcd.leftScroll(20, 50);
}
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

dnear1, looks like you are making progress.

I was wondering if you need the delay(100) after lcd.print in the sketch with your revised library code?

Also, You may want to look at a problem with the delayMicroseconds (2000) calls in clear()_ and home() discussed in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1232663936
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I saw that post too when I was looking for solutions to my problem.

I tried changing the delay values around to see if it could be reduced..

but any reduction to the value caused my sketch to fail..

While that solution may work in most cases, I think it could cause the sketch to completely fail if the millis value 'rolls over' during the calculation.. If my concern is valid.. that means you can't use that function on a device that does not have user interaction or you risk it basically crashing after xx days..  Is there a work around for the work around?

One work around is to disable the delay.. but then you need to make sure not to try to update the LCD until at least another 2ms or the LCD will be the one dropping characters!  
Logged

Greenfield, NH
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

dnear1,

Thanks for posting your findings...my display works great now  smiley-wink
So, does this mean there's no need to use the LCD4bit library now?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, no need for the lcd4bit library.

I ran into another unintended consequence..  when I try to print the degree symbol, in lcd4bit I just put lcd.print(223) and it put the result up there.. now with the same command it is printing the number 223 instead of the degree symbol..  
It looks like my answer may be here..

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1233339330/12#12
« Last Edit: March 04, 2009, 01:25:43 pm by dnear1 » Logged

Pages: 1 [2]   Go Up
Jump to: