0

I am working with an Arduino due and currently using the Arduino liquid crystal library to display data on an LCD screen (mc42004A6wk-bnmlw) which uses the Hitachi HD44780 controller. The LCD has been update to v2 and is now using the Sitronix ST7066U controller.

From what I have read the two controllers are compatible and the liquid crystal library should work for both. I am using the same software and hardware setup as before but the screen will not display anything.

The software I use is quite complex so I moved to a simple hello world program (below) to test and I still have the same issues. Any advice would be greatly appreciated.

#include <LiquidCrystal.h>
#include <Arduino.h>

LiquidCrystal lcd(30, 31, 32, 33, 46, 47);

void setup() 
{

  pinMode(36,OUTPUT);

  digitalWrite(36, LOW);

  delay(5000);

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  lcd.clear();

  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() 
{

  delay(5000);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}
2
  • 2
    Did you adjust the contrast?
    – gre_gor
    Commented Feb 9, 2018 at 14:13
  • 1
    I did indeed, no luck. I think its a problem with how the liquid crystal library initializes the screen. Just cant nail down the reason. Commented Feb 12, 2018 at 9:50

2 Answers 2

0

Try using this code, I have edited some parts of your code so this should work.

#include <LiquidCrystal.h>

const int rs = 30, en = 31, d4 = 32, d5 = 33, d6 = 46, d7 = 47;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{

  pinMode(36, OUTPUT);
  digitalWrite(36, LOW);
  delay(5000);    //Its okay to use delay here since its in the setup() function and will run only once

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

For this Hello World sketch, avoid using delay(); statement in the void loop() as it is not good to use when you have the millis(); used.

If the above wont work, check your LCD Wiring, many problems usually arouse from wrong wirings. Also I may suggest you to use some cheap LCD I2C Backpacks as this will ease the coding and will use less wire and pins on your Arduino. Here is a example enter image description hereenter image description here

If your'e going to use a I2C LCD Backpack, here is a working sample code.

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN     13

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

// Creat a set of new characters
const uint8_t charBitmap[][8] = {
   { 0xc, 0x12, 0x12, 0xc, 0, 0, 0, 0 },
   { 0x6, 0x9, 0x9, 0x6, 0, 0, 0, 0 },
   { 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0, 0x0 },
   { 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0, 0x0 },
   { 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0, 0x0 },
   { 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0, 0x0 },
   { 0x0, 0x0, 0x0, 0x6, 0x9, 0x9, 0x6, 0x0 },
   { 0x0, 0x0, 0x0, 0xc, 0x12, 0x12, 0xc, 0x0 }

};

void setup()
{
   int charBitmapSize = (sizeof(charBitmap ) / sizeof (charBitmap[0]));

  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );

  //lcd.begin(16,2); 
  lcd.begin(20,4); // initialize the lcd 

   for ( int i = 0; i < charBitmapSize; i++ )
   {
      lcd.createChar ( i, (uint8_t *)charBitmap[i] );
   }

  lcd.home ();                   // go home
  lcd.print("LCD TESTER - BY:");  
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print ("ABBAS (PRJCT.ME)");
  delay ( 3000 );
}

void loop()
{
   lcd.home ();
   // Do a little animation by writing to the same location
   //for ( int i = 0; i < 2; i++ )
    for ( int i = 0; i < 4; i++ )
   {
      //for ( int j = 0; j < 16; j++ )
      for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 1 );
       for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 2 );
       for ( int j = 0; j < 20; j++ )
      {
         lcd.print (char(random(7)));
      }
      lcd.setCursor ( 0, 3 );

   }
   delay (200);
}
3
  • Hi EngrAbbas, thank you so much for the reply and code.Removing the delay has given me some progress. The screen is not printing correctly but is now printing random chars on screen such as "?/?/ooo|||" etc. I'm really starting to think that the liquid crystal library is not compatible with the screen. Using the previous version I have no issues, even when using delays and milli's. Commented Feb 12, 2018 at 9:43
  • I did notice that the controllers have different timing with regards to initialization. Do you think this could be causing the issue? Initializing by Instruction - Wait time after power on ST7066U = Wait time > 40mS , Hitachi HD44780 = Wait time > 15mS . Initializing by Instruction - Wait time after first function set ST7066U = Wait time > 37uS , Hitachi HD44780 = Wait time > 4.1mS Commented Feb 12, 2018 at 9:48
  • I had so many troubles with a 20x4 LCD that required numerous data lines. It would work once then I'd power it down & up again & it wouldn't work -- instead showing nothing. I checked all the wiring and tried it again and then got same result as @user1649972 with the random characters showing up. I thought I had fried the LCD. I ordered the I2C version (amzn.to/2MAOAjL). It is so much easier. But, I still wanted to see if my orig. LCD worked. I connected a line from each data line from the new I2C LCD to the old one and lo & behold, it worked!. If any data line isn't 100% it fails.
    – raddevus
    Commented Jun 18, 2018 at 20:38
0

So after further investigation into the IDE, Libraries, board manager, hardware etc I discovered what was causing the issue.

On the initial hardware design the hardware engineer placed a capacitor on the enable leg between the LCD screen and the microcontroller. I have no idea why as I have not seen this done in any wiring diagrams but removing it has done the trick. The V2 board now works with all the original code and libraries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.