検索コード

I2Cインターフェースを使ったLCD1602の使い方 - Arduinoチュートリアル

I2Cインターフェースを使ったLCD1602の使い方 - Arduinoチュートリアル

このチュートリアルでは、…とインターフェースする方法を示します1602 LCDディスプレイArduinoでanを使用してI2Cモジュールこれにより、従来の並列配線と比べて接続が容易で配線もすっきりします。4つの接続(VCC、GND、SDA、SCL)だけで、Arduinoプロジェクトでディスプレイを完全に制御し、テキストやセンサーデータを表示できます。

LCD1602-I2C display module with 4 wires

必要なコード、配線図、ライブラリのダウンロードリンクはすべてこの記事の下に掲載されています。

I2C接続のLCD1602とは何ですか?

そのLCD1602組み込みシステムで一般的に使用される16文字×2行のディスプレイです。通常は、6~10ピン作動させるのではなく、あるものを追加することによってI2Cモジュール、のみ2本のデータ線(SDAとSCL)は通信に必要です。これにより配線が大幅に簡素化され、Arduinoのピンを他のコンポーネントにより多く割り当てることができます。

LCD1602をArduinoに配線する

Arduino wirng for LCD1602 with I2C
Arduino wirng for LCD1602 with I2C

LCD1602をI2Cモジュール経由でArduino Unoに配線する方法は以下のとおりです:

  • VCC-5V

  • 接地-接地

  • エスディーエー-A4判

  • エスシーエル-A5判

キャプション: LCD1602がI2C経由でArduinoに4本の配線だけで接続されている。

- LCDにテキストを表示するコードの説明

以下のコードはLCDを初期化し、バックライトを有効にし、ループ内でテキストを表示します。

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

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

  • Wire.h: I2C通信に必要です。

  • LiquidCrystal_I2C.h: I2Cを使用してLCDを制御するためのライブラリ。

  • lcd(0x27, 16, 2): 指定したアドレスのLCDを初期化します0x2716列と2行あります。

cppCopyEditvoid setup()
{
  lcd.begin();       // Initialize LCD
  lcd.backlight();   // Turn on backlight
}

  • lcd.begin()LCDを使用できるように準備します。

  • lcd.backlight()ディスプレイのバックライトを点灯させる。

cppCopyEditvoid loop()
{
  lcd.clear();                 // Clear previous content
  lcd.print("Robojax");        // Print on first line
  lcd.setCursor(0,1);          // Move cursor to beginning of second line
  lcd.print("Hello World!");   // Print on second line
  delay(500);                  // Wait for 0.5 seconds
}

  • 画面は0.5秒ごとに更新されます。

  • 時間やセンサーの値など、他のデータを表示することもできます。

必要なライブラリのインストール

インストールする必要がありますLiquidCrystal_I2Cライブラリ:

  1. Arduino IDEを開く

  2. 移動スケッチ > ライブラリを含める > ライブラリを管理

  3. 検索LiquidCrystal_I2C

  4. クリックインストール

インストールが完了したら、コードをコンパイルしてアップロードする準備ができています。

動画のチャプター

  • 00:00- 開始

  • 00:35-LCD1602とI2Cモジュールの解説

  • 午前04:37-配線の解説

  • 午前05:35- LCD1602-I2Cライブラリをダウンロード中

  • 07:13-LCD1602用コードの解説

画像

Arduino wirng for LCD1602 with I2C
Arduino wirng for LCD1602 with I2C
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
63-This is code for an LCD1602 display with an I2C module.
言語: C++
/*
This is code for LCD1602 Display with I2C module
 * Watch the video for this code https://youtu.be/q9YC_GVHy5A
 
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purposes only.
 * This library is based on work done by DFROBOT (www.dfrobot.com).
 */
/*
 *  This code has been modified from the Arduino library
 *  Updated by Ahmad Nejrabi on Jan 20, 2018 at 11:09
 *  in Ajax, Ontario, Canada
 *  for Robojax.com
 *  
 *  This is code for LCD1602 Display with I2C module
 *  which can display text on the screen.
 */
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
  // Robojax code for LCD with I2C
	// initialize the LCD, 
	lcd.begin();
 
	// Turn on the backlight and print a message.
	lcd.backlight();
  // Robojax code for LCD with I2C


}

void loop()
{
  
  //start of loop Robojax code for LCD with I2C
  lcd.clear();
  lcd.print("Robojax");
  lcd.setCursor (0,1); // go to start of 2nd line
 lcd.print("Hello World!");
  //lcd.print(millis() / 1000);
  delay(500);
 //end of loop Robojax code for LCD with I2C
}

必要かもしれないもの

ファイル📁

Arduinoライブラリ(zip)

フリッツィングファイル