🤖
LinkIt 7697 BlocklyDuino 使用指南
  • LinkIt 7697 BlocklyDuino 使用指南
    • 認識 LinkIt 7697
    • 認識 BlocklyDuino
    • BlocklyDuino v2 & v3 比較
    • 安裝開發環境 (v2)
      • 安裝 Arduino 編輯器
      • 安裝驅動並連接開發板
      • 安裝 BlocklyDuino 編輯器
      • 連結兩個編輯器並上傳程式
    • 安裝開發環境 (v3)
    • BlocklyDuino 基礎操作
    • 實作範例教學
      • A01. 內建 LED 閃爍
      • A02. 外接 LED 閃爍
      • A03. 外接 LED 呼吸燈
      • A04. RGB LED 顏色變化
      • A05. 外部按鈕控制開關
      • A06. 蜂鳴器播放聲音
      • A07 .可變電阻控制電壓輸出
      • A08. 伺服馬達控制
      • A21. DHT: 溫濕度感應器
      • A22. HTU21D: 溫溼度感應器
      • A23. PMSX003: PM2.5 感測器
      • A24. HC-SR04P: 超音波測距
      • A25. ADXL345: 加速規(動態)
      • A26. ADXL345: 加速規(手勢)
      • A27. 1602/2004: 液晶顯示模組
      • A28. WS2812: RGB 彩色燈條
      • A29. MFRC522: RFID
      • B00. Grove 相關基礎知識
      • B01. Grove 光感應器
      • B02. Grove 超音波測距感應器
      • B03. Grove 溫溼度感應器
      • B04. Grove 繼電器
      • B05. Grove LED 燈條
      • B06. Grove OLED 顯示器
      • C01. 雲端控制 LED 開關
      • C02. 上傳溫溼度到雲端
      • D01. 手機透過 BLE 讀寫裝置資料
      • E01. 遙控器: 按鈕控制 LED
    • 資源鏈結
  • LinkIt 7697 - Arduino IDE 開發指南
    • 環境設定
      • 設定 Arduino IDE
      • 將 LinkIt 7697 連接到電腦
        • 在 Windows 上安裝 CP2102N 驅動程式
        • 在 macOS 上安裝 CP2102N 驅動程式
      • 執行第一個程式
    • 開發指南
      • GPIO
      • UART
      • ADC
      • EINT (外部中斷 / External Interrupt)
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (索引式儲存空間)
      • RTC (Real-Time Clock)
      • Software Serial
      • 使用 Wi-Fi 函式庫
      • 使用 MCS 函式庫
        • 連接到 MCS
        • 連接到 MCSLite
          • 建立可透過 MCS Lite 控制的 Beacon
        • MCS 函式庫 API 使用手冊
          • MCSDevice
          • MCSLiteDeviceMCSLiteDevice
          • MCSDataChannel 相關類別
      • 使用 BLE 低功耗藍牙
        • 藍牙信標
        • 主控裝置
        • 周邊裝置
        • 已知限制
        • LBLE API 指南
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • 使用 LinkIt Remote
        • LRemote API
        • LRemote 控制元件 API
      • LinkIt 7697 腳位的初始狀態
      • LinkIt 7697 供電說明
      • 更新 Bootloader 與韌體
      • Flash 燒錄工具
      • FOTA 更新
      • LinkIt 7697 的功能限制
      • 自行編譯 Arduino Package
      • 回報問題
    • 週邊元件連接教學
      • SMD 按鈕
      • RGB 三色 LED
      • 可變電阻
      • 九軸感應器 (MPU-9250)
      • 溫度與濕度感應器 (AM2302)
      • 超音波距離感應器
      • 光感應器 (LM358)
      • 0.96 吋 OLED 顯示模組 (SSD1308Z)
      • 長條型 LED 顯示模組 (MY9221)
      • 繼電器
      • 伺服馬達 (EMAX 9g ES08A Servo)
      • 使用 74HC595 驅動七段顯示器
      • 使用 MAX7219 驅動七段顯示器
      • 使用 MAX7219 驅動 8x8 矩陣式顯示器
      • 使用 OLED 模組 (如 SH1106 / SSD1306... 等模組)
      • 使用 PCF8574 / PCF8574A 驅動 1602 LCD
    • 開發套件與擴充板
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • 下載
    • 資源連結
    • BSP 版本更新資訊
  • LinkIt 7697 - Development Guide for Arduino IDE
    • Environment Setup
      • Setup Arduino IDE
      • Connecting LinkIt 7697 to Computer
        • Install CP2102N Driver on Windows
        • Install CP2102N Driver on macOS
      • Run Your First Sketch
    • Developer Guide
      • GPIO
      • UART
      • ADC
      • External Interrupt
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (Key-Pair Storage)
      • RTC (Real-Time Clock)
      • Software Serial
      • Using the Wi-Fi Library
      • Using MCS Library
        • Connecting to MCS
        • Connecting to MCSLite
          • Build a Beacon controlled by MCS Lite
        • MCS Library API Reference
          • MCSDevice
          • MCSLiteDevice
          • MCSDataChannel Classes
      • Using Bluetooth
        • Beacons
        • Central Devices
        • Peripheral Devices
        • Limitations of LBLE library
        • LBLE Library API Guide
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • Using LinkIt Remote
        • LRemote
        • LRemote Control Classes
      • Initial Pin State of LinkIt 7697
      • Powering the LinkIt 7697
      • Update Bootloader and Firmware
      • Flash Uploading Tool
      • FOTA Update
      • Limitations of LinkIt 7697
      • Source Code of Arduino Package
      • Issue Report
    • Tutorial
      • SMD Buttons
      • RGB LED
      • Potentiometer
      • IMU 9DOF v2.0 (MPU-9250)
      • Temperature and Humidity Sensor Pro (AM2302)
      • Grove Ultrasonic Ranger
      • Light Sensor (LM358)
      • Grove OLED Display 0.96" (SSD1308Z)
      • LED Bar v2.0 (MY9221)
      • Relay
      • Mini Servo (EMAX 9g ES08A Servo)
      • Driving 7-segment Displays with 74HC595
      • Driving 7-segment Displays with MAX7219
      • Driving 8x8 Dot Matrices with MAX7219
      • Using OLED module (SH1106 / SSD1306... etc.)
      • Driving 1602 LCD with PCF8574 / PCF8574A
    • Kits and Shields
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • Download
    • Resources
    • BSP Release Notes
