ãä»åã¯ArduinoãšI2Cã«é¢ããå 容ã§ããI2Céä¿¡ã«å¯Ÿå¿ããã¢ãžã¥ãŒã«ãšããã®ã¯ã枩湿床èšãã¯ãããšãã枬å®ç³»ãããLCDãç°¡åã«äœ¿ããããã«ããããã®ã¢ãžã¥ãŒã«ã§ãã£ãããåºåIOãå¢ããããã®IOãšã¯ã¹ãã³ããŒã§ãã£ãããããŸããŸãªãã®ãååšããŸãã
ããããªãªãããã䜿ã£ãŠã¿ãããšããŠããã®ã¢ãžã¥ãŒã«ãArduinoããæäœã§ããªãããšã£ãŠãããŸãããïŒãããããã®èšäºãèŠãŠããããªãããã®äžäººã ãšæããŸããåå ã¯ãã¡ããæ§ã ããããã§ããããã®äžã§ãåæ©çãªãããããArduinoãããã®I2Cã¢ãžã¥ãŒã«ã¯èªèãããŠãããïŒããšãã課é¡ã解決ããŠã¿ãŸãããã
ããããªããã§ä»åã¯ãArduinoã䜿ã£ãŠI2Céä¿¡ããã¢ãžã¥ãŒã«ãæ£ããèªèããããšããããã玹ä»ããŸãã
Arduinoã«æ¥ç¶ããI2Céä¿¡ã¢ãžã¥ãŒã«ãã
ArduinoããèªèãããŠããã確èªããããšãã§ããããã«ãªãã
Youtubeãã£ã³ãã«ã«ããŸããŸãªåç»ãäžããŠããŸãã
âââãã¡ãããYoutubeãã£ã³ãã«ã«ã¢ã¯ã»ã¹!! âââ
æ¬ããã°ã¯ã¢ãã£ãªãšã€ããçšããåºåãæ²èŒããŠããŸãã
念ã®ããïŒæ£ããé ç·ãããŠããã確èªããŠãã
ãäŸãã°ããã¡ãã®ãããªI2Céä¿¡ã§æåã衚瀺ãããLCD(液æ¶ãã£ã¹ãã¬ã€)ãäŸã«ããŸãããã
ããã®LCDã¯I2Cã«ããéä¿¡ãã§ããŸãããé ç·ããããã®ãã³ã¯ãGND,5V,SDA,SCLã®4æ¬ã§ããI2Céä¿¡ãšãããšããã®SDA,SCLãéä¿¡çšã®ä¿¡å·ç·ã«ãªããŸãã
ãArduinoã¯I2Céä¿¡çšã®å¶åŸ¡ãã³(SDA,SCL)ããããŸãããããã¡ãã«LCDã®ãã³ãæ¥ç¶ããããšã«ãªããŸããå ·äœçã«ã¯ãã®ããã«ãªããŸãã
![arduino-lcd-i2c](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-3.png)
ããããŸã§ç¢ºèªåºæ¥ããé ç·ã¯å®äºã§ãã
ãåç»ã§ã¯2åã®LCDãã€ãªããŠããŸãããä»åã¯1ã€ã ãæ¥ç¶ããããšãã€ã¡ãŒãžããŠè§£èª¬ããŸãããã2ã€ä»¥äžã®I2Céä¿¡çšã®ã¢ãžã¥ãŒã«ãã€ãªãããå Žåã¯æ³šæç¹ãæããŸãã®ã§ãå¥èšäºã§ã玹ä»ããŸããã楜ãã¿ã«ã
ArduinoåŽã§I2Céä¿¡çšã®ã¢ãžã¥ãŒã«ãèªèã§ããŠããã確èª
ãããã§ã¯é ç·ãçµãã£ããšããã§ãArduinoãI2Céä¿¡çšã®ã¢ãžã¥ãŒã«(ä»åã®äŸã§ã¯CD)ãèªèããŠããã確èªããŠã¿ãŸãããã
ã確èªããŠã¿ãæ¹æ³ã¯ã以äžã®æé ã®éãã§ãã1ã€ãã€è©³ãã確èªããŠãããŸãããã
Arduino IDEãéã
ãArduinoããã§ã«è§Šã£ãŠããªãã°ãã®èª¬æã¯äžèŠã§ããããèªèº«ã®ããœã³ã³ã«å ¥ã£ãŠãããã®ã¢ã€ã³ã³ãã¯ãªãã¯ããŠArduinoIDEãç«ã¡äžããŠãã ããã
![ArduinoIDE-icon](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-4.png)
ãããã¢ã€ã³ã³ã®åœ¢ç¶ãéããªã…ãšããå Žåã¯ãææ°ã®ArduinoIDEã«ããŠã¿ãã®ããããããããŸããããâ»ä»å䜿çšããã®ã¯2024幎5æ25æ¥æç¹ã§ææ°ã®Ver.2.3.2ã§ãã
ãâââããããææ°çã®Arduino IDEãããŠã³ããŒãã§ããŸããâââ
Arduinoå ¬åŒããŒãžãžé£ã¶
I2cScanner(ã©ã€ãã©ãª)ãå°å ¥ãã
ãããã§ã¯æ¬¡ã«Arduino IDEã䜿ã£ãŠãI2cScannerãå°å ¥ããŠã¿ãŸãããããã®I2cScannerã¯ãã©ã€ãã©ãªãšåŒã°ãããã®ã§ããã©ã€ãã©ãªãšã¯ãç°¡åãªã³ãŒãã®èšè¿°ã§ããããããšãå®çŸã§ããããã«ããŠãããã¢ã€ãã ã ãšãèãäžããã
ãå°å ¥æé ã¯ããŸããArduino IDEã®å·ŠåŽã®æ¬ã®ãããªããŒã¯ãã¯ãªãã¯ããŸãããããšãã©ã€ãã©ãªãããŒãžã£ãŒãšãããŠã€ã³ããŠã衚瀺ãããŸãã
ããã®ãŠã€ã³ããŠã®äžçªäžã®ããã¹ãããã¯ã¹ã«ãi2cscannerãšæã¡èŸŒãã§æ€çŽ¢ããŸãããã1ã€ããåºãªãã¯ããªã®ã§ããã¡ããã€ã³ã¹ããŒã«ãã¿ã³ã§ã€ã³ã¹ããŒã«ããŸãã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-6.png)
ãã€ã³ã¹ããŒã«ãå®äºããããArduinoIDEã®ãã¡ã€ã«ã¿ãããã¹ã±ããäŸãéžæããŸããã¹ã±ããäŸã¯ArduinoIDEã«æšæºã§å ¥ã£ãŠãããã®ãããå ã»ã©ã€ã³ã¹ããŒã«ããã©ã€ãã©ãªã®ãããªå€éšããŒã¿ãããã«è¡šç€ºãããŸãã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-8.png)
ãã¹ã±ããäŸã®äžã®ã»ãã«ãi2CScannerãšããé ç®ãèŠã€ããã¯ããªã®ã§ããã®ãªãã®Scannerãšããé ç®ãã¯ãªãã¯ããŸãããã
ã(â»ãã®æç¹ã§I2CScannerãèŠã€ãããªãå Žåã¯ãã©ã€ãã©ãªã®ã€ã³ã¹ããŒã«ããããçŽããŠãã ããã)
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-9.png)
ãéžæãããšãæ°ãã«ã¹ã±ãããéãããŸããScanner.inoãšããã¹ã±ããã§ããããã®ã¹ã±ããã䜿ãããšã§ãããŸArduinoã«æ¥ç¶ãããŠããI2Céä¿¡çšã®ã¢ãžã¥ãŒã«ã®ã¢ãã¬ã¹ãããããŸãã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-10.png)
ãI2Cã®ã¢ãã¬ã¹ã«ã€ããŠã¯ä»åã¯è©³ãã解説ããŸãããã1ã€ãäŒããããšãã¢ãã¬ã¹ã衚瀺ãããŠããïŒArduinoããèªèãããŠããããšæã£ãŠããã ããŠééããããŸããã
I2cScannerãArduinoã«æžã蟌ã
ãããã§ã¯ä»äžãã«å ã»ã©æ°èŠã§éãããScanner.inoãšããã¹ã±ãããArduinoæ¬äœã«æžã蟌ã¿ãŸããããæžã蟌ã¿æ¹æ³ã¯éåžžã®ã¹ã±ãããšåæ§ã«ãå³ç¢å°ãã¿ã³ã§OKã§ãã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-11.png)
ãããæžã蟌ã¿ã倱æããå Žåã¯ãå³ç¢å°ãã¿ã³ãšåãåã«ããããŒããšCOMããŒãã®èšå®ãã¯ãªãã¯ããŠãèªèº«ã®ç°å¢ãšäžèŽããŠããã確èªããŠã¿ãŠãã ããããããŠãCOMããŒãçªå·ãééã£ãŠããã ãã ã£ããããŸãã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-12.png)
ã·ãªã¢ã«ã¢ãã¿ã§ç¢ºèªãã
ãScanner.inoãArduinoã«æžã蟌ãã ããã·ãªã¢ã«ãŠã€ã³ããŠãéããŠã¿ãŠãã ãããã·ãªã¢ã«ã¢ãã¿ã¯ãArduino IDEã®å³äžã®ãã®ãã¿ã³ãæŒãããšã§ç»é¢ãåãæ¿ãããŸããè«çŒé¡ã§ãããã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-13.png)
ãã·ãªã¢ã«ã¢ãã¿ã¯ãArduinoIDEã®äžã«åºãŠããŸããéåžžã¯åºåã¿ãã«ãªã£ãŠããŸãããã·ãªã¢ã«ã¢ãã¿ã®ãã¿ã³ãæŒãããšã§ãã®ããã«è¡šç€ºãããããšãã§ããŸãã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-14.png)
ãä»åã€ãªããŠããLCDã®ã¢ãã¬ã¹ã¯ã0x26ãš0x27ã§ããããšãããããŸããã
--- Scan started ---
I2C device found at address 0x26 !
I2C device found at address 0x27 !
--- Scan finished ---
ãããã»ã©ããäŒãããŸãããããã®ããã«ArduinoåŽã§I2Cã®ã¢ãã¬ã¹ãååŸã§ããŠãããšããããšã¯ããã ããI2Cçšã¢ãžã¥ãŒã«ãšéä¿¡ã§ããŠããããšã«ãªããŸãã
ãå察ã«ãããI2Cçšã¢ãžã¥ãŒã«ãšéä¿¡ã§ããŠããªãå Žåã¯ã©ããªãã§ããããïŒçµæã¯ãã¡ãã®ããã«ãªããŸãã
![](https://www.hobbyhappyblog.jp/wp-content/uploads/2024/05/image-15.png)
ãScan startedã®ãŸãŸã§ããããã»ã©ã¯ãã®åŸã«ã¢ãã¬ã¹ã䞊ãã§ããŸããããæ£ããèªèãããŠããªãå Žåã¯ããã§æ¢ãŸã£ãŠããŸããŸãã
ãã§ããããScan startedã§æ¢ãŸã£ãŠããŸã£ãå Žåã¯ãæ£ããI2Céä¿¡çšã¢ãžã¥ãŒã«ãArduinoåŽããèªèã§ããŠããŸãããããæ¥ç¶ãªã©ãèŠçŽãå¿ èŠããããŸãã
ä»åã®ãŸãšãïŒã¢ãã¬ã¹ååŸãããŠæ£ããèªèãããŠããããã§ãã¯
ãä»åã¯I2Céä¿¡çšã¢ãžã¥ãŒã«ããArduinoã§èªèã§ããŠãããã®ãã§ãã¯æ¹æ³ã«ã€ããŠã玹ä»ããŸãããI2Céä¿¡ãšãããšãé ç·ã5V,GMD,SCL,SDAãš4æ¬ã ãã§æ軜ãªã®ã§ãããããŸãéä¿¡ã§ããªãã£ãå Žåã«ã©ããåå ããããã«ããã§ãããã
ããããªãšããã®æ¹æ³ã䜿ãã°ãArduinoã«ã¯èªèãããŠãããã©ããã§å¯ŸåŠæ³ãå€ããããšãã§ããŸããã€ãŸãèŠå ã®åãåããå¯èœãšããããšã§ããã
ãããŸããã®æ¹æ³ã䜿ã£ãŠI2Céä¿¡ã䜿ãããªããŠã¿ãŠãã ãããã
ã³ã¡ã³ã