OLED 16x2 character display

"Plugh" worked pretty well, although I'm still in a maze of twisty little passages.

You can make the following mod to the "begin" function in LiquidCrystal.cpp (libraries folder) . . .

void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
  if (lines > 1) {
    _displayfunction |= LCD_2LINE;
  }
  _numlines = lines;
  _currline = 0;

  // for some 1 line displays you can select a 10 pixel high font
  if ((dotsize != 0) && (lines == 1)) {
    _displayfunction |= LCD_5x10DOTS;
  }

  // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
  // according to datasheet, we need at least 40ms after power rises above 2.7V
  // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50
  delayMicroseconds(50000); 
  // Now we pull both RS and R/W low to begin commands
  digitalWrite(_rs_pin, LOW);
  digitalWrite(_enable_pin, LOW);
  if (_rw_pin != 255) { 
    digitalWrite(_rw_pin, LOW);
  }
  
  //put the LCD into 4 bit or 8 bit mode
  if (! (_displayfunction & LCD_8BITMODE)) {
    // this is according to the hitachi HD44780 datasheet
    // figure 24, pg 46

// FOR OLED INIT - Runs before regular init - does not affect non-OLED
	write4bits(0x00);
    delayMicroseconds(4500); // wait min 4.1ms
	write4bits(0x00);
    delayMicroseconds(4500); // wait min 4.1ms
	write4bits(0x00);
    delayMicroseconds(4500); // wait min 4.1ms
	write4bits(0x00);
    delayMicroseconds(4500); // wait min 4.1ms
	write4bits(0x00);
    delayMicroseconds(4500); // wait min 4.1ms

	// FOR OLED INIT - must comment out the 3 0x03 commands . . .
    // we start in 8bit mode, try to set 4 bit mode
    //write4bits(0x03);
    //delayMicroseconds(4500); // wait min 4.1ms

    // second try
    //write4bits(0x03);
    //delayMicroseconds(4500); // wait min 4.1ms
    
    // third go!
    //write4bits(0x03); 
    //delayMicroseconds(150);

    // finally, set to 4-bit interface
    write4bits(0x02); 
  } else {
    // this is according to the hitachi HD44780 datasheet
    // page 45 figure 23

    // Send function set command sequence
    command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(4500);  // wait more than 4.1ms

    // second try
    command(LCD_FUNCTIONSET | _displayfunction);
    delayMicroseconds(150);

    // third go
    command(LCD_FUNCTIONSET | _displayfunction);
  }

  // finally, set # lines, font size, etc.
  command(LCD_FUNCTIONSET | _displayfunction);  

  // turn the display on with no cursor or blinking default
  _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF;  
  display();

  // clear it off
  clear();

  // Initialize to default text direction (for romance languages)
  _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT;
  // set the entry mode
  command(LCD_ENTRYMODESET | _displaymode);

}

Basically you send 5 (0x00) commands before the standard init and comment out the 3 (0x03) commands.

It needs work however. I see the following issues . . .

  • reset doesn't always work correctly
  • sometimes the line numbers get mixed up
  • the "createChar" function is not working and stops the display from working

I got the above info from NKC, and also a data sheet (attached). The data sheet also has a description of 4 bit init, but I've had no luck with it.

It's a gorgeous display. Highly visable, no contrast or backlight needed, low power.
I hope someone can get the kinks out.
(I was hoping to make an alternate init for this in the sketch and keep the LiquidCrystal lib in tact, but I had no luck with that approach.)

Winstar OLED Display Spec.pdf (1010 KB)