20x4 OLED Initialisation Problem?

I have got an 20x4 OLED display from NewHaven in the US.

It is HD44780 compatible so can be used with LiquidCrystal library.

However, sometimes when I plug it in, the information on there is show at the wrong line.

For example if I use this:

lcd.setCursor(0,0);
lcd.print(test);

Sometimes it is printed on the 1st line (position 0) sometimes the second line (position 1)

Any ideas?

Maybe it just does not support the complete set of calls of the LCD lib?

I don't know.

But if it's HD44780 compatible, then why shouldn't it?

It is easy to say something is compatible but it is harder to proof it ....

I see, fair enough!

M.

Do you have a link to the datasheet of the LCD? To check ...

Can you post a minimal sketch that shows this behavior?
It can also be a problem in the initialization, some LCD's have an externally 16x4 display but internally it is 20x4 so the intialization might go wrong.

Setcursor in the LiquidCrystal lib uses colum and row and hardcoded offsets which might not fit your display

void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
  int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
  if ( row > _numlines ) {
    row = _numlines-1;    // we count rows starting w/0
  }
  
  command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}

Here is the sketch:

 lcd.begin(4, 20);
   lcd.setCursor(0,0);
   lcd.print("Line Zero");
   lcd.setCursor(0,1);
   lcd.print("Line 1");

Link to datasheet: http://www.newhavendisplay.com/specs/NHD-0420DZW-AY5.pdf

It is HD44780 compatible so can be used with LiquidCrystal library.

The PDF does not mention HD44780 ....

It looks very nice but I see nowhere a HD44780 reference

The offsets in LCD.setcursor() seem to be OK - set DDRAM address -
and the LCD_SETDDRAMADDR define has a right value.

Have you connected it with 8 or 4 wires ? (I2C ?)

Please check the hardware/wiring if they connect well, a missing bit corrupts the commands ...

I'm sure the connections are fine.

I'm connecting it using 8 wires.

I called them all the way from the UK and asked them if it's compatible before buying, they said yes!

Hi everyone.

I managed to solve the above problem, now I've got another problem.

sometimes when I plug in the Arduino nothing shows up on the screen and other times garbage!

I have no idea why. Any ideas?

So what did you do to fix it? just in case some one else might run into the same problem.

RWW

lcd.begin(4, 20);

You are holding your display vertically - try turning it 90 degrees.

Fortunately this error won't currently cause any problems because all that the LiquidCrystal library does with the information is check to see if the second number is greater than 1. It could cause a problem in the future if they ever get around to expanding the library to account for things like the address offsets mentioned previously.

Don

sometimes when I plug in the Arduino nothing shows up on the screen and other times garbage!
I have no idea why. Any ideas?

This is a symptom of an LCD module that is improperly initialized.

I took a look at your data sheet and it appears to be HD44780 compatible EXCEPT for the instruction execution times. The Clear Screen instruction is only slightly longer than the Hitachi, the Return Home is actually shorter, but the real problem is with all the other instructions. The New Haven device is specified at 600uS whereas the Hitachi is 40 uS. Even if the 600 was supposed to be 60 it is still 50% longer than the Hitachi.

The LiquidCrystal library exclusively uses software time delays and those delays are geared to the Hitachi specifications. The New Haven data sheet recommends using the busy flag (which requires the use of LCD pin 5 (R/W). The current LiquidCrystal library does not use the busy flag even if you implement pin 5 so don't even try. I suggest that you check out the LiquidCrystal440 library (it may have a new name, search for it) which does implement the busy flag.

Don

Does the display work after pressing the reset button on the UNO ?

It maybe that you are using either or both pins 4 ,7 in your setup. Avoid those and see what happens.

It maybe that you are using either or both pins 4 ,7 in your setup. Avoid those and see what happens.

Why?

Don

See this thread -

Give it a try: Hookup a weak pullup to either pin 4 or 7 and plug the UNO into the USB.