Sunday 12 January 2020

Display Custom Characters on 16 x 2 LCD Display Module Using Arduino

January 12, 2020 0

This tutorial is about making/building your own characters/special images and then displaying them on character 16×2 lcd. Generating custom characters or special character images and displaying on lcds of any sizes (16×1,16×2,8×1,8×2,20×1,20×2,40×1,40×2 etc) is not a very hard task. One must go through the internal structure of lcd control set in order to know how the character lcd works? Once you know how the lcd works and what features it offers. Then you can easily build and display characters of your desire on lcd screen in a defined matrix.



    What are custom characters?

    Custom characters are self made characters which we design by our self. We have full control on designing them with some constraints which i will discuss later. Like if we want to display a smiley ðŸ™‚ on 16×2 lcd. We don’t have an ASCII character for smiley to display it on 16×2 lcd. Example of custom characters is below.  

    How custom characters are displayed on 16×2 lcd?

    Before beginning any further i recommend you to please take the 16×2 lcd display introduction tutorial. Tutorial will let you know about the pinout and internal structure of 16×2 LCD. (Click below)   

    16 × 2 LCD has an internal ​CG-RAM (Character Generated RAM) in which we can generate or create our custom character. The size of CG-RAM is 64 bytes. We can generate / place 8 characters of size 5 × 8 at a time in CG-RAM. We can also place 5 × 10 size characters in CG-RAM but only 4.
    5 × 8 represents the dimension of the matrix in which a particular character can be displayed. 5 represents the Number of Columns and 8 represents the Number of Rows in a matrix. 5 × 8 combined is a matrix size. Matrix is composed of pixels which we turn on and off to represent or make a character. For example to display a smiley ðŸ™‚ in 5 × 8 dimension individual pixels on and off will be same like below.   

    The above Binary or Hex values are then arranged in a byte array. Byte array is then placed in to CG-RAM of 16 × 2 LCD. Now when we want to display this smiley character on LCD screen we just call its address in CG-RAM and finally the character will appear on 16 × 2 LCD screen.

    Circuit Diagram 





    How to Generate Byte Code for Custom Characters


    1. Visit https://maxpromer.github.io/LCD-Character-Creator/
    2. Create the Character You Want
    3. Copy the byte char array code. Example : byte customChar[] = { B00000, B00000, B01010, B10101, B10001, B01010, B00100, B00000 };
    4. Paste the code accordingly in my source code and change the name accordingly. 

    Source Code 


       
     /*  
       
                Custom Characters  
            16 x 2 LCD Display with Arduino  
       
                 HarshTronics  
       
            For More :  
            https://www.harshtronic.blogspot.com  
            https://www.instagram.com/harshtronics  
              
     */  
       
     #include <LiquidCrystal.h>          // includes the LiquidCrystal Library   
     LiquidCrystal lcd(12, 11, 5, 4, 3, 2);    // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)   
     int contrast = 100;  
       
     byte s1[8]=                  // Array of bytes  
     {  
      B00000,                   // B stands for binary formatter and the 5 numbers are the pixels  
      B00000,   
      B01010,   
      B10101,   
      B10001,   
      B01010,   
      B00100,   
      B00000                     
        
     };  
       
     byte s2[8]={B00100,  
      B01110,  
      B01110,  
      B01110,  
      B11111,  
      B00000,  
      B00100,  
      B00000,};  
        
     byte s3[8]=  
     {  
      0b01110,  
      0b01110,  
      0b00100,  
      0b01110,  
      0b10101,  
      0b00100,  
      0b01010,  
      0b01010,};  
       
     byte s4[8]={B00100,B01010,B11111,B01010,B10101,B11011,B10001,};   
       
     byte s5[8]=  
     { B00000,  
      B01110,  
      B10001,  
      B10001,  
      B10001,  
      B01010,  
      B11011,  
      B00000,  
     };  
       
     byte s6[8] =   
     {  
      B00000,  
      B00000,  
      B01010,  
      B00000,  
      B10001,  
      B01110,  
      B00000,  
      B00000,  
     };  
     void setup() {   
      analogWrite(6,contrast);  
      lcd.begin(16,2);             // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display  
      lcd.createChar(1, s1);          // Create a custom character for use on the LCD. Up to eight characters of 5x8 pixels are supported  
      lcd.createChar(2, s2);  
      lcd.createChar(3, s3);  
      lcd.createChar(4, s4);  
      lcd.createChar(5, s5);  
      lcd.createChar(6, s6);  
     }  
     void loop()   
     {   
      lcd.clear();  
      lcd.setCursor(0,0);  
      lcd.print("Custom Character");  
        
      for(int i=5;i<11;i++)  
      {  
       lcd.setCursor(i,1);  
       lcd.write(i-4);  
       delay(500);  
      }   
       
      delay(50000);  
     }  
    

    Wednesday 25 December 2019

    Interfacing of 16 x 2 LCD Display Module with Arduino

    December 25, 2019 0
    In this Tutorial of Interfacing of 16 x 2 LCD Display with Arduino, we will learn how to connect an LCD (Liquid Crystal Display) to the Arduino board. LCD's like these are very popular and broadly used in electronics projects as they are good for displaying information like sensors data from your project, and also they are very cheap.





      Pinout of 16 x 2 LCD :

      Pin No:

      Pin Name:

      Description

      1

      Vss

      Ground pin connected to system ground

      2

      Vcc

      Powers the LCD with +5V (4.7V – 5.3V)

      3

      VE

      Decides the contrast level of display i.e. dimming the brightness or increasing the brightness of LCD. Grounded to get maximum contrast.

      4

      RS

      There are two very important registers inside the LCD. The RS pin is used for the selection of these registers. If RS = 0, the instruction command code register is selected, which allows the user to send commands for the LCD such as clear display, cursor at home, and so on. If RS = 1, the data register is selected. It allows the user to send data that is to be displayed on the LCD.

      5

      R/W

      This pin toggles the display among the read or writes operation, and it is connected to a microcontroller unit pin to get either 0 or 1 (0 = Write Operation, and 1 = Read Operation).

      6

      E

      Sends data to data pins when a high to low pulse is given; Extra voltage push is required to execute the instruction and EN(enable) signal is used for this purpose. This pin should be held high to execute Read/Write process, and it is connected to the microcontroller unit & constantly held high.

      7

      D0

      Data pins 0 to 7 forms a 8-bit data line. They can be connected to Microcontroller to send 8-bit data.

      These LCD’s can also operate on 4-bit mode in such case Data pin 4,5,6 and 7 will be left free.

      8

      D1

      9

      D2

      10

      D3

      11

      D4

      12

      D5

      13

      D6

      14

      D7

      15

      A

      Backlight LED pin positive terminal

      16

      K

      Backlight LED pin negative terminal

       

       



      Features of 16 x 2 LCD Module :

      • Operating Voltage is 4.7V to 5.3V.
      • Current consumption is 1mA without backlight.
      • Alphanumeric LCD display module, meaning can display alphabets and numbers.
      • Consists of two rows and each row can print 16 characters.
      • Each character is build by a 5×8 pixel box.
      • Can work on both 8-bit and 4-bit mode.
      • It can also display any custom generated characters.
      • Available in Green and Blue Backlight.

      Components Required :

      1 x Breadboard ( FlyRobo : http://bit.ly/2rwkVT3 ; Robu.in : http://bit.ly/2PrO9dU )
      1 x Arduino Uno ( FlyRobo : http://bit.ly/2rwkVT3 ; Robu.in : http://bit.ly/2PrO9dU )
      1 x (16 x 2 LCD Module) ( FlyRobo : http://bit.ly/2PRH5IQ ; Robu.in : http://bit.ly/2MsCBX3 )
      Jumper Cables  ( FlyRobo : http://bit.ly/2qzBQ6L ; Robu.in : http://bit.ly/2LzGwRq )
      Arduino USB Cable

      Circuit Diagram :


      LCD PIN

      ARDUINO PIN

      Vss

      GND

      Vdd

      5V

      V0

      D6

      RS

      D12

      RW

      GND

      E

      D11

      D0

      -

      D1

      -

      D2

      -

      D3

      -

      D4

      D5

      D5

      D4

      D6

      D3

      D7

      D2

      A

      5V

      K

      GND

       



      Source Code :


         
       /*  
         
              16 x 2 LCD Display with Arduino  
         
                   HarshTronics  
         
              For More :  
              https://www.harshtronic.blogspot.com  
              https://www.instagram.com/harshtronics  
                
        */  
         
       #include <LiquidCrystal.h>            // includes the LiquidCrystal Library   
       LiquidCrystal lcd(12, 11, 5, 4, 3, 2);      // Creates an LC object Parameters: (RS, E, D4, D5, D6, D7)   
       int contrast = 100;  
         
       void setup()   
       {   
        analogWrite(6,contrast);  
        lcd.begin(16,2);                         // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }   
       }  
         
       void loop()   
       {   
        lcd.setCursor(3,0);   
        lcd.print("Welcome to");               // Prints "Welcome to" on the LCD   
        delay(3000);                           // 3 seconds delay   
        lcd.setCursor(2,1);                    // Sets the location at which subsequent text written to the LCD will be displayed   
        lcd.print("HarshTronics");            // Prints "HarshTronics" on the LCD  
        delay(3000);                          // 3 seconds delay   
        lcd.clear();                          // Clears the display   
         
        lcd.setCursor(4,0);  
        lcd.print("Arduino");                 // Prints "Arduino" on the LCD   
        delay(3000);                         // 3 seconds delay   
        lcd.setCursor(2,1);                  // Sets the location at which subsequent text written to the LCD will be displayed   
        lcd.print("LCD Tutorial");   
        delay(3000);   
        lcd.clear();                        // Clears the display   
         
        lcd.setCursor(0,0);   
        lcd.print("Subscribe on");  
        lcd.setCursor(3,1);   
        lcd.print("Youtube");   
          
        for (int positionCounter = 0; positionCounter < 4; positionCounter++)   
        {  
         lcd.scrollDisplayRight();        // scroll one position right  
         delay(1000);  
        }  
          
        for (int positionCounter = 4; positionCounter > 0; positionCounter--)   
        {  
         lcd.scrollDisplayLeft();        // scroll one position left  
         delay(1000);  
        }  
          
        lcd.clear();  
         
        for(int i=0;i<=7;i++)  
        {  
         lcd.setCursor(i,0);  
         lcd.blink();                   //Displays the blinking LCD cursor   
         delay(1000);  
        }   
         
        lcd.noBlink();                 // Turns off the blinking LCD cursor   
          
        for(int i=7;i<=15;i++)  
        {  
         lcd.setCursor(i,0);  
         lcd.cursor();                // Displays an underscore (line) at the position to which the next character will be written   
         delay(1000);   
        }  
          
        lcd.noCursor();               // Hides the LCD cursor   
        lcd.clear();                  // Clears the LCD screen   
       }  
         
       /*  
                   HarshTronics  
         
              For More :  
              https://www.harshtronic.blogspot.com  
              https://www.instagram.com/harshtronics  
                
        */  
      



      Feel free to ask any question in the comments section below.

      Saturday 21 December 2019

      Introduction to 16 x 2 LCD Display Module

      December 21, 2019 0

      What is LCD and 16 x 2 LCD Module ?


      The term LCD stands for liquid crystal display. It is one kind of electronic display module used in an extensive range of applications like various circuits & devices like mobile phones, calculators, computers, TV sets, etc. These displays are mainly preferred for multi-segment light-emitting diodes and seven segments. The main benefits of using this module are inexpensive; simply programmable, animations, and there are no limitations for displaying custom characters, special and even animations, etc.


      The 16×2 translates o a display 16 characters per line in 2 such lines. In this LCD each character is displayed in a 5×7 pixel matrix.





      Features of 16×2 LCD module :

      • Operating Voltage is 4.7V to 5.3V.
      • Current consumption is 1mA without backlight.
      • Alphanumeric LCD display module, meaning can display alphabets and numbers.
      • Consists of two rows and each row can print 16 characters.
      • Each character is build by a 5×8 pixel box.
      • Can work on both 8-bit and 4-bit mode.
      • It can also display any custom generated characters.
      • Available in Green and Blue Backlight.


      Pin Configuration :


      Pin No:

      Pin Name:

      Description

      1

      Vss

      Ground pin connected to system ground

      2

      Vcc

      Powers the LCD with +5V (4.7V – 5.3V)

      3

      VE

      Decides the contrast level of display i.e. dimming the brightness or increasing the brightness of LCD. Grounded to get maximum contrast.

      4

      RS

      There are two very important registers inside the LCD. The RS pin is used for the selection of these registers. If RS = 0, the instruction command code register is selected, which allows the user to send commands for the LCD such as clear display, cursor at home, and so on. If RS = 1, the data register is selected. It allows the user to send data that is to be displayed on the LCD.

      5

      R/W

      This pin toggles the display among the read or writes operation, and it is connected to a microcontroller unit pin to get either 0 or 1 (0 = Write Operation, and 1 = Read Operation).

      6

      E

      Sends data to data pins when a high to low pulse is given; Extra voltage push is required to execute the instruction and EN(enable) signal is used for this purpose. This pin should be held high to execute Read/Write process, and it is connected to the microcontroller unit & constantly held high.

      7

      D0

      Data pins 0 to 7 forms a 8-bit data line. They can be connected to Microcontroller to send 8-bit data.

      These LCD’s can also operate on 4-bit mode in such case Data pin 4,5,6 and 7 will be left free.

      8

      D1

      9

      D2

      10

      D3

      11

      D4

      12

      D5

      13

      D6

      14

      D7

      15

      A

      Backlight LED pin positive terminal

      16

      K

      Backlight LED pin negative terminal

       

       



      LCD Commands :

      Sr.No.

      Hex Code

      Command to LCD instruction Register

      1

      01

      Clear display screen

      2

      02

      Return home

      3

      04

      Decrement cursor (shift cursor to left)

      4

      06

      Increment cursor (shift cursor to right)

      5

      05

      Shift display right

      6

      07

      Shift display left

      7

      08

      Display off, cursor off

      8

      0A

      Display off, cursor on

      9

      0C

      Display on, cursor off

      10

      0E

      Display on, cursor blinking

      11

      0F

      Display on, cursor blinking

      12

      10

      Shift cursor position to left

      13

      14

      Shift cursor position to right

      14

      18

      Shift the entire display to the left

      15

      1C

      Shift the entire display to the right

      16

      80

      Force cursor to beginning ( 1st line)

      17

      C0

      Force cursor to beginning ( 2nd line)

      18

      38

      2 lines and 5×7 matrix

       



      COMPONENT DATASHEET

         16 x 2 LCD Datasheet