ArduinoでLCDディスプレイを動かしてみた

スポンサーリンク

・目的

 osoyooのarduinoキットに入っていた

 ディスプレイにhello worldを表示させる

 

・使ったもの

 arduino uno

 

【永久保証付き】Arduino Uno

【永久保証付き】Arduino Uno

 

 

  ノートパソコン(windows10)

 ブレッドボード

 

 

 ジャンパワイヤーオス、メス

 キャラクタLCD(16×2)(osoyoo製)

 

・方法

 (1)LCDライブラリーをインポート

    http://osoyoo.com/ja/2014/12/07/16x2-i2c-liquidcrystal-displaylcd/

    osoyooのサイトからLiquidCrystal_I2C.zipというlibraryファイルを

    ダウンロードしてzipファイルを解凍する。

    解凍したファイルをc/programfile/arduino/libralesにコピー

 

 (2)LCDarduinoを接続

    

    SDAはSerial Data Access (シリアルデータアクセス)の略。     

    SCLはSerial Clock Line (シリアルクロックライン)。

          SDLをa5 、SDAをa4に接続した。回路図は図1に示した。

f:id:shangtian:20170301190559p:plain

図1:LCDArduinoの接続

 

 (3)i2cアドレスを特定する

    i2cアドレスを特定するために以下のプログラムコード(図2)を

    インポートし、シリアル通信画面を開き実行すると

    i2cアドレスが表示される(図3)。

 *  ___   ___  ___  _   _  ___   ___   ____ ___  ____  
 * / _ \ /___)/ _ \| | | |/ _ \ / _ \ / ___) _ \|    \ 
 *| |_| |___ | |_| | |_| | |_| | |_| ( (__| |_| | | | |
 * \___/(___/ \___/ \__  |\___/ \___(_)____)___/|_|_|_|
 *                  (____/    
 * www.osoyoo.com IC2 Liquid Crysal Testing program
 * program tutorial : http://osoyoo.com/?p=72
 *  Copyright John Yu
 */
   
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
 
LiquidCrystal_I2C lcd(0x3f,16,2);  // run ic2_scanner sketch and get the IC2 address, which is 0x3f in my case,it could be 0x3f in many cases
 
void setup()
{
  lcd.init();                      // initialize the lcd
}
 
void loop()
{
// set cursor to first line
lcd.setCursor(0, 0);

// Print a message to the LCD.
  lcd.backlight();
  lcd.print("Hello!");
  lcd.setCursor(0,1);
  lcd.print("Osoyoo.com");
}
図2:i2cアドレスを特定するためのスケッチ http://osoyoo.com/driver/i2c_lcd_test.txt

 



f:id:shangtian:20170301190620p:plain

 

図3:i2cアドレスの特定

 

 (4)プログラムコード

        (3)で調べらiscアドレスを

     LiquidCrystal_I2C lcd(0x3F,16,2);

     と書き込む。

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

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

void setup()
{
  lcd.init();               // initialize the lcd 
 
  lcd.print("Hello World");// Print a message to the LCD.
  lcd.backlight();
 
}

 

>OSOYOO(オソヨー) Raspberry Pi 学ぶ電子工作キット 初心者演習用パーツセット ラズパイ11実例 回路配線図とサンプルスケッチ有り プログラミング ラズベリー パイ 超入門 スターター学習キット LED制御 スイッチ

価格:8,240円
(2017/3/21 07:16時点)
感想(0件)

・結果

 無事表示できた。

f:id:shangtian:20170301211918j:plain

 

shangtian.hatenablog.com

 

 

<参考文献>

・16x2 I2C LCD プロジェクト(http://osoyoo.com/?p=72