Arduino Tutorial

By LiterallyTheOne

3: LCD and Keypad

Arduino Tutorial, LCD and Keypad

Introduction

  • Previous tutorial: 7-segment
  • This tutorial: LCD and Keypad
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

LCD

lcd

By Ramin Zarebidoky (LiterallyTheOne)
lcd arduino
Arduino Tutorial, LCD and Keypad

LCD Arduino SimulIDE

  • RS: 12
  • RW: ground
  • E: 11
  • D4: 5
  • D6: 4
  • D7: 3
  • D8: 2
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Liquid Crystal

  • Well-known package
  • Work with LCD
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Add Liquid Crystal to PlatformIO

  • In platfromio.ini
lib_deps =
  arduino-libraries/LiquidCrystal
  • in main.cpp
#include <LiquidCrystal.h>
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Make an LCD Object

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

begin

  • initilizes the LCD
lcd.begin(cols, rows);
  • Example:
lcd.begin(16, 2);
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Write

  • Write a character
lcd.write(ch);
  • Example:
lcd.write('h');
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Print

  • Write a text
lcd.print(text);
  • Example:
lcd.print("Hello World!");
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Set Cursor

  • Jumps to the given column and row
lcd.setCursor(col, row);
  • Example:
lcd.setCursor(5, 1);
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Clear

  • Clears the LCD and jumps to the start
lcd.clear();
  • Example:
lcd.clear();
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

LCD Hello World

  • 1st row, 3rd column: "Hello"
  • 2nd row, 4th column: "World"

By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Keypad

  • A series of keys
  • in a matrix

keypad

By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Connect the Keypad

  • row-0: 0
  • row-1: 1
  • row-2: 6
  • row-3: 7
  • col-0: 8
  • col-1: 9
  • col-2: 10
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Add Keypad to PlatformIO

  • in platformio.ini
lib_deps =
  ...
  Keypad
  • in main.cpp
#include <Keypad.h>
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Define Keys

const byte ROWS = 4;
const byte COLS = 3;

char keys[ROWS][COLS] = {
    {'1', '2', '3'},
    {'4', '5', '6'},
    {'7', '8', '9'},
    {'*', '0', '#'}};
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Define pins

byte rowPins[ROWS] = {0, 1, 6, 7};
byte colPins[COLS] = {8, 9, 10};
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Make a keypad Object

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Get Key

  • Gets the pressed key
keypad.getKey();
  • Example:
char key = keypad.getKey();
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Keypad to LCD

By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

Login System

  • Correct username: 12
  • Correct password: 5662
  • Enter: #
By Ramin Zarebidoky (LiterallyTheOne)
Arduino Tutorial, LCD and Keypad

By Ramin Zarebidoky (LiterallyTheOne)