Arduino + LCD works... some of the time?!?

I have an Arduino Mega 2560 and am using a Longtech Display LCM1602A Character LCD.
I am having a problem where my lcd works some of the time.
At first I thought it was my breadboard causing the problem but I checked all of the cables and the connections are fine. The cables are all connected to these pins on the arduino:

| RS | | RW | | EN | | DB4 | | DB5 | | DB6 | | DB7 |
| - | - | - | - | - | - | - |
| 52 | | GND | | 53 | | 50 | | 51 | | 48 | | 49 |

My code is attached, please help!!!
P.S. the delay is to give the lcd time to initialize!
EDIT: I also have the on board led blinking to confirm that the program is flowing correctly

LCM1602A.pdf (51.7 KB)

HelloWorld.pde (982 Bytes)

I am having a problem where my lcd works some of the time.

When does it work and when does it not work?

What does it do when it does not work?

You are telling us that your connections are good but without a photograph we cannot verify that.

Also (not related to your problem):
The comments at the beginning of your sketch do not agree with your code.
You don't need the initial delay (unless you got your display on Ebay for 49 cents).
You don't have to set the cursor to 0,0 immediately after initialization.

Don

My wires aren't the easiest to follow, but I will post a pic. I used a continuity checker to check the connections.
I know the comments don't agree, they are default an I didn't remove them
It would never work before the delay, and it is a very cheap display
I know I don't have to set the cursor, I just want to make my code bullet-proof

You might want to add a resistor to limit the current going to your LED back light.
I tested your code with my LCD display and it works fine even without the delay.
What happens when its not working?

When its not working it just displays the logic test (bottom row blocked) which makes me think its the data/rs/en pins but I move them to different pins and it doesn't change. And yes, I triple checked the solder job.

When its not working it just displays the logic test (bottom row blocked)

I don't understand this description at all.

Your photograph shows exactly what happens with an uninitialized LCD. There is a row of blocks on the top row and the bottom row is blank. This will occur with poor code, with bad wiring, or (rarely) with an LCD module with a very low (out-of-spec) clock speed. The last case can be fixed with delays but they typically have to be put in the library code, not in your sketch.

You still have not described when the display works and when it doesn't.
(1) After you apply power does it work for a while and then stop working?
(2) When you apply power does it (a) work some of the time and (b) not work other times?
(3) If (2a) is the situation then does it keep working as long as power is applied.

What happens if it is working and you press the Arduino reset?

What happens if it is not working and you press the Arduino reset?

Since works some of the time then your wires are in the correct locations but the breadboard connections could still be bad. You should try using a different location on the breadboard.

Don

Hey guys, sorry I never updated

I tracked the problem to a faulty LCD Controller. My only course of action is to replace it :frowning:

Your quick responses and readiness to help we're amazing. Thanks for all the help!

P.S. I did replace the screen and my code now works