analog in to 4 bit LCD driver

just wanted to say: AWESOME THREAD!! :slight_smile:

Thanx for your wiki link neillzero :slight_smile:

just wondered what LCD display I should get to start with.....

Hi Westbam,

Where are you? In the UK I recently bought a maplin "N27AZ" 16x2 with a backlight - expensive at 10 pounds. That's what I tested the 4-bit library against during development. Note that these seem to be web-only components at maplin now.

I plan to make a short tutorial about a simple device I made which incorporates this display (but we all make plans...)

If size is a factor, I'd be tempted to try to make do with a 1x8, as the 16 character displays are significantly longer than your arduino board. Then again, it's nice to have a bit more space on the display for debugging a lot of stuff (when serial is tied up).

A backlight is going to drain a battery more quickly, but normally you can decide not to wire it up.

I'd get something cheap for your first build. Then you'll learn what you can live with and what you're really missing.

Make sure it is HD44780-compatible.

I was able to get the LiquidCrystal library to work okay with this:

Since it only works with 1 of the 2 lines, I wanted to try the LCD4Bit library instead.
(and of course I'd like to use less pins)

The example doesn't work - I haven't changed any of the wiring but looking at the code,
it seems that it uses the same pines as LiquidCrystal.

Anyone else used this specific display or am I out of luck with LCD4Bit?

Thanks for any info,
Rob

Hi Rob, I wrote the 4-bit library, so would be keen to help you get it to work. I've only tested it so far on two devices (and they were from the same family).

I think maybe you've not tied RW low. There are two things to watch for when using this library:

  1. get the pins right (In your case, I don't think this is the problem)
  2. tie RW low

1. Get the pins right:
I intentionally kept the pins the same between the LiquidCrystal library and 4BitLCD library, so if you have your circuit working with LiquidCrystal library, you should have to make only two changes:

  • unplug the four unused databus lines DB0, DB1, DB2, DB3.
  • tie the LCD's RW input to ground (see point #2 below).

Here are the default arduino digital pins the 4bit library expects you to use. They can be found in LCD4Bit.cpp.

int RS = 12;
int RW = 11; //irrelevant if USING_RW is false.
int Enable = 2;
//4-bit data bus should be a sequence of pins
int DB[] = {7, 8, 9, 10}; //wire these to DB4~7 on LCD.

Ideally, when someone creates an instance of LCD4Bit, they should be able to specify the pins they want to use. Early days.

2. Tie RW low.
I wrote the 4-bit library for people who want to save on arduino pins. As most applications only need to write data to the LCD and never read, we can save another pin by hard-wiring the LCD RW input to low (or whatever indicates a write-operation in your LCD data sheet). The LCD4bit library expects this wiring and won't try to control the RW pin (by default). You can disable this behaviour in LCD4bit.cpp by finding the line
int USING_RW = false;
and setting it to true.

Making changes to the library
If you make changes in LCD4Bit.cpp, be sure to delete LCD4Bit.o before recompiling your arduino sketch - this will force recompilation of the library.

GDM1602K datasheet
By the way, looks like there's a more comprehensive data sheet for that product here:
http://www.xmocular.com/pdf/GDM1602K.pdf
not that you should need it.

What else to try
If the above ideas don't help, try using glasspusher or massimo's 4-bit code, too. This would give us the confidence that we can get your display working somehow, and I'll look at the 4bit library initialisation code again as I have a feeling it's not perfect. If we can get the LCD4Bit library tested successfully on many devices, we should be able to distribute it with the arduino IDE alongside the main LiquidCrystal library, making this much easier for all the other arduino users.

All comments here apply to LCD4Bit library v0.1 (16th Oct 2006). YMMV with other versions.

General LCD documentation on the arduino playground:
http://www.arduino.cc/playground/Code/LCD

good luck for now!
neill

hey neill,

thanks a lot for the info - sorry it took so long to take another stab at it.
i definitely did not have RW tied low so i made that change and your random fruit example is working now!
you can add this device to your HCL i guess. :slight_smile: (at least, it works with one of the two display lines)

also, being new to datasheets (and microcontrollers, and electronics, and...), i'm having a hard time figuring out how to get the backlighting for this thing to work. the datasheet is sort of confusing to me - it seems like I can use pins 1&2 OR 15&16 OR the two pads on the side of the display?

also, it seems to say that it wants 4.2V for the backlight. i had read somewhere that i could use the ~.7V voltage drop of pretty much any diode to get me in that range from our normal 5V. my multimeter is saying that i'm at 5.06V without a diode and 4.8V with the diodes i've tried - a little too high? maybe i've already fried the backlighting because i think i may have given it the 4.8V while i was playing around - i remember seeing backlighting for a moment at some point. :slight_smile:

thanks again for the help,
rob

Hi Rob,
Great!
So it was really my fault for not documenting that tie-low requirement. Ouch. Sorry for the wasted time. I've just now improved the documentation with a wiki page here:
http://www.arduino.cc/playground/Code/LCD4BitLibrary
Please feel free to add corrections and improvements.

Regarding the backlight questions, I haven't used one of those displays but have a look at landon's useful post in this recent thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1164517397/3#3

neill

your library is excelent,but I have a little question, how can I visualize the ADC in Decimal format?, Now I can see the result but only in ASCII code, how can I translate it to Decimal?

thanks fpr your answer and exuse mefor my bad english

greetings from Colombia !

:stuck_out_tongue: I forgot another question...

I need to modified the library in order to use the LCD from 2 to 8 pin.. but when I make the changes it doesn`t work if I delete the .o file it doesn´t apear again...

thanks for the answer

Hi Alvaro,
If I understand your first question correctly, you want to print your number in decimal on the LCD.

See the section "Printing Numbers" on the LCD wiki page:
http://www.arduino.cc/playground/Code/LCD

Remember that the LCD library print() functions accept single ascii characters or strings of characters. So first you have to convert your number into a string representation. The wiki section above shows how to do this using the itoa() function.

It might make sense for the LCD library to provide another function, say printNumber(int) which took an integer and printed its string representation in decimal.

neillzero

First off, kudo's for the instructions in the 4bit playground page. If I had been paying attention to the datasheet I found for my display, I'd have got it working the first time :slight_smile: (For some reason the pin numbering is ass-backwards on my LCD). Still, I have a small question. For now, the random fruit example works perfectly. Single line, scrolling, all the bits. But, if I enable the 2nd line and the commented out 'score' bit the display stays empty. No noise, no nothing. Backlight comes on, but no character appear. Am I missing something, or have my earlier attempts killed just the second line? The display is a pc1602f, which should be hd44780 compatible.

(excuse me for lifting this old thread from the depths of oblivion)

Thanks!
Andre

thanx a lot!

Hello Neillzero.

Congratulation by LCD4bit lib. I'm using and it's very very custom.

But, I have a suggestion:

Currently, I formatted my computer, but the pins had changed the lib in itself. cpp.

So when I installed again my system and upload to arduino, my display doesn't worked.

So again I edit in your CPP the pins.

You should create methods to set the number of pins.

Thanks

Hey Neilzero..

Ive adapted your code into my little program, but can't find out how to make it show the temperature as 26,1 as oposed to the 261 format it is in now ?!?! Im sure you have a solution, I just can't see it since i've only been into arduino programming for about 4 days now :-/

My code is at the bottom.

  int heat = 451;      

char heat_str[4] = "   ";  //reserve the string space first
 itoa(heat, heat_str, 10);
 lcd.printIn(heat_str);

//todo: make sure number can be notated within str length.




My code..


#include <LCD4Bit.h>

LCD4Bit lcd = LCD4Bit(2);
int temperaturePin = 2;    // select the input pin for the temperature

void setup() {
 lcd.init();
}

void loop() {

lcd.clear();
 lcd.printIn("Vandtemperatur :");
 delay(1000);

int i, val = 0;
 
 for(i = 0; i < 20; ++i)
 {
      val += analogRead(temperaturePin);    // read the value from the sensor
      delay(50);
 }
 
 val /= 4.06;      // conversion value to millivolts
  if(val > 28 * 10)   // temperature in deg C times 10, since we're measuring to tenths of a degree
    digitalWrite(13,HIGH);
  else
    digitalWrite(13,LOW);
   
    int heat = val;      
 char heat_str[5] = "    ";  //reserve the string space first
 itoa(val, heat_str, 10);

lcd.cursorTo(2, 5);  //line=2, x=6.
 lcd.printIn(heat_str);
 delay(1000);
 }




Thanks... Martin

neillzero,
Thanks so much for the trouble shooting help! I've been sitting here looking over the wiring over and over and over, wondering what could be wrong.
Turns out, once I delete LCD4bit.o and recompiled the code, it worked perfectly! I'm glad I found your post, maybe this should be in the wiki? Maybe it is and I missed it!
Thanks again!

My 2 playing with 4 bits LCD...

I always use LCD4Bits library...but i build it with a new LCD WH1602, and do not work...
in the Lib note this:

// ########## pin assignment ##########
int RS = 12; // Register Select
int RW = 11; // Read/Write
int En = 2; // Enable

//DB should be an unseparated group of pins - because of lazy coding in push_nibble()
int DB[] = {7, 8, 9, 10}; // DB4 .. DB7

That on the default lib, my Lib:
// ########## pin assignment ##########
int RS = 3; // Register Select
int RW = 11; // Read/Write
int En = 2; // Enable

//DB should be an unseparated group of pins - because of lazy coding in push_nibble()
int DB[] = {8, 5, 7, 6}; // DB4 .. DB7 :o

So this is not working... could be the pin assignment?

Best Regards!
Frank

Hey Neilzero..

Ive adapted your code into my little program, but can't find out how to make it show the temperature as 26,1 as oposed to the 261 format it is in now ?!?! Im sure you have a solution, I just can't see it since i've only been into arduino programming for about 4 days now :-/

Solow, read the attached post and you will get it.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1218132924/8#8

Hey,
im using this lcd http://www.sparkfun.com/commerce/product_info.php?products_id=709
and i cant get it to work, i followed your post Arduino Playground - LCD4BitLibrary
is it my lcd isnt compatible or am i doing something wrong?
Thanks

I've got a question, I haven't seen anyone else getting these strange results.

I have a HD44780 LCD and finally got it to display characters with the example. Only problem is, I don't see fruits I see characters like ->, 0, etc. It's like the character map used isn't correct for my LCD. Can these vary by LCD or isn't the ascii universal?

Any ideas? I've been playing with pins and am going to start probing to make sure all my connections are being made. Anything else I should look for?

EDIT
Nevermind my dumb question. I was feeding corrupt data (data pins were backwards)

This is a great thread. Thanks for contributing. Just thought I'd capture the landmark I stumbled upon

Hi, i came across these lines in your great library:

void LCD4Bit::printIn(char msg[]) {
  uint8_t i;  //fancy int.  avoids compiler warning when comparing i with strlen()'s uint8_t
  for (i=0;i < strlen(msg);i++){
    print(msg[i]);
  }
}

In my opinion you don't need to include <string.h> and you don't need that fancy int8_t. Take a look:

void LCD4Bit::printIn(char msg[])
{
      int i = 0;
      while(msg[i])
      {
            print(msg[i]);
            i++;
      }
}

greetings sunny