16x2 OLED initiation issues

Hi All

I have recently bought myself an OLED 16x2 screen (model # WEH001602A). The datasheet for this OLED is attached. I have wired it as shown below:


I am using the Adafruit OLED library and the code I am testing is as follows:

#include <Adafruit_CharacterOLED.h>

Adafruit_CharacterOLED lcd(6, 7, 8, 9, 10, 11, 12);

void setup() 
{
  lcd.begin(16, 2);
  lcd.print("hello OLED World");
}

void loop() 
{
  lcd.setCursor(0, 1);
  lcd.print(millis()/1000);
 }

I have managed to get this code to work but when I upload the code or if I restart Arduino the screen is blank. I have to reset the board using the reset button a few times before the screen start showing the characters. Like I said it works fine once it starts working but I guess the screen is having an initiation issue. Could someone please suggest what could I do to get rid of this issue?

Regards
Taimoor

13203765800176363412.pdf (723 KB)

OK does your screen have a back light? That if so apply power to pins 15 (+5v) and 16 (gnd). The next issue I see is you dont have anything in the VO or pin 3 This is the contrast, it could cause you to not to be able to see the digits. Use a potentiometer set up as a voltage divider with the middle going to the pin 3. I dont have my laptop with me tonight so I cant double check the code to make sure the code calls out the pins in the right order. I dont remember mine going sequentially, but the data lines backwards should not stop it from working, it should only reverse the display.

Dom

Take a looky-see here.

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

This will show you the correct wiring and also the proper pinouts.

Dom

Hi Dom

Thanks for your reply. I am using an OLED display. It does not have a back light and Pin 3, 15 and 16 are NC. Hence it does not need a potentiometer.

Hoi Taimoor,

looks like an init-Failure (Timings) or may be also a power problem

I dont have my laptop with me tonight so I cant double check the code to make sure the code calls out the pins in the right order.

There is no such thing as ‘the right order’. Any available I/O Arduino pin can be used for any of the LCD signal lines. Judging from the constructor it appears that the same is true for the OLED library.

I dont remember mine going sequentially, but the data lines backwards should not stop it from working, it should only reverse the display.

I suppose that your clock also run backwards when you reverse its power connections.

Don

floresta:

I dont have my laptop with me tonight so I cant double check the code to make sure the code calls out the pins in the right order.

There is no such thing as 'the right order'. Any available I/O Arduino pin can be used for any of the LCD signal lines. Judging from the constructor it appears that the same is true for the OLED library.

I dont remember mine going sequentially, but the data lines backwards should not stop it from working, it should only reverse the display.

I suppose that your clock also run backwards when you reverse its power connections.

Don

Well not sure what arduino or other microprocessor you use but with mine if I don't list the pins in the right order in the software it doesn't work. As for the running backwards the smart @ss comment is not needed, I have not tried it yet but I would seem that the top and bottom lines may reverse. Or since the parallel data would not be in the right order then it would come up as garbage characters on the screen.

Dom

MDMassey: I have not tried it yet but I would seem that the top and bottom lines may reverse. Or since the parallel data would not be in the right order then it would come up as garbage characters on the screen.

They're yankin' your chain, but with very good reason.

Having the correct data connections is a prerequisite for commanding the display. Unless you get the commands correct, it simply will not initialise to display anything at all.

Well not sure what arduino or other microprocessor you use but with mine if I don't list the pins in the right order in the software it doesn't work

But you don't understand the concept of "the right order", and it is not entirely your fault.

The perpetrators of the tutorial and the sample programs are really stingy with their comments (as are most C programmers it seems). Most, if not all, of the confusion on this topic could have probably have been avoided with a simple comment or two in the sample code:

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);      // put your pin numbers here

As I said before "Any available I/O Arduino pin can be used for any of the LCD signal lines." All you have to do is put the pin numbers that you used on your Arduino into the argument of the constructor (the parentheses) in the order shown in the comment.

Don

As for the running backwards the smart @ss comment is not needed.

Some sort of comment was needed in order to keep your erroneous information from being repeated by others who might read this thread in the future. Nobody ever accused me of being diplomatic.

Don

Hi All

This is what the pins on the OLED are for:

The circuit diagram posted earlier has the following connections:

  • GND (pin 1) to GND
  • VDD (pin 2) to 5V
  • RS (pin4) to digital pin 6
  • R/W (pin 5) to digital pin 7
  • Enable (pin 6) to digital pin 8
  • D4 (pin 11) to digital pin 9
  • D5 (pin 12) to digital pin 10
  • D6 (pin 13) to digital pin 11
  • D7 (pin 14) to digital pin 12

Hope this helps to rid the confusion about the code. Like I said the code and the circuit is working fine but I seem to be having issues with display's initiation.

tyousaf: Like I said the code and the circuit is working fine but I seem to be having issues with display's initiation.

You cant have it both ways - it clearly is not working.

Try putting a "delay 200" in the loop.

Well to be honest the code is not working all the time. What I really meant to say was that code is correct when it works. I am assuming this is more of a hardware or library issue. I have tried putting a delay in the loop but it has not fixed the problem.

Put a delay 1000 as the first thing in the setup function to allow the chip in the oled display to stabilise before you write to it.

It seems that the basic underlying problem may be that the Adafruit library does not follow the recommendations in the datasheet.

The datasheet provides information about the maximum execution time required for each instruction and the Adafruit library uses delay times that are more than adequate, including the initial start-up delay mentioned by Mike.

The disparity is that, unlike the HD44780 datasheet, the datasheet provided for this display does not mention using time delays anywhere other than for the initial power-up, it specifically states that the busy flag should be checked before sending data to the display.

Don

I came across this thread on adafruit's discussion forum.

http://forums.adafruit.com/viewtopic.php?f=22&t=42179&start=15

I have checked my library and it already has the changes that have been put forward in this thread. I really like the display and want to use it in my project but it does not seem reliable enough.

Unfortunately, that Adafruit library appears to have been derived from the standard character LCD library, and contains the same bug. The bug is that the constructor calls init() and this in turn calls to pinMode, digitalWrite etc. But when the constructor is called, there is no guarantee that the rest of the Arduino software had been initialized (google "c++ static initialization fiasco" for the details). As if that isn't enough, init() calls begin(), which sends commands to the LCD. All this before the power supply is even stable.

The fix would be to change the constructor to store the pin numbers and do nothing else, and move all the init stuff to the begin() function. If necessary, you could also put a delay call in setup() prior to calling begin() to give the power time to stabilize. I can't guarantee that doing all this would fix the problem, but it's the first thing I'd try.