ç§ãã¡ã¯ãã»ã³ãµãŒèªäœãšãã®ãã³ãå«ããã¹ãŠã®ãã®ãå€ããå°ãªããïŒå€ããå°ãªããé¡ã£ãŠããŸãïŒãArduinoã®ã©ã®ãã³ã«æ¥ç¶ãããŠããã®ãããããŠãªããŸã æ確ã§ã¯ãªããšããäºå®ã«èœã¡çããŸããã ãã®è³ªåã«çããŸãããã
Arduinoã®ãã³
ãããã«ã¯Arduino Nanoãå«ãŸããŠããŸãïŒå°åã§ã移åãªããžã§ã¯ããããŒã¿ãã«ãªããžã§ã¯ãã®ãããã¿ã€ãã³ã°ã«é©ããŠãããããå¶ç¶ã«éžæãããŸããïŒã 圌女ã®ããããã®çŽ æŽãããã¢ã¬ã³ãžã¡ã³ãããããŸãïŒããã ãã§ã¯ãããŸããããäœãããæ°ã«å ¥ã£ãŠããŸãïŒã
ããã€ã¹ã®åè·¯å³ã®ããã«ããããŸã§ã®ãšããããã®åè·¯ã®2ã€ã®éšåã«ã®ã¿æ³šæãæããŸãã
å·ŠåŽã«ã¯ãã³5ãš6ããããŸãã ãã¹ãã®æåã®éšåã®ããã€ã¹ã®åè·¯å³ãããäžåºŠèŠãŠãã ããã K4ãšK5ããããã³D5ãšD6ã«æ¥ç¶ããŸãã ããã¯ãçŸåšäœæ¥ããŠããã·ãŒã«ããããããã®ãã³ã䜿çšããŠãããã®æ¥ç¹ããé»å§ã\ã«è»¢éããããšãæå³ããŸãã è«çãŠãããã¯5 Vã§ãããããã£ãŠããããã®æ¥ç¹ã«äœããæ¥ç¶ããããšã«ããããããã®ãã³ããä¿¡å·ãåä¿¡ããŸãã
ååãšããŠãããšãã°ãæ¢è£œã®ã·ãŒã«ãã§ã¯ãªã審è°ããŒãäžã§ãããã¿ã€ããçµã¿ç«ãŠãå Žåãã»ã³ãµãŒãç¹å®ã®Arduinoãã³ã«çŽæ¥æ¥ç¶ã§ããŸãã ãã®å Žåãã·ãŒã«ãã¯ãããã€ã¹ãæã«ç ããªãããã«ãããŒãäžã§ããã€ã¹ã䟿å©ãã€çŸããçµã¿ç«ãŠãã®ã«åœ¹ç«ã¡ãŸãã
Arduinoã®ããã2æ¬ã®èãéžæããçç±ã¯äœã§ããïŒ 2ã€ã®çç±ïŒ
1.ç§ãã¡ã®ã¹ããŒã ã§ã¯ãç¡æãã®ãŸãŸã§ããã
2.ãããã¯ãä¿¡å·ãéåä¿¡ããããã«ããã°ã©ã ã§ããããžã¿ã«å ¥å/åºåã§ãã
æåŸã®ãã¬ãŒãºã«åºã¥ããŠãK4ãšK5ã«æ¥ç¶ããã»ã³ãµãŒãã³ãæšæž¬ããŸããïŒ å³ãããžã¿ã«å ¥åããã³åºåããã€ã¹ã
ãã¹ãã¹ãžã®æ³šæïŒ
Arduino Nanoã®ããžã¿ã«å ¥åãšåºåããŸãã¯ããžã¿ã«ã©ã€ã³ã¯ãã³D0ãD13ã§ãã ããžã¿ã«ãšã¢ããã°ã®äž¡æ¹ã®A0-A5ã«ããããšãã§ããŸãã ã¢ããã°A6ãA7ã®ã¿ã
ä¿¡å·ãéåä¿¡ããããã€ã¹ã¯Arduinoã®ããžã¿ã«å ¥å/åºåã«æ¥ç¶ã§ããããã枩床ã湿床ãè²ãé³ãå ãªã©ã®ã»ã³ãµãŒããŸãã¯ãšã°ãŒã¯ãã£ããªã©ãä»ã®ã»ã³ãµãŒãŸãã¯ã³ã³ããŒãã³ããããã«è¿œå ããããšãã§ããŸãããã€ã¹ãããšãã°ãªã¬ãŒã
ããã¯å°æ¥ã®éèŠãªæ å ±ã§ããããã¯ãã©ã®ã³ã³ããŒãã³ããã©ã®ããã«MKã«æ¥ç¶ããç¬èªã®ãããã¿ã€ããŸãã¯ããã€ã¹ãäœæã§ããããç¥ãããšãã§ããããã§ãã
Arduinoãä»ããé»æºæ¥ç¶
ããŠã2ã€ã®ã»ã³ãµãŒãã³ãèŠã€ããŸããã ã»ã³ãµãŒé»æºã®æ¥ç¶å -æ®ãã®2ã€ã®ãã³ã®ãã©ã¹ãšãã€ãã¹
Arduinoã«ã¯ã亀æå¯èœãªé»æºæ¥ç¶ãããã€ããããŸãã ãã®å Žåãå®æããããã€ã¹ïŒã©ãžãªïŒãããããªãŒïŒå¹²æžããªãããã«ãã¯ãã ä»ããããŠããªãããããªãŒã³ã³ããŒãã¡ã³ãïŒãšUSBãä»ããŠæ¥ç¶ã§ããŸãã å ¥ãå£ã®ãã¡ãã¡ã§5ãã«ããå¿ èŠã§ãã
ãã ããçŸåšãŸã§ãä¿¡å·ãéåä¿¡ããããã«Arduinoãã³ã«æ¥ç¶ããã2ã€ã®ã»ã³ãµãŒãã³ããããã»ã³ãµãŒã®é»æºãã³ã¯ç¡æã§ãã æãéããããŸãïŒ Arduinoã®äžéšã«ãããã³ã«ããããæ¥ç¶ã§ããŸãïŒãã³ã¬ã€ã¢ãŠãã®äžéšãåç §ïŒã ããã¯ãå³ã§ICSPãšããŠç€ºãããŠããéšåã§ãã ãããã«ã¯ãã³ïŒ1ãä»ããŠããŸãã 次ã«ããã³ã¯ãã¢ã§é 眮ãããŸãã
1ããã³2ïŒ2ã¯PlusãVccïŒ
3ãš4
5ããã³6ãããã§6-ãã€ãã¹ãGrndãã°ã©ãŠã³ã
ããã§ã¯ããã¹ãŠã5ãã«ãã®åãé»å§ã§ãã ããã«ã»ã³ãµãŒãæ¥ç¶ã§ããŸããïŒ ããšãã°ãæµæãå¿ èŠã§ããïŒ åœŒã®ããã©ãŒãã³ã¹ç¹æ§ãèŠãŠã¿ãŸããã ã
äŸçµŠé»å§ïŒ5 V
éé³æ¶è²»ïŒ2mA
è·å Žã§ã®æ¶è²»ïŒ15mA
æ£è§£ã¯æ¬¡ã®ãšããã§ãã æµæã¯å¿ èŠãããŸããã
éèŠïŒãã©ã¹ãšãã€ãã¹ãæ··ãããšãåããŠArduinoãçãããªãå ŽåããããŸãã äžéšã®ã³ã³ããŒãã³ãã¯å ç±ãããäžéšã¯çºç ãå§ããå ŽåããããŸãã ããããäœããçãå°œãããšãããããã»ã³ãµãŒã«ãªããŸãã ããã®é»æ±ã¯æ··åããã5 Vã®ä»£ããã«-5 Vã«ãªããŸããã€ãŸããã»ã³ãµãŒã®é»å§ã¯èš±å®¹é床ïŒTTXã«ãããš5 VïŒãè¶ ããŸãã
ã³ã³ããŒãã³ãã®çµã¿ç«ãŠ
æ¡åŒµããŒããä»ããŠArduinoãšã»ã³ãµãŒãæ¥ç¶ãããšã次ã®ããã«ãªããŸãã
äžã«ç€ºããããã«æ¥ç¶ããã·ãŒã«ããArduinoãã»ã³ãµãŒã®ã¿ãããã«è¡šç€ºãããŸãã æ°ããã»ã³ãµãŒãæ©èœããŠãããã©ããã¯ãŸã ããããªããããä»ã®ãã¹ãŠã®ã³ã³ããŒãã³ãã¯ãŸã å¿ èŠãããŸããã ArduinoãããŒãäžã®æå®ã®å Žæã«åãäžããããŠããã°ãã»ã³ãµãŒããã¹ãããæºåããã¹ãŠæŽããŸãã ãããã£ãŠããã¹ãŠãããŒããŠã§ã¢ã§ããã«é²ãã§ãããããã°ã©ãã³ã°ã®çªã§ãã
ãã®æ®µéã§ãç§ã®ããã«ãã®ãããã®æ¡åŒµã«ãŒãã䜿çšããŠããªãå Žåã¯ãå¿ èŠãªArduinoãã³ã«ã»ã³ãµãŒãçŽæ¥æ¥ç¶ããŠãå ã«é²ãããšãã§ããŸãã ç¹°ãè¿ãã«ãªããŸãããæ®å¿µãªãããArduinoãŸãã¯ã»ã³ãµãŒãæ¥ç¶ããŠæžã蟌ã¿ãè¡ããšãã«äœããæ··åããŠããæçš¿è ã¯è²¬ä»»ãè² ããŸããã ã ãã泚æããŠãã ããã
ããã°ã©ãã³ã°ïŒã»ã³ãµãŒãã¹ã
ååã¯ãããã€ã¹å šäœã®æäœã®ã¹ã±ãããšãåã ã®ã³ã³ããŒãã³ãã®æäœã®ãã©ã€ããŒã©ã€ãã©ãªãèªã¿èŸŒãæ¹æ³ãåŠã³ãŸããã IDEã¯ã»ãŒiTunesã®ããã«åäœãããã¬ãŒã€ãŒã®é³æ¥œã«äŒŒãããã°ã©ã ãMKã«ããŠã³ããŒãããããã«æãããŸããã ãã ããããã§è¿œå ã®æ©äŒãèŠã€ãããŸããIDEã䜿çšãããšãæ°ããã»ã³ãµãŒã«çŽæ¥pingãå®è¡ãããã®åäœã確èªããŠèª¿æŽããããšãã§ããŸãã æ¹æ³ã¯æ¬¡ã®ãšããã§ãã
ã¹ããã1ïŒ ã»ã³ãµãŒã®ã©ã€ãã©ãªãããŠã³ããŒãããŸã ã ã©ã€ãã©ãªã®æäœæ¹æ³ãã¹ã±ããã®æ¹æ³ãããããªãå Žåã¯ã ãã¡ãã§ç°¡åã«åŠç¿ã§ããŸã ã
æé 2ïŒããã¹ããšãã£ã¿ãŒã§NoBlindDemo2ã®äŸãéããŸãã
ããã¯.pdeãã¡ã€ã«ã§ã-ããã¯Processin gãã¡ã€ã«ã®æ¡åŒµåã§ãã ããã¯åãã¹ã±ããã§ãã Arduinoç°å¢ã¯åŠçç°å¢ã«åºã¥ããŠãããããArduinoã¯.inoãã¡ã€ã«ã«å ããŠ.pdeã¹ã±ãããã¡ã€ã«ãèªèããŸãã Arduinoã®ãã®ä»ã®ãã¡ã€ã«ã¿ã€ããšãé©åãªååã®ä»ãæ¹ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã
䜿çšããI / Oã©ã€ã³ãåå²ãåœãŠããŠãã¹ã±ãããä¿åããŸãã
TRIGGER_PINã®å ŽåãECHO_PIN-6ã®å Žåã¯5ãæå®ããŸãã
ãªããããããã®ã§ããïŒ ããªã¬ãŒã»ã³ãµãŒãã³ãMKãããªã¯ãšã¹ããåä¿¡ããå Žåã5çªç®ã®Arduinoãã³ã«éä¿¡ãããŸãã ãã決ããŸããã ãæ°ä»ãã®ããã«ã5ã€ã®ãã³ãš5ã€ç®ã®ãã³ã2ã€ãããŸããããã«ã€ããŠã¯æ¢ã«äžèšã§èª¬æããŸããã ãããã£ãŠãEchoã¯ã»ã³ãµãŒããArduinoã«ããŒã¿ãéä¿¡ãã6çªç®ã®ãã³ã«éä¿¡ããŸãã
ãã®ã¹ã±ããã§äœ¿çšãããŠããã³ãã³ãã«æ³šæããŠãã ããã
ã¹ã±ããã®åç·ã¯ã»ãã³ãã³ã§çµãã£ãŠããããšã«æ³šæããŠãã ããã ãŸããäžæ¬åŒ§ã«æ³šæããŠãã ãã-ãããã¯é©åãªã¿ã€ãã³ã°ã§ééããŸãã ãŸããã¹ã±ããã¯2ã€ã®éšåã«åãããŠããããšã«æ³šæããŠãã ããã
ãã€ãèšå®ïŒïŒ{}
ãã®ããŒãã§ã¯ãããã°ã©ã ã®æåã«äžåºŠèµ·ããããšãæžããŸãã ç§ãã¡ã®arduinoã¯ãåžæã®é床ã§ã·ãªã¢ã«ããŒãã«æ¥ç¶ãã枬å®ã«è¡ã£ãããšãæžã蟌ã¿ãŸãã
ç¡å¹ã«ãŒãïŒïŒ{}
ãµã€ã¯ã« ãã®ããŒãã§ã¯ãMKã®é»æºãåããŸã§ç¹°ãè¿ãããå 容ãæžããŸãã ãã®å Žåãã»ã³ãµãŒã«ãã50 msããšã®è·é¢æž¬å®ã
ããã°ã©ã ã®åéšåã¯ãããããã®{}
//ããã°ã©ã ãç¡èŠããåŸã«æžãããŠããã®ã¯ãã³ãŒãéçºè ã®ã³ââã¡ã³ãã§ãã ã芧ã®ãšããããã®ã³ãŒãã¯ããã¹ãŠã«ã³ã¡ã³ãããéåžžã«è²¬ä»»ã®ããæ£ç¢ºãªéçºè ã«ãã£ãŠäœæãããŸããã
ã¹ããã3ïŒ Arduinoã§æ°ããã¹ã±ãããããŠã³ããŒãããŸãã
ããããã£ãããšããªãå Žåã¯ããŸããã®æ¹æ³ãæããŠãã ããã
éèŠïŒ Arduinoã§ã®æäœã®åã«ãããŒãããããŒããåãå€ããé»æºããªãã«ããŸãã
ã¹ããã4ïŒ ArduinoãUSBããåæããŸãã ããŒãã«çœ®ããŠãã»ã³ãµãŒãæ¥ç¶ããŸãã USBãã³ã³ãã¥ãŒã¿ãŒã«åæ¥ç¶ããŸãã
ãããããIDEãéããŠå床éãå¿ èŠããããŸãã ããã§ãããã€ã¹ããµãŒãã¹-ã·ãªã¢ã«ããŒãã§æ€åºãããªãå ŽåããããŸãã å¿é ããªãã§ãã ãããããã¯ãã°ã§ãã ãã¹ãŠãåæããŠåèµ·åããã ãã§ãã
ãã¹ãŠåãã§ãArduinoãããŒãã«è¿œå ããã ãã§ãã +ãš-ãæ··åããŠããªãããšã確èªããŠãã ãããæ··åããŠããªããšãå°çã倩軞ã«é£ã³ãŸãã
éèŠïŒèšäºã®èè ã¯ãArduinoãçŒãä»ããŠã責任ãè² ããŸããã MKã§ã®ãã¹ãŠã®æäœã¯ãèªåã®è²¬ä»»ãšãªã¹ã¯ã§è¡ã£ãŠãã ããã
åå確èªããå ŽæïŒ
ããã§USBãæ¥ç¶ã§ããŸãã
ã¹ããã5ïŒ IDEãèµ·åããŸãã Arduinoãå²ãåœãŠãããããŒãã§ãã³ã°ããããšã確èªããŸãã
ãµãŒãã¹âã·ãªã¢ã«ããŒãâããŒãã¯ããã«èªåçã«ç»é²ãããŸãã ããã§ãªãå Žåãç¢æå šäœãç°è²ã«ãªãããã¹ãŠãåèµ·åããå¿ èŠããããŸãã
ã¹ããã6ïŒ[ããŒã«]â[ããŒãã¢ãã¿ãŒ]ãéžæããŸãã
ã¹ã±ããã«å¯Ÿå¿ããé床ãå³äžé ã®115200ããŒã«èšå®ãããŠããããšã確èªããŸãã
ããã°ã©ã ã«ç€ºãããŠããé床ã«å¯Ÿå¿ããé床ãéžæããŸãã æ¢ã«ãã®é床ãèšå®ããŠããå ŽåãArduinoãã»ã³ãµãŒã«æ¥ç¶ããçŽåŸïŒããŒãã®1ã€ã§æ€åºãããåŸïŒãã¢ãã¿ãŒãå®è¡ããã50ããªç§ããšã«è·é¢å€ã衚瀺ãããŸãã
é»æºãå ¥ãããšãã»ã³ãµãŒã¯ããŒãã«ã®äžã«æšªãããã倩äºãèŠãŠããŸããããããããââãããã«ãã»ã³ãµãŒã¯180 cmã§ããã
ã¹ããã7ïŒæãã»ã³ãµãŒã«è¿ã¥ããŸãã 圌ã®èšŒèšãã©ã®ããã«å€åããããèŠãŠãã ããã ç§ã®å Žåã次ã®ãããªãã®ã§ããã
ããã§ãšãããããŸãïŒã»ã³ãµãŒãåäœããŸãïŒ çµæãã·ãªã¢ã«ããŒãã«éä¿¡ãããã¹ãã¹ã±ããã§ãã¹ãããŸããã
è¶ é³æ³¢Arduinoã©ãžãª
çŸåšæ®ã£ãŠããã®ã¯ã次ã®2ã€ã§ãã
1.æ®ãã®ãã¹ãŠã®ç¡ç·ã³ã³ããŒãã³ããã·ãŒã«ãã«æ»ããŸãã
2.ç¡ç·ãšã»ã³ãµãŒãçµã¿åãããã¹ã±ãããArduinoã«ã¢ããããŒãããŸãã ãã®ããã«ã¯ãæšæºçãªã©ãžãªã®ã¹ã±ãããåããããã«äœããæžãå¿ èŠããããŸãã
ããããå®éã«ã¯ãããã¯ãã§ã«éçŸå®çãªã¯ãŒã«ã§ãã è¶ é³æ³¢å®èŠãåéãããšãããããŒãã«ããå£ãçªããã£ãããããªã©ãèªå® ãŸã§ã®è·é¢ãå®å šã«ææ¡ã§ããŸããã ååã«ãã¬ã€ããã®ã§ãæ°ããã»ã³ãµãŒã§ã©ãžãªãåæ§ç¯ããããã«äœ¿çšããŸããïŒ
ãããã®ã©ã€ãã©ãªã¯ã»ããèªäœçšã§ã
ã»ã³ãµãŒã©ã€ãã©ãª
ãã®ã¹ã±ãã
ã©ãžãªå±ãå€æŽããŸãã
ã©ãžãªå±ãå€æŽããã«ã¯ãè·é¢ã5 cmåäœã§å€æŽããå¿ èŠããããŸãã
ã»ã³ãµãŒã«è¿ã¥ã-ã¹ããŒã·ã§ã³ãç¯å²å ã«åãæ¿ãã
ã»ã³ãµãŒããã®è·é¢-ç¯å²å ã§ã¹ããŒã·ã§ã³ãåãæ¿ããŸãã
è·é¢å€æŽã¹ãããã¯ãå®æ°DISTANCE_STEPã«ãã£ãŠåçãããŸãã
ãã®å€ã¯å€æŽã§ããŸãã
ã¹ããŒã·ã§ã³ãã¥ãŒãã³ã°ã¢ãŒããçµäºããŸãã
ã¹ããŒã·ã§ã³ã調æŽããåŸãã»ã³ãµãŒãŸã§ã®è·é¢ã5ç§éå€æŽããªãã§ãã ããã
ãã¥ãŒãã³ã°ã¯çŸåšã®ã¹ããŒã·ã§ã³ã®ä¿®æ£ã§çµäºããŸãã ãåºå®ãäžã«è²¬ä»»ããããŸã
å®æ°EXIT_TUNE_TIMEã å¿ èŠã«å¿ããŠããã®å€ãå€æŽã§ããŸãã
Arduinoã§ã®æ°ããããã€ã¹ã®çµã¿ç«ãŠãããã§ãšãããããŸãã 次ã®2ã€ã®æçš¿ããå€ãã®ããšãåŠã³ãŸããã
1.æ°ããã»ã³ãµãŒã®ç¹æ§ãå解ãããªã³ã¯ã®åªããã³ã¬ã¯ã·ã§ã³ããŸãšããŸããã
2. Arduinoãšæ¡åŒµããŒãã§ãã³ãéžæããæ¹æ³ãåŠã³ãŸããã
3.ãã¿ãŒã³ãšããŒã¿ã·ãŒããããã²ãŒãããæ¹æ³ãåŠã³ãŸããã
4.æ°ããã»ã³ãµãŒããããžã§ã¯ãã«å°å ¥ãããåã§ããæ°ããã»ã³ãµãŒããã¹ãããæ¹æ³ãåŠã³ãŸããã
5.å®æããããã€ã¹ãçµã¿ç«ãŠãŠããã°ã©ã ããŸããã
ãããŠïŒåžæïŒããªãã¯ãéãã§èªç±ã«æããŠããŸããããããŸã§ç§ãã¡ã¯ã»ã³ãµãŒããã¹ãããããã«1ã€ã®ã¹ã±ããã ããå解ããããšããããšãèŠããŠããããšãéèŠã§ãã ãããã£ãŠãä»ããæ°ããããã€ã¹ã®ã¹ã±ãããäœæãŸãã¯å€æŽããå¿ èŠãããå Žåã¯ããŸã æºåãã§ããŠããªãå¯èœæ§ããããŸãã æ°ããæçš¿ããã©ããŒãã 賌èªããŠãã ãã-ç§ãç¥ã£ãŠããããšããããŠå°æ¥ã®æçš¿ã§ã§ããããšãããªããšééããªãå ±æããŸãã
ãªããªãŒãã£ãªè·é¢èšã䜿çšããã®ã§ããïŒ ãããžã§ã¯ããå€æŽããŠè£è¶³ããã«ã¯ã©ãããã°ããã§ããïŒ ã³ã¡ã³ããžããããïŒ
// ** PSã³ã¡ã³ãã§ã¯ãããŒãšã¯äœããé床ãç°ãªãçç±ãéèŠãªããšã説æããããã®ã³ã³ãã¹ãã宣èšããŠããŸãã è³åã¯ãããŸããããç§ã¯åãã§ããªãã®èª¬æãç解ããããšããŸãã