Powered by GitBook
On this page
  • Table of contents
  • Download and install the library
  • Hardware setup
  • LiquidCrystal_I2C library
  • HelloLinkIt7697 example
  • Appendix
  1. LinkIt 7697 - Development Guide for Arduino IDE
  2. Tutorial

Driving 1602 LCD with PCF8574 / PCF8574A

PreviousUsing OLED module (SH1106 / SSD1306... etc.)NextKits and Shields

Last updated 3 years ago

LCDs are widely used in various applications for displaying feedback to users. One of the most commonly accessible display is the Hitachi 1602 LCD display. In this tutorial, we'll show how to connect the LinkIt 7697 with a (with built-it) and give examples about how to use to drive it.

Table of contents

Download and install the library

Hardware setup

Four pins are needed from the LinkIt 7697 to connect to the LCD module:

  • 5V

  • GND

  • I2C Clock (P8)

  • I2C Data (P9)

and they are wiring to:

  • VCC

  • GND

  • SCL

  • SDA

pins of the module, respectively. The figures for the connection are shown below:

[Back view of the LCD module and pins for the connection]

After the wiring is done, you can execute the HelloLinkIt7697 example mentioned above to see how the display works as this video:

Trouble-shooting

When running this example, you might encounter issues and not see expected result displayed:

  • Nothing is displayed on the LCD: you can adjust the variable resistor (indicated by the yellow rectangle) on the module to modify the contrast of the display.

LiquidCrystal_I2C library

LiquidCrystal_I2C()

The constructor initializes the device and assigns the I2C address of the device to the software. For example, we assign the address 0x3F for the LCD with PCF8574A:

// set the I2C address of the LCD controller
//    0x3F for PCF8574A
//    0x27 for PCF8574
LiquidCrystal_I2C lcd(0x3F);

If the driving IC on the LCD module is PCF8574 (not PCF8574A), make sure the address is set to 0x27 instead of 0x3F for the LCD to work correctly.

