Interfacing Arduino with a Purdy LCD (4×40) – Modified LCD4Bit Library
April 13th, 2008 by TheKidd
So I managed to grab a Purdy LCD sample (thanks to LadyAda’s page) to test Arduino interfacing. The first problem I ran into was that my LCD has two LCD controllers (KS0066 – based on HD44780). Thankfully lega7 faced this issue and modified code to work with a 4 line LCD.
I started with that but decided I wanted to modify his library to provide a few different advantages for my design. First of all, I set it up so the developer could pass the library all of the pins and other variables depending on their specific LCD. I also added a few additional functions including an easy debug function, right scroll function, and number functions.
A lot of this is still under testing so I will update this post as I improve the library and learn more about C/C++/C#. Hopefully it will work with other screens easily. This I have not tested yet as I only have one LCD at the moment. Its all kind of crazy at the moment because my background in programming is non-existent. I can read code but don’t know if I’m writing it properly yet. Then again, thats what I like about microcontrollers. I can build circuits and code and actually see it happen. Its definitely got me interested again in becoming a better programmer and engineer.
So anyway, moving on…Here is the Arduino code I’m currently working with.
#include <LCD4Bit.h>
// Constants
#define DEBUG_LED = 13;
// Variables: Program definitions for user configurable settings.
int lcdRows = 4;
int charactersPerLine = 52;
int dotFormatPtn = 0×00; //5×7 dots. 0×04 is 5×10
int usingRW = false;
int registerSelect = 6;
int readWrite = 7;
int enablePin1 = 0;
int enablePin2 = 1;
const int NUM_DB_PINS = 4;
int dataBits[NUM_DB_PINS] = {2, 3, 4, 5};
int test;
LCD4Bit lcd = LCD4Bit(lcdRows, charactersPerLine, dotFormatPtn, usingRW, registerSelect, readWrite, enablePin1, enablePin2, dataBits, NUM_DB_PINS);
void setup(){
pinMode(13, OUTPUT); //we’ll use the debug LED to output heartbeat
lcd.init();
lcd.clear();
lcd.cursorTo(3,0); //select second displaycontroller, line 3, 4
lcd.init();
lcd.clear();
}
void loop(){
digitalWrite(13, HIGH); //light the debug LED
lcd.cursorTo(1,0);
lcd.printIn("WTF is up with this");
lcd.cursorTo(2,10);
lcd.printIn("Num of Lines: ");
char buf[3];
//lcd.printIn(itoa(charactersPerLine, buf, 16));
lcd.numberWrite(charactersPerLine);
lcd.cursorTo(3,0);
lcd.printIn("To Visual C++ I go.");
lcd.cursorTo(4,0);
lcd.printIn(itoa(25, buf, 16));
/* lcd.printIn("Debug: ");
lcd.debugVariables(); */
delay(1000);
lcd.cursorTo(1,0); // select first two rows
lcd.leftScroll(40, 80); //scroll first two rows
//lcd.cursorTo(3,0); //select second displaycontroller, line 3, 4
//lcd.leftScroll(40, 80); //scroll third and fourth row
delay(5000);
digitalWrite(13, LOW);
}
And I’ve zipped up and attached the current modification to the LCD4Bit library. Again, this is so not ready for anything serious. I need to add comments to the Wiring code and work a lot more on the library. I’ll work on all that.
My next major mod to the LCD4Bit code will be to get it working properly with a shift register. This is important as I need to keep Arduino pin usage to a bare minimum to ensure there is also room for Xbee, RFID, a keypad, and GPS.
Haha, this will definitely be interesting.
[...] started playing with my Arduino micro. Rewrote the LCD4Bit library to work with an old HD44780-based 40×4 character LCD I had laying around. [...]
Hey Michael. I just took a look at your site. Kewl stuff you are doing with remote lighting!
Good info. They must be something value. Thanks
bilgisayar tamiriweb tasar?m
web hostingtwindows hosting
linux hostinglinux web hosting
laptop tamirbilgisayar servis
notebook tamir
anakart tamir
web dizayn
e-ticaret
Very nice post. I just stumbled upon your blog and wished to say that I’ve really enjoyed surfing around your blog posts. After all I’ll be subscribing to your rss feed and I hope you write again soon!
Hello, I am a Web Developer and Mobile Hardware & Mobile Software expert.
I have been a full time internet Article writter for 4 years now.
I am grateful to be able to live the lifestyle I enjoy, thanks to the internet.
Can I post some Guest Article in your site?
Thanks for the library any changes? I am using a ks0066u uP for the LCD. It isn’t working with the regular LCD library