Arduino NANO (2) 1602 LCD i2c 表示

1602 LCD直接繋ぐと、6つのデジタルポートを占有(4つデータワイヤ+2の制御ワイヤが必要)し、GPIOはたくさん消耗するので、i2cを利用すると2つのアナログポートが足りる。

WeMosで試すと、うまくいかないので、より汎用のこのNANOで試す。すんなりうまくいく。

I2C インターフェイス SDA、SCL は Arduino Nano ではそれぞれ A4、A5 です。

Arduino Nano
SDA A4
SCL A5

 

サンプルプログラム。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Hello, world!");
}
void loop(){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); void setup() { lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Hello, world!"); } void loop(){ // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis() / 1000); }
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

void setup() {
  lcd.init(); 
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello, world!");
}

void loop(){
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}

写真も後ほどに。