How to tell which pins connected to the Arduino does exactly what to the LCD?

Greetings!
I'm new to community, and already have begun tweaking around with my Uno.

I came across this page, https://www.arduino.cc/en/Tutorial/LiquidCrystalSerialDisplay

Everything worked as expected, however, out of out curiosity,

In the code, this snippet is used: LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Sure, this snippet initializes the library with the number of the pins, but.. after going through the given code, I realized, how does the the Arduino know what pin does exactly what?
There are 6 pins that were initialized, so how does the Arduino plan out that which pins will send the data and which pins will do other stuff? (RS & E pins)

The code does not seem to be very intuitive about the assignment of the pins for particular tasks.

It would be cool if someone could explain the entire code in detail!
Thanks!

[PS, Im talking about the standard Hitachi LCD here!]

Perhaps if the perpetrators of the example program had included these comments you wouldn't have had to ask this question.

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);      // put your pin numbers here

Don

Ah I see!

However this creates yet another question;
What will happen if I jumble the numbers up?
Is there a proper predefined way of feeding in PIN numbers?

Thanks a ton Don!

McSuperbX1:
Ah I see!

However this creates yet another question;
What will happen if I jumble the numbers up?
Is there a proper predefined way of feeding in PIN numbers?

Thanks a ton Don!

What do you mean by jumble the pin numbers?

ieee488:
What do you mean by jumble the pin numbers?

In the snippet of code, LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Will it be fine if I jumble these numbers up? like (1, 4, 2, 3, 5, 12, 11)?
Im pretty sure this wont work out, as there must be some predefined way of entering the pin numbers, such
as data pins at the last, controlling pins in front, etc.

floresta:
Perhaps if the perpetrators of the example program had included these comments you wouldn't have had to ask this question.

//LiquidCrystal lcd(RS, E, D4, D5, D6, D7);

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);      // put your pin numbers here




Don

Yes, of course you can rearrange the Arduino pins if you want e.g.

//LiquidCrystal lcd(RS,  E, D4, D5, D6, D7);
LiquidCrystal   lcd( [color=red]3[/color], 11,  5,  4, [color=red]12[/color],  2);      // put your pin numbers here

I have moved the RS jumper wire to 3. And moved the D6 jumper wire to 12.

Your proposed wiring:

//LiquidCrystal lcd(RS, RW,  E, D4, D5, D6, D7);
LiquidCrystal   lcd([color=red] 1[/color],  4,  2,  3,  5, 12, 11);      // put your pin numbers here

Your choice of wiring RS to 1 is unwise. But only because it is the Serial TX pin.
And you have chosen a 7-argument constructor. i.e. the one that uses the RW pin.

Life is so much clearer when you line up the constructor arguments with descriptive names.

David.

david_prentice:
Life is so much clearer when you line up the constructor arguments with descriptive names.

Or simply stop using naked constants as parameters in the constructor, especially in the constructors of example code that is trying to demonstrate how to use the library.

The problem with the LiquidCrystal examples is that they describe the Arduino pins used in the comments at the top of the code then just plop in naked constants for the pins in the constructor with no explanation other than a single line comment:

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

Is not helpful since:

  1. They don't describe what the parameters represent
  2. to some people it isn't clear that the arguments are arduino pin numbers
    and the order of the parameters determines what arduino pin is connect to which hd44780 signal pin.

I prefer using const variables with descriptive names as well as better comments.
You can see this in the examples in my hd44780 library.
The hd44780_pinIO class uses the same constructor arguments as the LiquidCrystal library.
(Other than my library optionally supports backlight control)
Here is a link to such an example:

which does it like this:

const int rs=8, en=9, db4=4, db5=5, db6=6, db7=7;
hd44780_pinIO lcd(rs, en, db4, db5, db6, db7);

Another problem with the LiquidCrystal code is that they foolishly used really bad parameter names for the data pins in the 4 bit mode constructor. I would go so far as actually call them STUPID!
For example if you look at the LiquidCrystal.h header file to try to determine what the 4 bit mode constructor parameters mean, you will see this:

  LiquidCrystal(uint8_t rs, uint8_t enable,
 uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

Which is really really stupid since the parameters d0, d1, d2, and d3 represent the Arduino pin numbers for the hd44780 signals DB4, DB5, DB6, and DB7. They picked really STUPID names.

The combination of using stupid names in the constructor and having (IMO) poorly commented example code, can make things confusing, especially for less technical users and even for some of the more experienced users that go look at the header file to see the constructor arguments.
The only way to really verify the parameters is to walk through the source code in LiquidCrystal.cpp and see how they are used, which also requires some understanding of how the hd44780 interface and signal pins work, which is step too large for many Arduino users.

I created an issue for this but the Arduino team didn't seem to have much interest in updating the code or examples to correct it.

--- bill