begin()

This defines the display region. For a 1602 LCD, the API is called with (16, 2) as the input parameters:

// init the 1602 (2 rows / 16 columns) LCD
lcd.begin(16, 2);

home()

Set the cursor back to the position 0 of the display.

clear()

Clear all contents and settings of the display.

setCursor()

Define the cursor position for displaying characters.

print()

Output characters to the display from the position of the cursor. You can use ASCII characters as inputs or define customized bitmaps for displaying. For displaying ASCII characters, simply call the API with a ASCII string:

// display ASCII characters directly
lcd.print("LinkIt 7697");

To display customized characters, you need to register the customized bitmaps first by the following API.

createChar()

Each character on the 1602 LCD is a 5x8 matrix and it is defined as a 8-byte array, which uses the lower 5 bits of each byte to define the dots on a bitmap. Here we give an example of defining a "up-arrow" bitmap:

So it can be coded as:

// define the up-arrow bitmap
const uint8_t up_arrow[8] = {0x04, 0x0E, 0x1F, 0x04, 0x04, 0x04, 0x00, 0x00};

By calling the createChar() API, you can register this bitmap with a desired index:

// register the bitmap to index 3
lcd.createChar(3, (uint8_t *)up_arrow);

With above statement, the up-arrow bitmap is registered to the index 3. So you can show the up-arrow character on the LCD by calling:

// show the bitmap (with index 3) on the LCD
lcd.print(char(3));

Limitation

The 1602 LCD supports up to 8 customized bitmaps. So the valid range of the registered index is between 0 to 7.

display() / noDisplay()

Turn on / off the display (not the backlight). One of the applications of this operation is to blink the texts displayed while keeping the backlight on.

backlight() / noBacklight()

Turn on / off the backlight (not the display).

scrollDisplayLeft() / scrollDisplayRight()

Move all characters on the display left / right by one position. This is done by changing the coordinate space of the display, not by modifying the coordinate of each character.

leftToRight() / rightToLeft()

Define the cursor moving direction.

HelloLinkIt7697 example

As shown in the example video above, we combined APIs mentioned in the previous section together to make the HelloLinkIt7697 example sketch. You can refer to the source codes to see how to put operations provided by the library into real display applications.

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

// set the I2C address of the LCD controller
//    0x3F for PCF8574A
//    0x27 for PCF8574
LiquidCrystal_I2C lcd(0x3F);

// define the custom bitmaps
// up to 8 bitmaps are supported
const uint8_t my_bitmap[][8] =
{
  // chequer
  {0x15, 0x0A, 0x15, 0x0A, 0x15, 0x0A, 0x15, 0x00},
  // up arrow
  {0x04, 0x0E, 0x1F, 0x04, 0x04, 0x04, 0x00, 0x00},
  // down arrow
  {0x00, 0x00, 0x04, 0x04, 0x04, 0x1F, 0x0E, 0x04},
  // rectangle
  {0x00, 0x1F, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00},
  // up-left arrow
  {0x1F, 0x1E, 0x1C, 0x1A, 0x11, 0x00, 0x00, 0x00},
  // up-right arrow
  {0x1F, 0x0F, 0x07, 0x0B, 0x11, 0x00, 0x00, 0x00},
  // down-left arrow
  {0x00, 0x00, 0x00, 0x11, 0x1A, 0x1C, 0x1E, 0x1F},
  // down-right arrow
  {0x00, 0x00, 0x00, 0x11, 0x0B, 0x07, 0x0F, 0x1F},
};

#define LONG_DELAY()  delay(1000)
#define SHORT_DELAY() delay(500)
#define ANIM_DELAY()  delay(400)

