IIC 16x2 RGB LCD KeyPad HAT for Raspberry Pi Wiki - DFRobot

DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+)

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

DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) Board Overview DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) Board Overview
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

DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) IIC 16X2 RGB LCD KeyPad HAT DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) IIC 16X2 RGB LCD KeyPad HAT

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]:

DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) Operations DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) Operations DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) Operations DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) Operations DFR0514 I2C 16x2 RGB LCD KeyPad HAT with RGB Backlight(Compatible with Raspberry Pi 4B/3B+) Operations

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_RGB1602_RaspberryPi library: cd DFRobot_RGB1602_RaspberryPi

b. Check the files in DFRobot_RGB1602_RaspberryPi: ls

c. Switch the catelogue to CPP files: cd cpp/examples

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 xxx(For instance, utilize the SetColor.cpp routine: execute "make SetColor")

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

h: Exit the program: Ctrl+C

![](https://dfimg.dfrobot.com/nobody/wiki/b821384d883926a27b732acfb2da9184.png

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_RGB1602_RaspberryPi library: cd DFRobot_RGB1602_RaspberryPi

c. Check the files in DFRobot_RGB1602_RaspberryPi: ls

d. Switch the catelogue to python3 example program: cd python/examples

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

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

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

h. Exit the program: Ctrl+C

Python3wiringpi

Step 11

rock 4se

Note: Rock 4se is only compatible with Python code.

install libmraa

enable rock pi i2c

Firstly, modify the /boot/hw_intfc.conf file as following and then reboot to enable i2c7

# Hardware Interface Config 
   # For more details, check https://wiki.radxa.com/Rockpi4/hardware/devtree_overlays. 
   # Set "on" to enable the optional hardware interfaces while set "off" to disable
   intfc:pwm0=off
   intfc:pwm1=off
   intfc:uart2=off
   intfc:uart4=off
   intfc:spi1=off
   intfc:spi2=off
   intfc:i2c2=off
   intfc:i2c6=off
   intfc:i2c7=on

install smbus pip install smbus Download the library files

git clone https://github.com/DFRobot/DFRobot_RGB1602_RaspberryPi.git
cd DFRobot_RGB1602_RaspberryPi/python/examples
sudo python3 xxx.py

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