Alternatively, you can also drive the screen directly from the Raspberry Pi with the following connections:
LCD |
VSS |
VDD |
V0 |
RS |
RW |
E |
DB4 |
DB5 |
DB6 |
DB7 |
LCD Pin |
1 |
2 |
3 |
4 |
5 |
6 |
11 |
12 |
13 |
14 |
Raspberry Pi GPIO |
6 (GND) |
2 (5V) |
Contrast |
11 |
13 (GND) |
15 |
12 |
16 |
18 |
22 |
The preceding table lists the connections required between the Raspberry Pi and the HD44780-compatible, alphanumeric display module.
The contrast pin (V0) can be connected to a variable resistor as before (with one side connected to the 5 V supply and the other to GND); although, depending on the screen, you may find you can connect directly to GND/5 V to obtain the maximum contrast.
The wiringpi2 LCD library assumes that the RW pin is connected to GND (read only); this avoids the risk that the LCD will send data back if it is connected directly to the Raspberry Pi (this would be a problem since the screen is powered by 5 V and will send data using 5 V logic).
Ensure that you update the code with the new AF_XX references and refer to the physical pin number by changing the setup within the gpiosetup() function. We can also skip the setup of the MCP23017 device.
Have a look at the following commands:
wiringpi2.wiringPiSetup() wiringpi2.mcp23017Setup(AF_BASE,0x20)
Replace the preceding commands with the following command:
wiringpi.wiringPiSetupPhys()
You can see that we only need to change the pin references to switch between using the I/O expander and not using it, which shows how convenient the wiringpi2 implementation is.