arduino BIG Digits 0-99 with i2c 16X2 LCD

in #utopian-io6 years ago (edited)

Introduction

This tutorial is an open source arduino project that teaches how to make a BIG digit numbers displaying on 16X2 i2c type Liquidcrystal display, the possible purpose of this lesson is you can make an analog 7 segment display using LCD and I am going to show you how to make a counter using this components.

20180221_144005.jpg

What will I learn?
  • how to make a Big numbers display using LCD 16X2
  • how to make an Digital counter using LCD
  • how to program a code on arduino Desktop IDE
  • how to connect all the components connection using diagram
  • HARDWARE

    Step 1: Gather all the Requirements

    Requirements

    20180221_143538.jpg

    • 16X2 LCD with IIC backpack
    • Breadboard (optional)
    • jumper wires
    • Type B usb cable
    • Arduino UNO R3 board
    • PC

    Difficulty

    • Basic arduino Project

    Tutorial Contents

    • Information about the 2 main components

    20180221_143618.jpg

    Gather all the components, The 16x 2 LCD with I2C module you will be able to connect the LCD with Arduino board with only two Data cables! The i2c module has a built in potentiometer bakpack for contrast adjustment. The 16x2 display is the set up LCD number of columns and rows ( 16 columns, 2 rows Display ).

    The arduino UNO R3

    20180221_143639.jpg

    has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. 32k Flash Memory
    source

    codes and programs can be uploaded on to it from the easy Arduino computer program. which makes it a very easy way to get started working with embedded electronics. The name R3 is the third, and latest version of Arduino Uno Board

    Experimental Procedures

    • Step 2: Build the circuit

    The 16X2 LCD display interfaces has 4 build in backpack pins (1) VCC it refers to the power signal of the LCD typically connected to 5volts, (2)GND or sometimes zero voltage, It is also the common connection of the LCD must connect to in one way or another path in order to complete the circuit. (3) SDA and (4) SCL is the i2c serial bus pin it is used to synchronize all data transfers over the I2C bus from the 16 pin of the normal LCD, Both SCL and SDA are connected to analog pin ouputs of the arduino beacasue i2c lines are open drain drivers, means is that the chip can drive its output low.

    U5dtqsMcFweBEB4pxkKhQ8g7Vs1gJBs_1680x8400.png

  • VCC - 5V
  • GND - GND
  • SCL - A4
  • SDA -A5
  • SOFTWARE

    • Step 3: Dowload the Software and Libraries

    If you’re ready to get started, click on the link below then select the version with your operating system.
    Dowload the arduino Desktop IDE: https://www.arduino.cc/en/Main/Software
    When the download is finished, un-zip it and open up the Arduino folder to confirm that click yes, there are some files and sub-folders inside. The file structure is important so don’t be moving any files around unless you really know what you’re doing.

    Download the liquidcrystal LCD library : https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library This library is a modified version of the H. Mario LiquidCrystal_I2C V.2.0 lib.

    • Step 4: Include libraries to arduino IDE

    Once installed the Arduino desktop IDE. open the software then locate the SKETCH tab at the top of the software, navigate ADD ZIP LIBRARY >> then look for the downloaded libraries in the download folder. SELECT the zip file then wait for the process. include all the libraries fo liquidcrystal display.

    add zip.png

    • Step 5: Programming

    Add Libraries at the first line of the code define the components library for the liquidcrytal i2c library, the wire h file is build in config on the IDE.

    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    include the type of LCD for 16X2 LCD with i2c backpack address is 0x27;

    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

    Build LCD Custom Character Generator using; http://maxpromer.github.io/LCD-Character-Creator/
    it support character lcd and create code for Arduino. once you set the charcter it will generate a binary data type for adruino code.

    generator.png

    Initialize the couner = 0

    int counter = 0;
    byte LT[8] =
    {
      B00111,
      B01111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };
    byte UB[8] =
    {
      B11111,
      B11111,
      B11111,
      B00000,
      B00000,
      B00000,
      B00000,
      B00000
    };
    byte RT[8] =
    {
      B11100,
      B11110,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };
    byte LL[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B01111,
      B00111
    };
    byte LB[8] =
    {
      B00000,
      B00000,
      B00000,
      B00000,
      B00000,
      B11111,
      B11111,
      B11111
    };
    byte LR[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11110,
      B11100
    };
    byte MB[8] =
    {
      B11111,
      B11111,
      B11111,
      B00000,
      B00000,
      B00000,
      B11111,
      B11111
    };
    byte block[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };

    At the void setup() function write the command that starts serial connection this method is ran once at the just after the Arduino is powered up. The lcd.begin(16,2) command set up the LCD number of columns and rows. For example, if you have an LCD with 20 columns and 4 rows (20x4) you will have to change this to lcd.begin(20,4). change the possition of the digits to right by changing the int col=9; to col=0.

    void setup()
    {
      lcd.begin(16,2);                      // initialize the lcd
      lcd.createChar(0,LT);
      lcd.createChar(1,UB);
      lcd.createChar(2,RT);
      lcd.createChar(3,LL);
      lcd.createChar(4,LB);
      lcd.createChar(5,LR);
      lcd.createChar(6,MB);
      lcd.createChar(7,block);
      // Print a message to the LCD.
      lcd.backlight();
       int temp = 10;
      lcd.clear();
      printDigits(0,0);
      printDigits(1,4);
      printDigits(2,8);
      printDigits(3,12);
    }
    void printNumber(int val){
         int col=9;    
         printDigits(val/10,col);
         printDigits(val%10,col+4);
    }

    At the he void loop() function this method you want to run the code over and over again. The lcd.print("--message--") command print a message to first column and row of lcd display. The lcd.setCursor(0,1) command will set cursor to first column of second row, change delay time of counter to (1000) equal to 1 second.

    void loop()
    {
       lcd.clear();
       printNumber( counter );
       counter++;
       if( counter >= 100) counter= 0;
       delay(500);
    }
    void custom0(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0); 
      lcd.write(1); 
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(3); 
      lcd.write(4); 
      lcd.write(5);
    }
    void custom1(int x){
      lcd.setCursor(x,0);
      lcd.write(1);
      lcd.write(2);
      lcd.print(" ");
      lcd.setCursor(x,1);
      lcd.write(4);
      lcd.write(7);
      lcd.write(4);
    }
    void custom2(int x){
      lcd.setCursor(x,0);
      lcd.write(6);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(3);
      lcd.write(4);
      lcd.write(4);
    }
    void custom3(int x){
      lcd.setCursor(x,0);
      lcd.write(6);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(4);
      lcd.write(4);
      lcd.write(5);
    }
    void custom4(int x){
      lcd.setCursor(x,0);
      lcd.write(3);
      lcd.write(4);
      lcd.write(7);
      lcd.setCursor(x, 1);
      lcd.print(" ");
      lcd.print(" ");
      lcd.write(7);
    }
    void custom5(int x){
      lcd.setCursor(x,0);
      lcd.write(3);
      lcd.write(6);
      lcd.write(6);
      lcd.setCursor(x, 1);
      lcd.write(4);
      lcd.write(4);
      lcd.write(5);
    }
    void custom6(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0);
      lcd.write(6);
      lcd.write(6);
      lcd.setCursor(x, 1);
      lcd.write(3);
      lcd.write(4);
      lcd.write(5);
    }
    void custom7(int x){
      lcd.setCursor(x,0);
      lcd.write(1);
      lcd.write(1);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.print(" ");
      lcd.print(" ");
      lcd.write(7);
    }
    void custom8(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(3);
      lcd.write(4);
      lcd.write(5);
    }
    void custom9(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.print(" ");
      lcd.print(" ");
      lcd.write(7);
    }
    void printDigits(int digits, int x){
      // utility function for digital clock display: prints preceding colon and leading 0
      switch (digits) {
      case 0: 
        custom0(x);
        break;
      case 1: 
        custom1(x);
        break;
      case 2: 
        custom2(x);
        break;
      case 3: 
        custom3(x);
        break;
      case 4: 
        custom4(x);
        break;
      case 5: 
        custom5(x);
        break;
      case 6: 
        custom6(x);
        break;
      case 7: 
        custom7(x);
        break;
      case 8: 
        custom8(x);
        break;
      case 9: 
        custom9(x);
        break;
      }
    }

    • Step 6: Upload the code to arduino board

    Connect the arduino board to type B usb cable on your computer make sure you choose the correct port and board type on the tools section of the software.

    SOURCE CODE

    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    int counter = 0;
    byte LT[8] =
    {
      B00111,
      B01111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };
    byte UB[8] =
    {
      B11111,
      B11111,
      B11111,
      B00000,
      B00000,
      B00000,
      B00000,
      B00000
    };
    byte RT[8] =
    {
      B11100,
      B11110,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };
    byte LL[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B01111,
      B00111
    };
    byte LB[8] =
    {
      B00000,
      B00000,
      B00000,
      B00000,
      B00000,
      B11111,
      B11111,
      B11111
    };
    byte LR[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11110,
      B11100
    };
    byte MB[8] =
    {
      B11111,
      B11111,
      B11111,
      B00000,
      B00000,
      B00000,
      B11111,
      B11111
    };
    byte block[8] =
    {
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111,
      B11111
    };
    void setup()
    {
      lcd.begin(16,2);                      // initialize the lcd
      lcd.createChar(0,LT);
      lcd.createChar(1,UB);
      lcd.createChar(2,RT);
      lcd.createChar(3,LL);
      lcd.createChar(4,LB);
      lcd.createChar(5,LR);
      lcd.createChar(6,MB);
      lcd.createChar(7,block);
      // Print a message to the LCD.
      lcd.backlight();
       int temp = 10;
      lcd.clear();
      printDigits(0,0);
      printDigits(1,4);
      printDigits(2,8);
      printDigits(3,12);
    }
    void printNumber(int val){
         int col=9;    
         printDigits(val/10,col);
         printDigits(val%10,col+4);
    }
    void loop()
    {
       lcd.clear();
       printNumber( counter );
       counter++;
       if( counter >= 100) counter= 0;
       delay(500);
    }
    void custom0(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0); 
      lcd.write(1); 
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(3); 
      lcd.write(4); 
      lcd.write(5);
    }
    void custom1(int x){
      lcd.setCursor(x,0);
      lcd.write(1);
      lcd.write(2);
      lcd.print(" ");
      lcd.setCursor(x,1);
      lcd.write(4);
      lcd.write(7);
      lcd.write(4);
    }
    void custom2(int x){
      lcd.setCursor(x,0);
      lcd.write(6);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(3);
      lcd.write(4);
      lcd.write(4);
    }
    void custom3(int x){
      lcd.setCursor(x,0);
      lcd.write(6);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(4);
      lcd.write(4);
      lcd.write(5);
    }
    void custom4(int x){
      lcd.setCursor(x,0);
      lcd.write(3);
      lcd.write(4);
      lcd.write(7);
      lcd.setCursor(x, 1);
      lcd.print(" ");
      lcd.print(" ");
      lcd.write(7);
    }
    void custom5(int x){
      lcd.setCursor(x,0);
      lcd.write(3);
      lcd.write(6);
      lcd.write(6);
      lcd.setCursor(x, 1);
      lcd.write(4);
      lcd.write(4);
      lcd.write(5);
    }
    void custom6(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0);
      lcd.write(6);
      lcd.write(6);
      lcd.setCursor(x, 1);
      lcd.write(3);
      lcd.write(4);
      lcd.write(5);
    }
    void custom7(int x){
      lcd.setCursor(x,0);
      lcd.write(1);
      lcd.write(1);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.print(" ");
      lcd.print(" ");
      lcd.write(7);
    }
    void custom8(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.write(3);
      lcd.write(4);
      lcd.write(5);
    }
    void custom9(int x){
      lcd.setCursor(x,0);
      lcd.write((byte)0);
      lcd.write(6);
      lcd.write(2);
      lcd.setCursor(x, 1);
      lcd.print(" ");
      lcd.print(" ");
      lcd.write(7);
    }
    void printDigits(int digits, int x){
      // utility function for digital clock display: prints preceding colon and leading 0
      switch (digits) {
      case 0: 
        custom0(x);
        break;
      case 1: 
        custom1(x);
        break;
      case 2: 
        custom2(x);
        break;
      case 3: 
        custom3(x);
        break;
      case 4: 
        custom4(x);
        break;
      case 5: 
        custom5(x);
        break;
      case 6: 
        custom6(x);
        break;
      case 7: 
        custom7(x);
        break;
      case 8: 
        custom8(x);
        break;
      case 9: 
        custom9(x);
        break;
      }
    }
    • Now, you can see the value of current counter digit displaying on the 2 row of the LCD.

    20180221_143900.jpg

    I hope this Tutorial might help you on your future activity, if you want t buy arduino components ansd learn how to use it, this website might help: https://www.sunfounder.com all images in this post is mine, i appreciate your time reading my post. if you have questions about this tutorial you can drop it below in the comment. thanks you. 21/02/2018



    Posted on Utopian.io - Rewarding Open Source Contributors

    Sort:  

    @lapilipinas, I like your contribution to open source project, so I upvote to support you.

    Awesome
    Keep posting
    And upvote me

    Thank you for the contribution. It has been approved.

    You can contact us on Discord.
    [utopian-moderator]

    Hey @lapilipinas I am @utopian-io. I have just upvoted you!

    Achievements

    • Seems like you contribute quite often. AMAZING!

    Suggestions

    • Contribute more often to get higher and higher rewards. I wish to see you often!
    • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

    Get Noticed!

    • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

    Community-Driven Witness!

    I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

    mooncryption-utopian-witness-gif

    Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

    Coin Marketplace

    STEEM 0.31
    TRX 0.14
    JST 0.039
    BTC 63653.32
    ETH 3485.56
    USDT 1.00
    SBD 4.83