void setup()
{
  int i;
  int bitmap_size = sizeof(my_bitmap) / sizeof(my_bitmap[0]);

  // init the 1602 (2 rows / 16 columns) LCD
  lcd.begin(16, 2);

  // register the custom bitmaps
  for (i = 0; i < bitmap_size; i++)
  {
    lcd.createChar(i, (uint8_t *)my_bitmap[i]);
  }

  // move the cursor to 0
  lcd.home();
  lcd.print("          Hello!");
  
  // scroll left for 5 positions
  for (int i = 0; i < 5; i++)
  {
    lcd.scrollDisplayLeft();
    
    ANIM_DELAY();
  }

  // clear the LCD contents and the scrolling offset
  lcd.clear();

  // turn off the backlight
  lcd.noBacklight();
  
  LONG_DELAY();

  // turn on the backlight
  lcd.backlight();
  
  lcd.print("     Hello!     ");
  // change to the starting position of the next line
  lcd.setCursor ( 0, 1 );
  lcd.print("  LinkIt 7697   ");

  // blinks the texts
  for (i = 0; i < 2; i++)
  {
    ANIM_DELAY();
    lcd.noDisplay();
    
    ANIM_DELAY();
    lcd.display();
  }
  
  LONG_DELAY();
  LONG_DELAY();

  // clear all LCD contents and settings
  lcd.clear();
  
  SHORT_DELAY();
}

void loop()
{
  int i, ch_map;

  // clear the LCD and set the string direction to left-to-right
  lcd.clear();
  lcd.leftToRight();  
  lcd.print("    LeftToR");
  
  LONG_DELAY();

  lcd.setCursor(4, 0);
  lcd.print("12345678");
  
  SHORT_DELAY();
  
  lcd.setCursor(4, 0);

  // display the custom characters. randomly select a character bitmap
  for (i = 0; i < 8; i++)
  {
    ch_map = random(8);
    
    lcd.print(char(ch_map));

    ANIM_DELAY();
  }

  lcd.setCursor(0, 1);
  lcd.print("    RightToL");
  LONG_DELAY();

  // set the string direction to right-to-left
  lcd.rightToLeft();
  lcd.setCursor(11, 1);
  lcd.print("12345678");
  SHORT_DELAY();
  
  lcd.setCursor(11, 1);

  // display the custom characters. randomly select a character bitmap
  for (i = 0; i < 8; i++)
  {
    ch_map = random(8);

    lcd.print(char(ch_map));

    ANIM_DELAY();
  }
}

Appendix

The I2C address of the module

and the address of PCF8574 is 0x27:

For the library, the 7-bit I2C address format is used so that's why we assign 0x3F / 0x27 as the address for the device. However, the module also provides flexibilities for developers to customize the address to prevent from address collision on the same I2C bus. This is achieved by short-circuiting the A0 / A1 / A2 pads indicated by the yellow rectangle below:

The address bits (A0 / A1 / A2) of the PCF8574A / PCF8574 are controlled by the A0 / A1 / A2 pins on the chip and it's pulled high on the module by default. The schematic diagram is:

Therefore, if you mount a 0R resistor on the A0 pads of the module, for example, it will make the A0 bit to 0 and this changes the I2C address of this device from 0x3F to 0x3E on PCF8574A (or from 0x27 to 0x26 on PCF8574) according to the address map listed above. By following the same idea, you can modify the address bit A1 and A2 in the same way to customize your own I2C device address.

Based on the work of , we removed unused files and ported it to fit You can and follow the in the "Install Drivers" section to install it into the Arduino development environment. After the installation is done, you can see there is an example under the File / Examples / LiquidCrystal_I2C / HelloLinkIt7697 sub-menu. Before going into details of the HelloLinkIt7697 example, let's first look at the hardware setup and usages of the library.

Only rectangles are displayed on the first row of the LCD: the I2C address of the module is configured incorrectly in the software. Make sure the part number of the driving IC on the module. In the example sketch, it assumes the IC is PCF8574A, which uses the address of 0x3F. If the driving IC on the module is PCF8574 (without an "A" in the name), the address would be 0x27. You'll see how to assign the I2C address in the code later. For more details about the I2C address of the module, you can refer to the of this article.

By using , developers can easily access the 1602 display module. It provides APIs to control different functionalities of the display. Here we introduce basic ideas of them.

As indicated in the , the default I2C device address of PCF8574A is 0x3F:

Download and install the library
Hardware setup
LiquidCrystal_I2C library
HelloLinkIt7697 example
Appendix
Download
Francisco Malpartida
the LinkIt 7697 Arduino BSP.
download the library
instructions
appendix section
the LiquidCrystal_I2C library
datasheet
HD44780
1602 I2C LCD display module
PCF8574A
the library