Introduction

This is a 2X16 character RGB LCD+Keypad shield for Raspberry Pi. We made improvements in the wiring connection based on the previous LCD display as well as left out the contrast adjustment function, so the product can be pretty easy to use, and users can spend time focusing on the most important projects.

The RGB LCD1602 display is integrated on the shield. It leads out Raspberry Pi’s GPIO ports for connecting more device. Besides, the shield adopts IIC interface, so you can realize the 16 million color combination of the LCD, backlight brightness adjustment, display control etc. To convenient your use on Raspberry Pi, there are 5 push-buttons integrated on the board to help you to switch display and configure functions, then you can easily build up your data monitor and small operating platform.

IIC 16x2 RGB LCD Keypad HAT has two display effects: colorful background or colorful font.

Specification

Board Overview

RGB Interface 1

RGB Interface 2

GPIO(BCM Num) Button Description
16 Select
17 Up
18 Down
19 Left
20 Right

Note: when using the Keys, the jumper needs to be installed first. For example, connect GPIO16 and Button via jumper cap, then the button Select can be used.

Tutorial

  1. Learn how to use RGB LCD KeyPad HAT on Raspberry Pi and set the color of the LCD screen.
  2. Learn the usage of Buttons and the calling of the programs.

Requirements

IIC 16X2 RGB LCD KeyPad HAT

RGB KeyPad HAT Top View

RGB KeyPad HAT  Bottom View

Operations

Step 1. Install RGB LCD KeyPad HAT onto Raspberry Pi board. The IIC interface of Raspberry Pi board is disabled by default, we have to enable it manually first:

Input the command into the Raspberry Pi terminal: sudo raspi-config

Press "Enter" on the keyboard to select: [Interfacing Options] (or [Advanced Options])->[I2C]->[Yes]->[OK]->[Finish]:

Step 1

Step 2

Step 3

Step 4

Step 5

Step 2. Detect if the IIC address of the RGB LCD KeyPad HAT is detected by the Raspberry Pi bus:

Input the command into the Raspberry Pi terminal:

Install the test tool: sudo apt-get install i2c-tools

Detect the IIC device on the bus: sudo i2cdetect -y 1

IIC detection state when the HAT board is not installed on the Raspberry Pi

IIC detection state when the HAT board is installed on the Raspberry Pi

Step 3 When finishing the above two steps, we can start to use RGB LCD KeyPad HAT now. To begin with, we must copy the library files into Raspberry Pi Board, and there are two ways to realize that:

a. Click to download DFRobot_RGB1602_RaspberryPi, copy the downloaded files to Raspberry Pi board via a U-disk;

b. If your Raspberry Pi is connected to network, you can directly use git command to get files through Raspberry Pi terminal, input the command: git clone https://github.com/DFRobot/DFRobot_RGB1602_RaspberryPi.git

Download DFRobot_RGB1602_RaspberryPi library

Check if the Raspberry Pi board is installed, input the command: ls

Step 4. Run the C++ program[SetColor]: Set the LCD screen color to red.

Input the commands into Raspberry Pi terminal:

a. Switch the catelogue to DFRobot_RGBLCD library: cd DFRobot_RGB1602_RaspberryPi/DFRobot_RGBLCD

b. Check the files in DFRobot_RGBLCD: ls

c. Switch the catelogue to CPP files: cd cpp

e. Check the files in CPP: ls (all the example programs edited in c++ can be seen after this command is executed)

f. Compile the example program: make

g. Run the SetColor example program: ./SetColor

h. As shown below, input r into the terminal: 255 (Enter) g:0 (enter) b:0 (Enter)

i: Exit the program: Ctrl+C

Step 10

4-1: Run the python example program [SetColor]: set the color of the LCD screen to red.

a. Install the wiringpi library of python3: pip3 install wiringpi

b. Switch the catelogue to DFRobot_RGBLCD library: cd DFRobot_RGB1602_RaspberryPi/DFRobot_RGBLCD

c. Check the files in DFRobot_RGBLCD: ls

d. Switch the catelogue to python3 example program: cd python3

e. Check the files in python3: ls (all the example programs edited in python can be seen after this command is executed.)

f. Switch the catelogue to SetClolor: cd SetColor

g. Execute the SetColor example program: python3 SetColor.py

h. As shown below, input r into the terminal: 255(Enter) g: 0(Enter) b: 0(Enter)

i. Exit the program: Ctrl+C

Python3wiringpi

Step 11

Sample Code (c)

Function: set the color of the RGB LCD screen

Result: input r: 255 g: 0 b: 0 then the screen displays red.

Note: vim compiler needs to be installed first then you can continue the above operations. vim install command: sudo apt-get install vim-gtk

Open c program in Vim

#include "../DFRobot_RGBLCD.h"
#include <iostream>
#include <string>

using namespace std;

int main(){
  int r,g,b;

  DFRobot_RGBLCD lcd(16, 2);
  // initialize
  lcd.init();
  // Print a message to the LCD.
  lcd.print("set cllor");

  while(1){
    cout << "r:";
    cin >> r;
    cout << "g:";
    cin >> g;
    cout << "b:";
    cin >> b; 

    lcd.setRGB(r, g, b);

    cout << "r = " << r 
         << "g = " << g
         << "b = " << b
         << endl;
  }
  return 0;
}

Sample Code(Python)

Fucntion: detect the functions of the buttons

Result:

  1. When press the "Up" button, the LCD display Push the buttons UP
  2. When press the "Down" button, the LCD display Push the buttons DOWN
  3. When press the "Left" button, the LCD display Push the buttons LEFT
  4. When press the "Right" button, the LCD display Push the buttons RIGHT
  5. When press the "Select" button, the LCD display Push the buttons SELECT
import sys
sys.path.append('../')
import RPi.GPIO as GPIO
import rgb1602
import time

lcd = rgb1602.RGB1602(16,2)
GPIO.setmode(GPIO.BCM)
# Define keys
lcd_key     = 0
key_in  = 0

btnRIGHT  = 0
btnUP     = 1
btnDOWN   = 2
btnLEFT   = 3
btnSELECT = 4

GPIO.setup(16, GPIO.IN)
GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.IN)
GPIO.setup(19, GPIO.IN)
GPIO.setup(20, GPIO.IN)


#Read the key value
def read_LCD_buttons():
  key_in16 = GPIO.input(16)
  key_in17 = GPIO.input(17)
  key_in18 = GPIO.input(18)
  key_in19 = GPIO.input(19)
  key_in20 = GPIO.input(20)

  if (key_in16 == 1):
    return btnSELECT
  if (key_in17 == 1):
    return btnUP
  if (key_in18 == 1):
    return btnDOWN
  if (key_in19 == 1):
    return btnLEFT
  if (key_in20 == 1):
    return btnRIGHT

lcd.setCursor(0,0)
lcd.print("Push the buttons"); #print“Push the buttons”

while True:
  lcd.setCursor(0,1)
  lcd_key = read_LCD_buttons()  #  Reading keys

  if (lcd_key == btnRIGHT):
    lcd.print("RIGHT ")
  elif (lcd_key == btnLEFT):
    lcd.print("LEFT  ")
  elif (lcd_key == btnUP):
    lcd.print("UP    ")
  elif (lcd_key == btnDOWN):
    lcd.print("DOWN  ")
  elif (lcd_key == btnSELECT):
    lcd.print("SELECT")

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum

More Documents

DFshopping_car1.png Get IIC 16X2 RGB LCD KeyPad HAT (V1.0) from DFRobot Store or DFRobot Distributor.

Turn to the Top