Tearing my hair out - anyone got a Newhaven 20x4 OLED working?

I have searched every thread on the forum, and followed every link I can find online, and tried the various 'solutions'. I still am unable to get my NewHaven 20x4 OLED (NHD-0420DZW-AY5) working with my Arduino.

It seems the general concensus is that the LiquidCrystal.h library doesnt allow sufficient initiallisation time for this particular display. I have looked at others' customised libraries, tried serial wiring etc. but nothing I can find works. I am not competent enough to look at the .h and .cpp files and know what needs to be changed.

Does anyone have a working library, example sketch and wiring diagram that could put me out of my misery?

Did you find this page ?

Seems to have some quite clear instructions, addressing exactly this problem.

Hi MAS3 - yes spent a while trying to get this one to work - downloaded he supplied .h and .cpp files etc however the Arduino IDE just gaave many error messages when I tired to compile, saying tha tthe lirary file had (among other things) superfluous hashes etc. So as far as I can ascertain he .h file that is offered for download is somehow corrupted.

Does anyone have a working library, example sketch and wiring diagram that could put me out of my misery?

I asked NewHaven for a sample OLED module so I could work out the problems but they refused. I'm certainly not about to lay out my own cash to do their product support.

Don

I can't tell for sure for the errors reported to you, but things like these sometimes happen when one tries to use libraries and such that were designed for an older version of IDE (pre 1.0).
The page dates December 29, 2011, IDE 1.0 (which seems to be the threshold) dates November 30 2011.
So maybe this was developed for an older IDE.
I'd try to find an older version and see if that would work.

I can't verify if it works, but I've updated the library to build on both pre 1.x and 1.x
and also added and example sketch.
See the example for the Arduino pins. It uses the same pins as the LiquidCrystal Example
other than the library also needs the RW pin hooked up so that is an additional pin.

You can use the IDE to directly install the library using the attached .zip file.

--- bill

OLEDFourBit.zip (12.4 KB)

Thanks Bill - I'll give this a try at the weekend and let you know how I get on. Really appreciate the help regardless of the outcome.

Bill you are a legend. I now have a working OLED!

To anyone finding this thread and having the same challanges:

  • Download the files supplied by Bill
  • Download the product spec for your NewHaven OLED and note the pin numbers to ensure they are mapped correctly in the supplied example sketch (on NewHaven's specs 'E' is the pin to be used for 'EN' in the sketch)
  • Note that the OLED does not always initialise properly from a reset - only a hard reset (cycle power on/off) reliably initialises the display - something to consider in your end design

Thanks again for your help Bill - please accept many virtual beers on my behalf :slight_smile:

scifictus:

  • Note that the OLED does not always initialise properly from a reset - only a hard reset (cycle power on/off) reliably initialises the display - something to consider in your end design

Glad it is working.
Can you describe this in more detail?
as I'm sure this can be fixed/resolved, if you can help me understand
what is happening.

--- bill

BTW,
were you able to install it using the IDE and did the HelloWorld example work?

scifictus,
I went and actually looked at the library code.
It has some issues.
The 4 bit initialization sequence
is definitely wrong which is why it only reliably works from a power up reset.
It is amazing how few people really understand the hd44780 4 bit initialization sequence.
The main point of the sequence is to get the host and lcd back into nibble sync with each other.
His sequence only works if the device is in 8 bit mode, or is in 4 bit mode and already
in nibble sync.

I can work with you to fix it (as it should be a very simple fix)
but I'd prefer to work off line with you to get it resolved & tested so that only
the final working image is in this thread.
I'll also try to contact the original Author.

BTW, which IDE version are you working with?

Don,
Here is what I see:
Notice the nibble command sequence in his code:

  • 0x3
  • 0x2
  • 0x2
  • 0x8

which turns into either:
(if in LCD 8 bit mode)

  • function set 8 bit mode LCD sees: 0x30
  • function set 4 bit mode LCD sees: 0x20
  • function set 4 bit mode LCD sees: 0x28

(if LCD in 4 bit mode and in sync)

  • function set 8 bit mode LCD sees: 0x32
  • function set 4 bit mode LCD sees: 0x28

(if LCD in 4 bit mode but not in sync)

  • ???? LCD sees: 0x-3 (leftover upper nibble from previous command, lower nibble 3)
  • function set 4 bit mode LCD sees 0x22
  • sends a nibble of 0x8
    [ LCD and host are now hopelessly out of nibble sync with each other forever until LCD reset]

In order to fix this, the nibble command sequence must be:

  • 0x3
  • 0x3
  • 0x3
  • 0x2

As this sequence forces the LCD back to 8 bit mode and then into 4 bit mode
and is guaranteed to get the host and LCD in sync regardless of whether
the LCD is in 8 bit mode, 4 bit mode in sync, or 4 bit mode and out of sync
when the sequence starts.

One thing I don't understand is why this LCD wouldn't work with the standard LiquidCrystal
library that is included with the IDE?
Maybe it requires extended the a few of the delays on some of the commands?

Other issues in this library code:

delayMicroseconds(100000);

100,000 is too large as that function takes an unsigned int which is limited to 16 bits.
(I corrected the code to use a loop with a smaller value

The code is calling waitBusy() after sending
the command to the LCD when it should be before.

This explains the unnecessary delays in the init code after
each command() call in the begin() routine.

These all look like pretty simple fixes and the resulting library
should work on standard hd44780 displays as well.

--- bill

Thanks for the continuing support Bill.

I won't pretend to understand some of the detail in your posts but to answer your questions:

  • I am using IDE version 1.0.5r-2
  • I was able to install your supplied files via the IDE without any problems and HelloWorld worked straight out of the box once I had adjusted the assigned pin variables
  • Using the default LiquidCrystal library worked only very intermittently but almost always generated garbage on the display. Reading the other internet sources mentioned earlier, this appears to be attributed to the OLED display requiring longer delays within the initialisation sequence as it doesnt complete those actions as quickly as an LCD (I'm paraphrasing - badly!)
  • Hard/soft reset - using the reset button on the Arduino always generates the garbage display - only cycling the power on/off ensured that your supplied library properly initialised the display - no idea why this particular discrepency but again I have read that others experienced the same problem.

More than happy to work to resolve offline - let me know how you would like to proceed.