How to change pins on an LCD

I am using an Arduino Mega. I am using a New Haven Display (PN#, NHD-0216K1Z-NSW-BBW-L) and it use to work but now it does not. All I did was change the pins and now it does not work. Same exact code except for the pin change. Here is my new code that does not work.

#include <LiquidCrystal.h>

//------------ initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 8, 3, 2);

void setup (){
   lcd.begin(16, 2);                           // LCD is a 16 by 2 character array

   lcd.setCursor(0, 0);
   lcd.print("Manufactured by:");  
}

My old code used this statement for the initialization. “LiquidCrystal lcd(2, 8, 9, 10, 11, 12);” How do I get my LCD to operate using different pins?

There should be no problem in changing the pins like this. Are other things using those pins? Have you wired it up correctly? Have you blown up any of those pins earlier?

I just checked the upload with another board. It works with my Mega ADK but not with my Mega 2560. I will check to see if one of the ports on the 2560 is fried. I guess I'll just write a quick loop that toggles all those pins at 1Hz and put an LED on each one to see if they are all working. And yes I am changing the board selection in the tool menu. Thanks for the quick reply.

Here is my new code that does not work.

Where is loop()? I believe it has to be present, even if it is empty.

Don

now it does not work

Can you explain that? Does it not light up, looks dead, prints wrong characters, or what. Are you just sending the one string once, or do you have in the loop also to send like ever second?

looks like you are using all the same pins(just rearranged), except pin 3 in now used, but wasn't before.

The backlight lights up. I can see blocks on the display so that part is getting power also. The blocks fade in and out when I adjust the POT connected for the contrast. I just checked all my pins with a scope and they are outputting signals. I works on my ADK Mega but not my Mega 2560.

I didn't see a url to the LCD. One may be helpful. Is it a shield (plugging it on top of the arduino), or are you running wires between? So the code, and LCD works one one arduino, but not the other? Hmmm

My old code used this statement for the initialization. "LiquidCrystal lcd(2, 8, 9, 10, 11, 12);" How do I get my LCD to operate using different pins?

Until you provide us with a picture or an accurate description of the interconnections between your LCD and your Arduino we cannot tell if you understand the significance of the numbers within the parentheses, specifically the significance of the order in which the numbers appear.

Of course it doesn't help that the author of the sketch, and the author of the example upon which it is based didn't explain this either. I think this is a bit more informative:

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

Don

Attached is my snippet of my schematic connection for the LCD.
Here is the code for pin setup.

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(12, 11, 10, 8, 3, 2 );

Here is the link to the display.
http://www.mouser.com/ProductDetail/Newhaven-Display/NHD-0216K1Z-NSW-BBW-L/?qs=%2Fha2pyFadujEgI3vbt6cm6Rm57Vr1NYnKeJ6ExmoEz%2FA8J9l88fazv79zjdzYbxt

LCD connections.JPG

It appears the wiring is correct. You say it works with one arduion, but not with the other. Is that running the arduion boards with only the display , or does one have other peripherals attached? When It does not work, what does it actually do/not do?

At this point, looks like the LCD is good. Looks like your sketch is good. Looks like your wiring is good., and at least one arduino board is good. It is getting narrowed down now. Did you get the pins checked on the questionable arduino board yet?

From your original post --> "All I did was change the pins and now it does not work."

Have you tried going back to the original configuration to see if it still works as it did before?

Don

The old config seems to not work with the Mega 2560 also. I checked all the pin (D0-D13) with a 1 Hz pulse programs. All the pins flashed the LED/resistor that I put on them. Pins seem to be fine. Th ADK Mega works and the Mega 2560 does not. I have no clue why.

Is that running the arduion boards with only the display , or does one have other peripherals attached?

Add the loop() function, and have it also send info to the lcd, ever so often (one second maybe).

Add the loop() function, and have it also send info to the lcd, ever so often (one second maybe).

I disagree. If you can't get the display to work with static information then sending it stuff over and over again will only make the troubleshooting harder.

So far we have only seen program fragments and a diagram of how he intends to connect the display. In order to provide decent help we have to see the actual circuit connections, the actual code used (all of it) with those connections, and the actual resulting display.

Don

I think the OP gave us his complete sketch in his first post, and it did not include a loop() function. It may not be the problem, but I see that some boards/systems, really do want the loop() to be there (even if empty). I was hoping he could add the loop(), and put in two or three lines to make the display continue to work. Can't hurt.

I think he also provided us the exact wiring diagram he is using (posted early today). It looked correct to me.

Still a mystery, but not for long (I hope). LOL

I think the OP gave us his complete sketch in his first post, and it did not include a loop() function.

And I told him about that in reply #3, but we don't know if he actually did put an empty loop() in to his sketch. Hence we need to see the complete code that he is now having a problem with so we can find out.

I think he also provided us the exact wiring diagram he is using (posted early today).

But we don't know that he implemented it properly. Hence we have to see the actual connections that he is now having a problem with so we can find out.

Don

Hi Don, Yea, it is hard to trouble shoot over the internet. We can ask questions, get answers. Sometime we suspect those answers are not really what we ask, but ! I think this OP is not a novice. He has provided answers with accuracy. He may know more than I do (not that much). And you are right, if the sketch has been updated, we need to see it. Isn't this forum fun. (not a pun, really).

My code is extremely long so it would not be good to post here (924 lines). Here is the jist of my code. Again I do not see how it can be the code if it works with the Mega ADK and not the Mega 2560.

// include the library code:
#include <LiquidCrystal.h>

//------------ initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(12, 11, 10, 8, 3, 2 ); 
void setup() {
    
   // set up the LCD's number of columns and rows: 
   lcd.begin(16, 2);                           // LCD is a 16 by 2 character array
   
   lcd.setCursor(0, 0);
   lcd.print("Manufactured by:"); 
}
void loop() {
lcd.setCursor(3, 1);
                                lcd.print(" Fahrenheit     ");
}

First of all you should delete the code from within loop() or move it to setup() since it will just drive the display bonkers the way you have it now. Leave the contents of loop blank between the brackets.

Then we also have to see how you connected your display to your Arduino. We need to see how you actually connected it, not how you proposed to connect it.

Don

Seems to be a disagreement about having something running in loop(), But What if the program is not running for some reason? I still think something should be put into loop() with a delay of about a second. Put both the print to lcd, and blink led so we can see if the sketch is running. Just my opinion.