Problem with 16x2 LCD display and Atmega328p

Hi folks. I'm new here. I'm working on a project for my Advanced Micro Controller Course at school. Part of the project is to have the arduino control a 16x2 LCD display. Now, previously this semester, we had an assignment to connect the LCD and run a simple message which I was able to do. Now that I'm completing the final project, I went to re-connect the LCD and run another message and no dice. For some reason the LCD display won't work. I've tried two different LCDs and various configurations of the pins.

Is this a sign of a busted board? For those who might be wondering, I am following all of the steps to initialize the LCD and program the pins. I have the header file included and the proper pin commands to make the LCD run. In fact, I tested out the LCD with the old program that I had used to complete the first task assigned to us earlier this semester. The LCD didn't work this time even though I was successful before.

Another note, the set-up that I'm using is to power the arduino with 4 AA batteries via the Vin pin on the board. According to the specs the board can take 6V but 7V is recommended. Initially this is how I tested the LCD and it didn't work. I then switched to USB power and the LCD still didn't work.

On a side note, something starting smoking in the battery pack while testing out the dc motors and other things while putting the project together. I thought, at the time, that it was a battery issue or that a small piece of wood (part of the project is wood) got caught in the battery pack. Perhaps I somehow shorted out my board? Would it be the board that is shorted or the chip? Tomorrow I'm going to write a simple code to set the pins high and low and check their output with a DMM. Aside from this, are there any other parts of the board that I should check?

Setup of the LCD display is as follows:
Pin 1 - Ground
Pin 2 - +5 V
Pin 3 - 10k resistor to +5 V (for contrast)
Pin 4 - RS - to pin 12
Pin 5 - R/W - Grounded
Pin 6 - Enable - to pin 2
Pin 11 - D4 - to pin 7
Pin 12 - D5 - to pin 8
Pin 13 - D6 - to pin 9
Pin 14 - D7 - to pin 10

Thanks for your help. I really appreciate it.

Pin 3 should be connected to the wiper of a 10k pot wired between Gnd and 5v. It should then be adjusted so you get blocks showing on the screen. This will work just with power on the board, and nothing will work until you get the blocks. It almost certainly won't work with a 10k resistor to 5V (all mine work at around the 1V on this pin), yours will have 5V or close to it.

pluggy...Thank you for your advice. I did that this morning and it worked. I'm going to have to review my past configuration of the LCD. I think that I might have, instead of a 10k pot, used two resistors between the ground and +5V to set the contrast. Thanks again for your help.

Actually, I just thought of another question, if that's alright.

I was wondering if anyone knows how much current the 5V pin on the Arduino can supply?

I know that each I/O pin can supply up to 40 mA and the 3.3V can supply 50 mA. Is it safe to assume that the 5V pin also supplies 40 mA?

From there, if I'm running the LCD, powering a L293D chip, and a Pololu QTR-8A line sensor array off of the 5V pin, am I pulling too much current or not getting enough current due to the pin's limitations? I have 3 other pins that are open that I can set high to provide current/voltage if need be.

Lastly, on the Arduino, is the ground pin that is on the digital pin side the same ground as the ones among the power pins? Thanks a bunch.

The current limit of the 5V pin will be determined first by the power source your using. If your running off USB then your limited to the 500mA that USB provides. If your running off the power connector then your limited to about 1A which i believe is the max the voltage regulator can offer. But the the power sourced plugged into there needs to be able to support that much current draw.

Using other pins on the board will not increase the available current. If you need more power you will need to use an external power source. Just be sure you have a common ground running between that external source and the Arduino.

The ground pins are the same. Ground on all devices are leading to the same place. The negative side of the power source. When designing any type of circuit you should always have a common ground. There are very few exceptions to this.

Hi Mem,

I am relatively new to Arduino Duemilanove platform, but have managed a few LED projects and now would like to learn how to display time on my 16x2 LCD.

I hooked up the LCD and Arduino circuits as follow:

  • LCD RS pin to digital pin 12
  • LCD Enable pin to digital pin 11
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • VSS pin to GND
  • VDD pin to +5V
  • Vo pin to 2.2kOhm then to GND for contrast purpose
  • RS pin to digital pin 11
  • R/W pin to GND

I managed to get "Hello World" displayed, but using both of the following codes, I don't get the time displayed on the 16x2 LCD Hitachi hd44780. Can please help me why my LCD isn't displaying the time?

#include <LiquidCrystal.h>          // lib. for LCD
#include <Time.h>

time_t elapsedTime;

//to restart the time counter to Zero:  setTime(0);

LiquidCrystal lcd(7,8,9,10,11,12);  // pins connected to LCD

void setup()
{
  lcd.begin(20,4);                   // open the LCD
}
void loop()
{
  elapsedTime = now();
  lcd.setCursor(0,2);                // sets cursor to 3rd line
  lcd.print("Hour ");
  lcd.print(hour(elapsedTime));
  lcd.print("   ");
  lcd.setCursor (0,3);               // sets cursor to 4th line
  lcd.print("DAYS ");             // elapsed days
  lcd.print(elapsedTime / SECS_PER_DAY);
  lcd.setCursor (0,1);               // sets cursor to 2nd line
  lcd.print(minute(elapsedTime));
  lcd.print(" min ");
  lcd.setCursor(0,0);               // sets cursor to 1st line
  lcd.print(second(elapsedTime));
  lcd.print(" SEC ");
}
 

