Newhaven Display Forum

Newhaven Products => Character LCDs => Topic started by: c2hollow on July 08, 2014, 01:44:44 PM

Title: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: c2hollow on July 08, 2014, 01:44:44 PM
Assuming that my code for controlling the NHD‐0420H1Z‐FL‐GWB-3V3 is the reason that it isn't working, I plugged it into a breadboard and attempted to get the Arduino LCD example working:

http://arduino.cc/en/Tutorial/LiquidCrystal

However, nothing is happening. Is there anything nonstandard about the LCD controller chip in this module?
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: Michael_L on July 08, 2014, 05:06:45 PM
This display does work with the Arduino LCD library.  What voltage do you have connected to pin 3?
I just loaded this code on my Arduino Uno and connected to the display in 4-bit mode and it worked:
Code: [Select]
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  // RS connected to Arduino digital pin 12
                                        // E  connected to Arduino digital pin 11
                                        // R/W connected to Ground
                                        // DB4 connected to Arduino digital pin 5
                                        // DB5 connected to Arduino digital pin 4
                                        // DB6 connected to Arduino digital pin 3
                                        // DB7 connected to Arduino digital pin 2
void setup()
{
  lcd.begin(8, 2);                      // 8 columns, 2 rows
}

void loop()

  lcd.clear();                          //clear LCD and set cursor for upper-left corner
  lcd.setCursor(0,0);                   //set cursor for column 0, row 0
  lcd.print(" Hello");
  lcd.setCursor(0,1);                   //set cursor for column 0, row 1
  lcd.print(" World!");
  delay(1000);                          //delay for 1000ms (1 second)
  lcd.clear();
  lcd.setCursor(0,0);                   //set cursor for column 0, row 0
  lcd.print("Newhaven");
  lcd.setCursor(0,1);                   //set cursor for column 0, row 1
  lcd.print("Display");
  delay(1000);
}
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: c2hollow on July 08, 2014, 05:10:35 PM
Should the logic voltage supply be going into the 5V line or the 3.3V line?
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: Michael_L on July 08, 2014, 05:14:52 PM
This display is a 3.3V display so it should be powered as such, however, the Arduino Uno does not provide 3.3V logic.  I have an Arduino with a swapped voltage regulator (3.3V), but I have used 5V logic before and it still works to show something on the LCD (not recommended for extended use).  For this purpose, you may connect it to the 5.0V supply.

Have you checked what voltage you are putting on pin 3?
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: c2hollow on July 08, 2014, 05:50:38 PM
What happens if you run the module at 5V for too long? is there an easy way to test whether the module has gone bad?
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: Michael_L on July 09, 2014, 07:57:22 AM
I have never tested this before, but since 5V is outside the maximum rating, after many hours of use it could ruin the controller.  The only way to test if the module is functioning is to power it up and write characters to it.
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: c2hollow on July 09, 2014, 02:36:21 PM
I got the arduino HelloWorld example working (but only with 4 pins, not 8-pin operation). Turns out I was getting pins 1-8 mixed up with pins 7-16.

However, the sample code you provided in the other forum thread only occasionally print the correct message, and then otherwise print gibberish. The arduino helloWorld code prints gibberish in 8-bit mode.
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: c2hollow on July 09, 2014, 02:48:00 PM
To be specific, it only prints characters from the upper 4 bit 0110 and 0111 rows, and the lower 4 bit rows where bit 4 and bit 5 are 1.

How bizarre.
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: c2hollow on July 09, 2014, 03:04:51 PM
hmm I modified the original code you sent me so that it operates in 4 bit mode:
Code: [Select]
// R/W signal is tied to ground (always write, never read)

int RS = 11;   //RS signal connected to digital pin 30 of Arduino Mega2560
int E = 12;    //E signal connected to digital pin 30 of Arduino Mega2560

const char text1[] = {"Newhaven Display"};
const char text2[] = {" Character LCD  "};

void command(char c)

   digitalWrite(RS, LOW);
   PORTD = c;
   digitalWrite(E, HIGH);
   delay(1);
   digitalWrite(E, LOW);
   c = c<<4;
   PORTD = c;
   digitalWrite(E, HIGH);
   delay(1);
   digitalWrite(E, LOW);
}

void command8(char c)

   digitalWrite(RS, LOW);
   PORTD = c;
   digitalWrite(E, HIGH);
   delay(1);
   digitalWrite(E, LOW);
}

void data(char d)
{
   digitalWrite(RS, HIGH);
   PORTD = d;
   digitalWrite(E, HIGH);
   delay(1);
   digitalWrite(E, LOW);
   d= d<<4;
   PORTD = d;
   digitalWrite(E, HIGH);
   delay(1);
   digitalWrite(E, LOW);
}

void Home()
{
   command(0x01);
   delay(5);
}

void nextline()
{
   command(0xC0);
}

void disp_pic()
{
   int i;
   Home();
   for (i=0;i<16;i++)
   {
      data(text1[i]);
   }
   nextline();
   for (i=0;i<16;i++)
   {
      data(text2[i]);
   }
}

void setup()
{
   DDRD = 0xFF;    //set PORTA as output
   PORTD = 0x00;   //initialize PORTA to 0x00
   pinMode(RS, OUTPUT);
   pinMode(E, OUTPUT);
   digitalWrite(E, HIGH);
   delay(40);
   command8(0x30);
   delay(5);
   command8(0x30);
   delay(5);
   command8(0x30);
   delay(5);
   command(0x28);
   command(0x10);
   command(0x0F);
   command(0x06);
   delay(5);
}

void loop()

  disp_pic();
  delay(5000);
}
and now it works perfectly fine...
Title: Re: Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3
Post by: Michael_L on July 10, 2014, 08:46:06 AM
I'm glad you got it working!  Thank you for sharing!