Introduction: LCD Trainer Kit
A few years back, I was introduced to the world of Arduino. I was fascinated by the fact that you can make things work with just typing in some lines of code. Do not like how it works? Change a few lines of code and there you have it. As soon as I got my first Arduino, like every other excited hobbyist, I tried each and every basic example circuits right from blinking an LED to displaying my name on a 16 x 2 LCD display. There are lots of tutorials on the internet along with the code. Just copy paste the code and your circuit is up and running. As time progressed I started playing with more complex components like OLED displays, sensors, etc.
After having some fun with Arduino, I realised that some things are not complete. What does lcd.print("Hello, World!") actually do? What does each pin of the display do? How does the microcontroller on the Arduino communicate with the display? We simply overlook this because a complex task of making a component like those to work is made simple for us with the help of a Library! A library is a collection of a predefined set of instructions. Most of the information is hidden in these libraries. When the main program reaches the function such as lcd.print, the program will jump into the library, look for the function and execute it. After execution, it returns back to the main program. In the above example, you might have come across such lines in the program #include . The library used here is LiquidCrystal.
Though the main program becomes small and easy to understand, it hides a lot of information and it can be confusing for newbies like us. So, in this Instructable let us try to run an LCD Display but WITHOUT a microcontroller! Yes, YOU are going to be the microcontroller. This will help us to know what all task a microcontroller does to display a text on the screen.
Let's get back to the basics!
Step 1: Things You Will Need
1) 16 x 2 LCD Display x1
2) SPDT Toggle switches x8
3) Momentary Push Button x1
4) Slide Switch x1
5) 1k Potentiometer x1
6) Micro USB breakout board x1
7) Project enclosure box x1
Step 2: Know Your LCD
The most commonly known 16 x 2 LCD Display in the hobby world will have 16 pins. We will be using the same display for the demonstration. Before going further, let us have a look at what each of the 16 pins does.
LOW - Connecting the pin to ground.
HIGH - Connecting the pin to +5V.
Pin 1: GND
Connect the pin to ground.
Pin 2: VCC
Connect the pin to +5V.
Pin 3: Contrast Adjust
The contrast of the LCD can be adjusted by providing a voltage to this pin between 0V and 5V. This can be done with the help of a potentiometer.
Pin 4: Register Select (RS)
The display has two registers viz. Data Register and Instruction Register which can be selected with the help of this pin. Pull the pin low to select instruction register and high to select data register.
The instruction register is used to send instructions such as initiate display, clear display, etc. while the data register is used to send ASCII characters on the screen.
Pin 5: Read/Write (R/W)
This pin allows you to write or read from the selected register. Pull the pin low to write or high to read.
Pin 7 to Pin 14: DB0 - DB7
These are the data bits from 0 to 7 which represent an 8-bit binary number.
Pin 6: Enable (E)
When you have set all the above pins as you want, a high to low pulse to this pin will feed all the information into the screen.
Pin 15: LED +5V
Pin 16: LED GND
The pins 15 and 16 are for the backlight LED. Connect pin 15 and 16 to +5V and GND respectively.
Step 3: Preparing the Enclosure and Layout
Choose a suitable project enclosure box. Mine has a dimension of 20x15x4 cm. Plan the layout of components to be installed on the box as shown in the picture. Be creative in choosing the layout as long as it is sensible. I actually reused this box which was originally used in some other project. It had some slots and holes already drilled and so I had to plan the layout according to it.
8x SPDT Toggle switches for D0 - D7.
1x Momentary Push Button for Enable
1x Slide Switch to select between Instruction and Data Register.
1x 1k Ohm Pot for Contrast.
Step 4: Time for Wiring
Refer to the schematic diagram attached here.
The USB micro breakout board has 5 terminals of which we will be using only two viz. VBUS (+5V) and GND since we are using USB only for power.
Connect all the upper terminals of toggle switches together as shown in the picture. This will be connected to GND. Likewise, connect all the bottom terminals together. This will be connected to +5V. Connect the first switch's middle terminal to D7 (pin 14) on LCD. Similarly, the middle terminal of the 2nd switch to D6 (pin 13) and so on till D0 (pin 7).
Connect any one terminal of the push button to +5V. Connect the other terminal to GND through a 1k resistor. Connect the same terminal to Enable (pin 6) on LCD. Connect a 100uF electrolytic capacitor across the switch with the negative side of the capacitor connected to the terminal with the resistor attached to it.
Connect the middle pin of the slide switch to pin 4 on LCD and the lower and upper terminal to +5V and GND respectively.
Connect the outer two terminals of the pot to +5V and GND respectively and the middle pin to Contrast adjustment (pin 3) on LCD.
Connect pins 1, 5 and 16 on LCD to GND
Connect pins 2 and 15 to +5V.
Step 5: Working
The actual LCD is controlled by an IC called HD44780U which can be seen as a black blob on the back of the LCD module. It is a Liquid Crystal Display Controller/Driver. The datasheet for this driver can be found here.
To get the LCD running, we have to go through a few steps. This includes initializing the LCD by giving some set of instructions followed by the actual data (characters). All the information can be found in the datasheet. But for now, I will give a quick demo on how to type HELLO! on the display.
Note: 0 means LOW (GND)
1 means HIGH (+5V)
First, turn ON the power. The backlight of the LCD should light up.
Step 1: As we will be sending Instructions, Instruction Register(IR) must be selected using the slide switch.
Step 2: Next, we will set the bits using the toggle switches as 00001111 as shown. This will turn ON the display, cursor and blinking of the cursor. Press enable push button. You should now be able to see the blinking cursor at the top left corner of the screen. Adjust the contrast using the pot if needed.
Step 3: Set the toggle switches as 00110000 as shown and press Enable. This will set the display to accept 8-bit data, enable first out of the two lines and set the font size to 5x8.
Step 4: Set the slide switch to Data Register (DR) so that we can now send some characters.
Refer to the document attached hereby to find out the bits for each character
Step 5: To display H, set the toggle switches to 01001000 and press enable. Repeat the same for every character.
Step 6: To display E, set the toggle switches to 01000101 and press enable.
Step 7: To display L, set the toggle switches to 01001100 and press enable twice.
Step 8: To display O, set the toggle switches to 01001111 and press enable.
Step 9: To display !, set the toggle switches to 00100001 and press enable.
Well done! You must now see HELLO! on the screen.
Step 6: Enjoy!
We just learnt that just to type in a few letters on the display there are a lot many steps involved in the process. In this way, we can learn what a microcontroller does to communicate with the displays. We just saw a few instructions out of the many. You can have fun with it and learn along the way!
Now we can understand how and why the libraries are created and also the hard work which goes behind the making of a library for a device.
Thank you for sticking till the end. Hope you all love this project and learnt something new today. Let me know if you make one for yourself. Subscribe to my YouTube channel for more upcoming projects. Thanks once again!
First Prize in the
Electronics Tips & Tricks Challenge