[code]/* This sketch is basically a clock function even though it doesn't
 "tell" time.  I designed it to perform operations at a certain time
 of the day.  Depending on what time you start the program, you would
 have to adjust the time of the operation accordingly. (unless you want
 to start the program at midnight) I start by (Scount) counting milli-
 seconds, then (Mcount) minutes etc....  It prints to the LCD (4 x 20)
 sec, min, hrs, days.
 garym
 */
#include <LiquidCrystal.h>          // lib. for LCD

int Scount = 0;                     // count seconds                
int Mcount = 0;                     // count minutes
int Hcount =0;                      // count hours
int Dcount = 0;                     // count days
LiquidCrystal lcd(7,8,9,10,11,12);  // pins connected to LCD

void setup()
{
  lcd.begin(20,4);                   // open the LCD
}
void loop()

{
  lcd.setCursor(0,2);                // sets cursor to 3rd line
  lcd.print ("Hour ");
  lcd.print (Hcount);
  lcd.print ("   ");
  lcd.setCursor (0,3);               // sets cursor to 4th line
  lcd.print ("DAY ");
  lcd.print (Dcount);

  if ( Mcount == 60)                 // if Mcount is 60 do this operation
  {
    delay (32);                      // good place to fine tune timing
    Mcount = 0;                      // reset Mcount
    Hcount ++;
  }
  if (Hcount> 23)
  {
    Dcount++;
    Hcount = 0;                      // have to reset Hcount to "0" after 24hrs
  }

  lcd.setCursor (0,1);               // sets cursor to 2nd line
  lcd.print (Mcount);
  lcd.print (" min ");

  lcd.setCursor (0,0);               // sets cursor to 1st line
  lcd.print (Scount);
  lcd.print (" SEC ");

  if (Scount >59)                    // if 60 do this operation
  {
    Mcount ++;                       // add 1 to Mcount
    Scount = 0;                      // reset Scount
    delay (58);                      // changes ms per min

  }

  if (Scount < 60)                   // do this oper. 59 times  
    // to count the seconds
  {
    delay (988);                     // changing by one = 60 ms a min
    Scount ++;                       // add 1 to Scount
  }
}

Regards,
Yashar

I don't get the time displayed on the 16x2 LCD Hitachi hd44780.

What does that sketch display on the LCD?

Hi Paul,

Thanks for your reply, the LCD only displays black blocks. I don't have program code issue coz it is compiled and uploaded successfully.

Regards,
Yashar

Thanks for your reply, the LCD only displays black blocks.

If you mean black boxes on the top line it means that your LCD is not being initialized properly due either to improper wiring or bad code.

I don't have program code issue coz it is compiled and uploaded successfully.

The fact that your code compiled and uploaded properly means that it has the proper syntax. It does not mean that the instructions that you used will do what they were intended to do.

I would go back to the 'Hello World' sketch and get that working again to verify that you didn't mess up the wiring.

You really should separate the two sketches that you are having trouble with into two separate code boxes.

If you are using a 16x2 display why does your code try to display information on four different lines?

Don

Don,

Thanks for your feedback, it is working after changing the 20x4 to 16x2 and secondly the lcd (12, 11, 5, 4, 3, 2) was incorrect.

Thanks once again for your help.

Regards,
Yashar

Hi,

Can anyone tell me how to connect 16x2 LCD serially via USB to Arduino dumlin. ?

1- I need the circuit diagram,
2- I want to type text on PC and get displayed on LCD.

Regards,
Yashar

You can use I2C expander PCF8574. And the link is http://www.xs4all.nl/~hmario/arduino/LiquidCrystal_I2C/LiquidCrystal_I2C.zip

I see a problem in the arduino digital pin 11 of the pin will say rs rs pin lcd but lcd arrives a few lines say it goes to the arduino digital pin 12 which then connects the arduino to 11 or 12 " ?

the sketch have the errors:

sketch_nov14a:32: error: expected unqualified-id before '[' token
sketch_nov14a:47: error: redefinition of 'LiquidCrystal lcd'
sketch_nov14a:7: error: 'LiquidCrystal lcd' previously declared here
sketch_nov14a.cpp: In function 'void setup()':
sketch_nov14a:49: error: redefinition of 'void setup()'
sketch_nov14a:9: error: 'void setup()' previously defined here
sketch_nov14a.cpp: In function 'void loop()':
sketch_nov14a:53: error: redefinition of 'void loop()'
sketch_nov14a:13: error: 'void loop()' previously defined here
sketch_nov14a:81: error: 'Scount' was not declared in this scope

the sketch have the errors:

Posting the error messages without also posting the sketch will not get you too far.

Don

the sketch is posted by yashar i copy and paste in my arduino and the errors that the program show to me are those:

sketch_nov14a:32: error: expected unqualified-id before '[' token
sketch_nov14a:47: error: redefinition of 'LiquidCrystal lcd'
sketch_nov14a:7: error: 'LiquidCrystal lcd' previously declared here
sketch_nov14a.cpp: In function 'void setup()':
sketch_nov14a:49: error: redefinition of 'void setup()'
sketch_nov14a:9: error: 'void setup()' previously defined here
sketch_nov14a.cpp: In function 'void loop()':
sketch_nov14a:53: error: redefinition of 'void loop()'
sketch_nov14a:13: error: 'void loop()' previously defined here
sketch_nov14a:81: error: 'Scount' was not declared in this scope