ã¯ããã«
20æ¡Ã4è¡ã®LCD LCD2004ãArduinoã§å¶å¾¡ãã¦HelloWorldãã¾ããã
æ¤ç´¢ããã¨ãããããããLiquidCrystal_I2C.h
ã使ç¨ããã¿ã¤ãã§ãã
使ã£ããã®
- LCD2004
- I2Cã¢ããã¿(PCF8574T)
- Arduino UNO R2
LCD2004
ã¢ãªã¨ã¯ã§ä»¥ä¸ã®LCDã1500åç¨åº¦ã§è³¼å ¥ãã¾ãããI2Cã¢ããã¿ä»ãã§ãã ããã°ãµã¤ãºã謳ã£ã¦ãããiPhone12miniã¨åããããã®ãµã¤ãºã§ãã
LCDã®å¶å¾¡ICã¯åå説æã«
hd44780,st7066,eqvããã
ã¨ããã®ã§ãæ¥ç«ã®HD44780ã®äºæICãè¼ã£ã¦ããã¨æããã¾ãã
I2Cã¢ããã¿ã¨LCDã¯ã¯ãã ä»ãããã¦ããããå¥ã ã§å±ãã¾ããã
LCDã¯18pinã§ä»¥ä¸ã®ãã³ã¢ãµã¤ã³ã«ãªã£ã¦ãã¾ãã
I2Cã¢ããã¿ã¯16pinãªã®ã§ãpin1ããåããã¦ãpin17,18ãNCã¨ãªãã¾ãã
I2Cã¢ããã¿åºæ¿ã®è¡¨é¢ãããã¿ã¼ã³ã追ãã¦ã¾ããããããããåè·¯ã¯ä»¥ä¸ãµã¤ãããã¨åãã¨æããã¾ãã
DB0~DB3ã¯æªæ¥ç¶ã§ãDB4~DB7ã¯ç¹ãã£ã¦ãããã4bitã¢ã¼ãã ã¨æããã¾ãã
I2Cã¢ããã¿(PCF8574T)
PCF8574Tã¯I2Cæ¥ç¶ã®I/Oã¨ãã¹ãã³ãã§ãã
éãããã³ã·ã§ã¡ã¼ã¿ã¼ä¸ã®A0,A1,A2ã®ç©ºãã©ã³ãã§I2Cã®ã¹ã¬ã¼ãã¢ãã¬ã¹ã決å®ãã¾ãããããã©ã«ãã§ã¯3ã¤ã¨ãéæ¾ãªã®ã§ã¢ãã¬ã¹ã¯0x27
ã¨ãªãã¾ãã
PCF8574Tã®ãã¼ã¿ã·ã¼ãï¼https://www.nxp.jp/docs/en/data-sheet/PCF8574_PCF8574A.pdfï¼ã®7.1.1 Address mapsãã¿ãã¨I2Cã¢ãã¬ã¹ï¼A0~6ã®7bitï¼ã®A0,A1,A2ãHIGH(éæ¾ã§VDDã¨ãªãHIGH)ã¨ãªãã7-bit hexadecimal address without R/Wã27h(=0x27)ã¨ãªããã¨ããããã¾ããA3~6ã®bitã¯åºå®ã§ãã
Arduino IDEã®ã¹ã±ããä¾-Wire-i2c_scanner.ino
ã使ç¨ãã¦ãã¢ãã¬ã¹ã0x27
ã§ãããã¨ã確èªã§ãã¾ããã
ä»ã®ããã¤ã¹ï¼STM32ãªã©ï¼ã¯ã¢ãã¬ã¹ã¯R/Wãå«ãã8bitã§éä¿¡ãã¾ãããArduinoã¯R/Wãå«ãã7bitã§ããWire.h
ããã®ããã«ãªã£ã¦ãã¾ãã(LiquidCrystal_I2C.h
ã§ã¯Wire.h
ã使ç¨ãã¦ãã¾ã)
ã¾ããI2Cã¯ä¿¡å·ç·ã®ãã«ã¢ãããå¿
è¦ã§ãããWire.h
ã§ã¯å
é¨ãã«ã¢ãããã¦ãããã®ã§å¤ä»ãæµæãä¸è¦ã§ãã
ãªã®ã§ããã ç·ãã¤ãªãã ãã§OKã§ãã
æ¥ç¶
Arduinoã¨I2Cã¢ããã¿ã4æ¬æ¥ç¶ããã ãã§ãã
Arduino | I2Cã¢ããã¿ |
---|---|
A4 | SDA |
A5 | SCL |
5V | VCC |
GND | GND |
ããã°ã©ã
è²ã
æ¸ãã¾ããããLiquidCrystal_I2C.h
ã使ãå ´åã¯ç´°ãããã¨ã¯æèãããã¨ãªã表示ãããã¨ãã§ãã¾ããï¼LiquidCrystal_I2C.h
ãããæãã«ãã£ã¦ããã¾ãï¼
#include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,20,4); // ã¹ã¬ã¼ãã¢ãã¬ã¹0x27 20æ¡4è¡ void setup() { lcd.init(); lcd.clear(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("0 Hello, world!"); lcd.setCursor(0, 1); lcd.print("1 Hello, world!"); lcd.setCursor(0, 2); lcd.print("2 Hello, world!"); lcd.setCursor(0, 3); lcd.print("3 Hello, world!"); } void loop(){ lcd.setCursor(0, 0); lcd.print("0 Hello, world!"); delay(1000); lcd.setCursor(0, 0); lcd.print("1 world, world!"); delay(1000); }
ããã£ãã¨ãã
ã³ã³ãã©ã¹ã調æ´ãã¦ããã表示ãåºãªãã
表示ãåºãªãã¨æã£ãããã³ã³ãã©ã¹ããæªãåºã¦ãã¾ããã§ãããI2Cã¢ããã¿ã®ããã³ã·ã§ã¡ã¼ã¿ã¼ã§èª¿æ´ãã¾ãã
åè
åèã«ããã¦ããã ãããããã¨ããããã¾ããã