Author Topic: NHD-0420DZW-AY5 and Arduino  (Read 120 times)

MikD

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
NHD-0420DZW-AY5 and Arduino
« on: November 02, 2017, 12:53:02 PM »
Hi

I have spent several hours, even days, trying to communicate properly and robustly with the NHD-0420DZW-AY5 from an Arduino Nano but in vain. Neither the standard Arduino way, nor third-party examples, nor trying from scratch myself and nor using this: http://www.newhavendisplay.com/app_notes/4_bit_character.txt seems to work, when converted as below (16 vs 20 char can hardly be the issue):

Code: [Select]
#define lcdRS      3   // D/I is P3.0
#define lcdRW     13   // WR is P3.7 ***GND***
#define lcdEnable  4   // E is P3.4  active LOW
#define lcdData4   9
#define lcdData5  10
#define lcdData6  11
#define lcdData7  12

char msg0[] = "Newhaven Display";
char msg1[] = "4-bit interface ";

void nybble()
{
    digitalWrite(lcdEnable, LOW);  // Reset P3.4  'E
    delay(1);                      // Waitms 1    'enable pulse width  >= 300ns
    digitalWrite(lcdEnable, HIGH); // Set P3.4    'E
}

void writeCom(byte val)
{
    digitalWrite(lcdData4, (val >> 4) & 1); // P1 = Com 'move data to Port 1
    digitalWrite(lcdData5, (val >> 5) & 1);
    digitalWrite(lcdData6, (val >> 6) & 1);
    digitalWrite(lcdData7, (val >> 7) & 1);
    digitalWrite(lcdRS, LOW);     // Reset P3.0 'RS = Instruction register
    nybble(); // Call Nybble 'write high 4 bits

    digitalWrite(lcdData4, val & 1); // Rotate Com , Left , 4  'rotate; P1 = Com 'move data to Port 1
    digitalWrite(lcdData5, (val >> 1) & 1);
    digitalWrite(lcdData6, (val >> 2) & 1);
    digitalWrite(lcdData7, (val >> 3) & 1);
    nybble(); // Call Nybble 'write low 4 bits
}

void writeData(byte val)
{
    digitalWrite(lcdData4, (val >> 4) & 1); // P1 = A
    digitalWrite(lcdData5, (val >> 5) & 1);
    digitalWrite(lcdData6, (val >> 6) & 1);
    digitalWrite(lcdData7, (val >> 7) & 1);
    digitalWrite(lcdRS, HIGH);     // Set P3.0  'RS = Data register
    nybble(); // Call Nybble

    digitalWrite(lcdData4, val & 1); // Rotate A , Left , 4, P1 = A
    digitalWrite(lcdData5, (val >> 1) & 1);
    digitalWrite(lcdData6, (val >> 2) & 1);
    digitalWrite(lcdData7, (val >> 3) & 1);
    nybble(); // Call Nybble
}

void setup()
{
    // Pin setup
    pinMode(lcdRS, OUTPUT);
    pinMode(lcdRW, OUTPUT);
    pinMode(lcdEnable, OUTPUT);
    pinMode(lcdData4, OUTPUT);
    pinMode(lcdData5, OUTPUT);
    pinMode(lcdData6, OUTPUT);
    pinMode(lcdData7, OUTPUT);

    // Communicate with LCD
    digitalWrite(lcdRS, HIGH);     // Set P3
    digitalWrite(lcdRW, LOW);      // Somewhat a contradiction to set P3!!!!!!!!!!
    digitalWrite(lcdEnable, HIGH);
    digitalWrite(lcdRS, LOW);     // Reset P3.0
    delay(100);                   // Waitms 100

    digitalWrite(lcdData4, HIGH); // A = &H30; P1 = A
    digitalWrite(lcdData5, HIGH);
    digitalWrite(lcdData6, LOW);
    digitalWrite(lcdData7, LOW);

    nybble();                     // Call Nybble 'wake up
    delay(100);                   // Waitms 100
    nybble();                     // Call Nybble 'wake up
    delay(10);                    // Waitms 10
    nybble();                     // Call Nybble 'wake up
    delay(10);                    // Waitms 10

    digitalWrite(lcdData4, LOW);  // A = &H20 ' 4-bit interface; P1 = A
    digitalWrite(lcdData5, HIGH);
    digitalWrite(lcdData6, LOW);
    digitalWrite(lcdData7, LOW);
    nybble();
   
    writeCom(0x28);  // Com = &H28 '4-bit 2 lines; P1 = A; Call WriteCom
    writeCom(0x10);  // Com = &H10 'cursor shift; Call WriteCom
    writeCom(0x0F);  // Com = &H0F 'display on; Call WriteCom
    writeCom(0x06);  // Com = &H06 'entry mode; Call WriteCom   

    writeCom(0x01);  // Com = &H01 'home; Call WriteCom   
    for (byte i = 0; i < 16; i++)  // Restore Dta1; For Count = 1 To 16; Next Count
    {
        writeData(msg0[i]);        // Read A; Call Writedata
    }

    writeCom(0xC0);  // Com = &HC0 '2nd line
    for (byte i = 0; i < 16; i++)  // Restore Dta1; For Count = 1 To 16; Next Count
    {
        writeData(msg1[i]);        // Read A; Call Writedata
    }
    delay(5);
}

void loop()
{
}

One thing that puzzles me using the above code from NHD is that it does now seem to follow the 4 bit procedure found in the data sheet p. 21. Furthermore, is it my observation that if the display has been improper communicated with the initialization procedure does not seem to work at all.

So I am looking for a bullet proof way of operating the display - please.
« Last Edit: November 02, 2017, 12:59:30 PM by MikD »

 

Questions regarding NHD‐0220DZW‐AY5 & NHD‐0420DZW‐AY5

Started by tseyfarthBoard OLEDs

Replies: 3
Views: 2875
Last post August 20, 2015, 09:51:26 AM
by Saurabh_B
Arduino LCD library not working with newhaven display NHD‐0420H1Z‐FL‐GWB-3V3

Started by c2hollowBoard Character LCDs

Replies: 9
Views: 8818
Last post July 10, 2014, 08:46:06 AM
by Michael_L
NHD‐0420DZW‐AB5 Lines

Started by RickJBoard OLEDs

Replies: 1
Views: 2280
Last post January 09, 2015, 04:18:32 PM
by Michael_L
NHD‐0420DZW‐AY5 SPI Interface

Started by vinaykBoard OLEDs

Replies: 0
Views: 2051
Last post October 26, 2015, 05:13:10 AM
by vinayk
NHD-0420DZW-AG5 - Display "sometimes" shows only 2 lines

Started by stylonurusBoard OLEDs

Replies: 5
Views: 5575
Last post June 18, 2014, 10:09:49 AM
by Michael_L