20x4 LCD: 2 rows on, 2 rows off

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I'm trying to simply display some text on a 20x4 LCD display. I did same thing many times before; however, this LCD has a strange behavior. It always shows below pattern.

No difference if I connect or disconnect RS, RW, E and D4..7 lines. I tried different contrasts (using PWM). Power source is 5V and GND lines of Arduino UNO (which is connected to USB).

Once I wrote a code to do these repeatedly:

  • clear screen
  • delay 250ms
  • print "Hello World"
  • delay 1000ms

And while running this code, sometimes first character (0,0) blinked by the same time pattern.

Any idea? LCD malfunctioning? Breadboard is kinda old but still OK.

LCD controller is hd44780 (as seller website said).

This topic has a solution.

Slow and Steady!

Last Edited: Sun. Oct 4, 2020 - 12:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

pajuhesh80 wrote:

Any idea? LCD malfunctioning? Breadboard is kinda old but still OK.

 

That display means that you have not initialised the display controller correctly. So it could be hardware or it could be software.

 

1) Show your schematic

2) Show your software

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pajuhesh80 wrote:

It always shows below pattern...

No difference if I connect or disconnect RS, RW, E and D4..7 lines...

I tried many HW/SW configurations. Always same thing happens. It is not from software because of the second sentence in above quote. Anyway, here's my code:

#include <avr/io.h>
#include "adelay.h"     //https://community.atmel.com/projects/accurate-delay-library-102
#include "hd44780.h"    //https://www.avrfreaks.net/projects/hd44780-library

int main(void)
{
    TCCR0A = 0b10000011;
    TCCR0B = 0b00000001;
    DDRD = 0xff;
    OCR0A = 50;
    lcd_init();
    while (1)
    {
        lcd_clrscr();
        Delay_ms(250);
        lcd_puts("Hello World!");
        Delay_ms(1000);
    }
}

hd44780_settings.h:

#ifndef HD44780_SETTINGS_H
#define HD44780_SETTINGS_H
//#define F_CPU                    16000000     // Set Clock Frequency - defined in adelay_settings.h
#define USE_ADELAY_LIBRARY       1
#define LCD_BITS                 4
#define RW_LINE_IMPLEMENTED      0
#define WAIT_MODE                0
#define DELAY_RESET              15
#if (LCD_BITS==8)
  #define LCD_DB0_PORT           PORTC
  #define LCD_DB0_PIN            0
  #define LCD_DB1_PORT           PORTC
  #define LCD_DB1_PIN            1
  #define LCD_DB2_PORT           PORTC
  #define LCD_DB2_PIN            2
  #define LCD_DB3_PORT           PORTC
  #define LCD_DB3_PIN            3
#endif
#define LCD_DB4_PORT             PORTB
#define LCD_DB4_PIN              2
#define LCD_DB5_PORT             PORTB
#define LCD_DB5_PIN              3
#define LCD_DB6_PORT             PORTB
#define LCD_DB6_PIN              4
#define LCD_DB7_PORT             PORTB
#define LCD_DB7_PIN              5
#define LCD_RS_PORT              PORTB
#define LCD_RS_PIN               0
#define LCD_RW_PORT              PORTC       // Port for RW line (ONLY used if RW_LINE_IMPLEMENTED=1)
#define LCD_RW_PIN               6
#define LCD_DISPLAYS             1
#define LCD_DISPLAY_LINES        4
#define LCD_E_PORT               PORTB
#define LCD_E_PIN                1
#if (LCD_DISPLAYS>=2)
  #define LCD_DISPLAY2_LINES     2
  #define LCD_E2_PORT            PORTC
  #define LCD_E2_PIN             5
#endif
#if (LCD_DISPLAYS>=3)
  #define LCD_DISPLAY3_LINES     2
  #define LCD_E3_PORT            PORTC
  #define LCD_E3_PIN             5
#endif
#if (LCD_DISPLAYS>=4)
  #define LCD_DISPLAY4_LINES     2
  #define LCD_E4_PORT            PORTC
  #define LCD_E4_PIN             5
