SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By partypants69
#62100
Ok, so I bought an arduino and LCD among other things from spark fun, but I just can't seem to get the lcd to work properly. It display's garbage at first, but if I unplug and replug pin 12 (DB5 according to GDM1602K data sh**t) at the right time, it starts working. As a side not, I had to censor that dirty word that comes after "data" because of the stupid filter. Here is a link to a video showing what happens http://www.youtube.com/watch?v=7UeiREZZI60 and here is the source code i'm running:
Code: Select all
#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(2, 3, 4, 8, 9, 10, 11);
int test = 0;

void setup()
{
  Serial.begin(9600);
  lcd.print("Hello World!!");
}

void loop()
{
    // Print a message to the LCD.
    lcd.clear();
    lcd.setCursor(0,0);
  lcd.print("Hello");
  //Serial.println(test);
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,1);
  lcd.print("World");
  delay(1000);
  test++;
}
Hopefully someone can tell me if I am messing up, or if I need a new LCD.
User avatar
By bigglez
#62102
partypants69 wrote: Ok, so I bought an arduino and LCD among other things from spark fun, but I just can't seem to get the lcd to work properly.
It would help to give the part numbers of your
chosen purchases (or better yet, a link to the
SFE page for each).
partypants69 wrote:It display's garbage at first, but if I unplug and replug pin 12 (DB5 according to GDM1602K data sh**t) at the right time, it starts working. As a side not, I had to censor that dirty word that comes after "data" because of the stupid filter. Here is a link to a video showing what happens and here is the source code i'm running:
If the LCD module is not a serial data
type then the print command (to serial UART)
will not work.

If your LCD module is an industry standard
interface it requires special codes and data
to operate.
Code: Select all
Pin Signal
1    Vss
2    Vcc
3    Vee
4    RS
5    R/W
6    E
7    DB0
8    DB1
9    DB2
10   DB3
11   DB4
12   DB5
13   DB6
14   DB7
By jasonharper
#62103
partypants69 wrote:// 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(2, 3, 4, 8, 9, 10, 11);
The comments don't match the code here. Which matches the way the display is actually connected?
By partypants69
#62105
Sorry for not listing part numbers. This is the LCD.
Here is the Arduino.
As far as the code goes, I was working off of one of the examples and changed it around, so ignore the comments. The way it is in the actual code is the way it was hooked up.
User avatar
By FartingMonkey92
#62108
I've read a few problems like this one and many times it's because these displays take a while to initialize...
Maybe you wanna add a delay before you start communications with it...?
By partypants69
#62119
Thanks for the suggestion. I tried adding a 5 second delay in void Setup, still no luck.
User avatar
By bigglez
#62121
partypants69 wrote:Thanks for the suggestion. I tried adding a 5 second delay in void Setup, still no luck.
If you insist on sending serial data to your parallel
interfaced LCD module you should add this hardwarefirst.
By partypants69
#62122
Forgive me, I am new at this. I was under the impression that I was sending parallel data. Could you help explain what I am doing wrong?
User avatar
By bigglez
#62124
partypants69 wrote:Forgive me, I am new at this. I was under the impression that I was sending parallel data. Could you help explain what I am doing wrong?
Code: Select all
{ 
  Serial.begin(9600); 
  lcd.print("Hello World!!"); 
}
Looks like a serial instruction to me...
By partypants69
#62125
The Serial.begin(9600) was for sending a debug value via serial to my computer, so I could see that the program was running properly. Serial.println is the command that would do that. The Serial class should not be sending any data to the lcd.
User avatar
By FartingMonkey92
#62126
bigglez wrote:Looks like a serial instruction to me...
Yup, bigglez is right... I just plugged my "code brain" in and realized your sending serial commands to an LCD, with a parallel interface...
Failing that, just remove everything that isn't needed for the LCD to run and try again...
User avatar
By bigglez
#62128
partypants69 wrote:The Serial class should not be sending any data to the lcd.
Okay, but isn't this code continuously banging the LCD hardware?
Code: Select all
void loop() 
{ 
    // Print a message to the LCD. 
    lcd.clear(); 
    lcd.setCursor(0,0); 
  lcd.print("Hello"); 
  //Serial.println(test); 
  delay(1000); 
  lcd.clear(); 
  lcd.setCursor(0,1); 
  lcd.print("World"); 
  delay(1000); 
  test++; 
} 
The LCD will lock up if you send the data too fast or
for too long. Perhaps you should execute this code
once then stop your program until either a timeout
of several seconds or an interrupt (or reset)?

Also you need to give the LCD several hundred
milliseonds wait after sending a clear command
for the LCD module hardware to reset itself.

Have you read the datasheet for the LCD module yet?
By partypants69
#62129
I have read the datash**t, some of it I don't understand, but I have looked into how the timing should work. From what I understand, the delays needed should be part of the LiquidCrystal library. I read on another site that something in the library needed to be commented out, but I don't understand what.

As far as my code running to fast for the LCD, I don't think that's the problem. Did you watch the video? You can see that it starts working, and has no problem updating that quickly, it just starts out with garbage until i disconnect and reconnect pin 12.

Ok, so I tried some different code, an example from the library called SerialDisplay. Now this code is not outputting serial data to the LCD. It waits for serial input (from terminal) and then sends that to get displayed on the LCD. I tried it, and the first time I sent a string it came out as garbage. Than I disconnected pin 12 and sent it another time. This time it showed up as garbage, but it was a bit different. Then I plugged pin 12 back in and sent it again. This time it showed the correct text. All following times work properly.
Code: Select all
/*
 * Displays text sent over the serial port (e.g. from the Serial Monitor) on
 * an attached LCD.
 */

#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(2, 3, 4, 8, 9, 10, 11);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
    }
  }
}
User avatar
By bigglez
#62130
partypants69 wrote:From what I understand, the delays needed should be part of the LiquidCrystal library.
Code: Select all
LiquidCrystal()
Description
Creates a variable of type LiquidCrystal. 
Syntax
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7) 
Yet you have:
Code: Select all
#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(2, 3, 4, 8, 9, 10, 11); 
We don't know how you have assigned the IO pins.
Can you post a diagram (schematic) of your hardware?
We need to know that the Arduino and the LCD are
connected correctly before debugging your code.

Also, even if the library has the correct hardware
timing for the LCD controller IC, you can't just
keep sending commands without allowing more
time for the commands to work. The fact that you
can manipulate the hardware and get sensible results
suggests a timing violation (or just a hardware
error that happens to clear when you do so).
By partypants69
#62140
Here is a schematic. The green box is the arduino, the lines going to it show where they are connected even thought they are not attached all the way in the diagram.

Image