#endif
#endif

Connection:

    LCD pin               Arduino UNO pin

 

    VSS                    GND

    VDD                    5V

    VO                       6

    RS                       8

    RW                      GND

    E                         9

    D0..3                   -

    D4..7                   10..13

    A                         5V

    K                         GND

Slow and Steady!

Last Edited: Sun. Oct 4, 2020 - 08:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Once LCD was powered and I was connecting and disconnecting data lines. Suddenly, line 2 started filling like a left to right progress bar and after it was filled, line 4 did the same thing!

Slow and Steady!

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is the "Power Up" pattern shown for that LCD controller. it persists until the Initialisation is completed.

 

I use a 6-line LCD version using that controller and often see 3 sets of the alternate Line of blocks /  Blank line pattern.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since you have a Uno,  I would use the Arduino libraries.   e.g.

//                RS,EN,D4,D5,D6,D7
LiquidCrystal lcd( 8, 9,10,11,12,13);

Connect pin #3 (VO) to GND via a 470R resistor.   If you don't have any resistors,  just connect VO straight to GND.

 

When you have verified that the LCD is working correctly we can show you how to use a C library in AS7.0

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried hd44780 library for Arduino IDE code example (File> Examples> hd44780> ioClass> hd44780_pinIO> HelloWorld) and modified it to match my connections. Also tried VO connection to GND. No Luck.

Slow and Steady!

Last Edited: Sun. Oct 4, 2020 - 08:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now I tested internal Arduino IDE LCD example (Examples> LiquidCrystal> HelloWorld).

Result: LCD went CRAZY!

Hard to explain its behavior: Random fast blinks, sometimes some random faded characters,...

Slow and Steady!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pajuhesh80 wrote:

I tried hd44780 library for Arduino IDE code example (File> Examples> hd44780> ioClass> hd44780_pinIO> HelloWorld) and modified it to match my connections. Also tried VO connection to GND. No Luck.

Change this line in example from

const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7;       // for all other devices

to

const int rs=8, en=9, db4=10, db5=11, db6=12, db7=13;       // for all other devices

If this does not work,  post a photo of your wiring.

 

David.

Last Edited: Sun. Oct 4, 2020 - 09:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pajuhesh80 wrote:

Now I tested internal Arduino IDE LCD example (Examples> LiquidCrystal> HelloWorld).

Result: LCD went CRAZY!

Hard to explain its behavior: Random fast blinks, sometimes some random faded characters,...

If you are using the example from https://www.arduino.cc/en/Refere... change it to:

 

#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup()
{
  lcd.begin(16,1);
  lcd.print("hello, world!");
}

void loop() {}

If this does not work,  post a photo of your wiring.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good News: LCD worked using ATmega32A.

Now I should check my Arduino as main target of project is mega328P.

Slow and Steady!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

pajuhesh80 wrote:
Good News: LCD worked using ATmega32A

So what did you do to get it working?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I found the problem:

Long time ago, I set CKOUT fuse of ATmega328P on my Arduino; thus, pin 8 I/O was simply disabled! blush

Now code in #3 works perfectly. (except that PWM on contrast causes some problem, it should be filtered or replaced by a potentiometer)

Slow and Steady!

Last Edited: Sun. Oct 4, 2020 - 12:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should not use PWM on contrast.   A simple 470R resistor should give a reasonable contrast.   Or try 470R, 390R, 330R, ...

 

You can use PWM on the backlight but make sure that there is a series resistor to limit the peak current to the AVR max current per GPIO pin.

In practice you want backlight either on or off.

 

I strongly advise you to "Burn Bootloader" on your Uno after you have been experimenting in AS7.0

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My Arduino has its bootloader and I use AVRDUDE to upload hex file to it.

Also, I want to be able to adjust contrast digitally (variable digital contrast).

Slow and Steady!

Last Edited: Sun. Oct 4, 2020 - 04:43 PM