Raspberry Pi 2 ã§ã¨ã¢ã³ã³æä½ï¼èµ¤å¤ç·ãªã¢ã³ã³ç·¨ï¼
çæã§å¸°å®
æã®é¨å±ã®æãã«èãåããªãï¼
帰å®
åã«ã¨ã¢ã³ã³ã稼åããã¦å®¤æ¸©ãä¸ãããï¼
ããã ãå¤é¨ããRaspberry Pi 2 çµç±ã§ã¨ã¢ã³ã³ãæä½ãããï¼
ã¨æã£ã¦ããããï¼æãçµããã«å·®ãæãããæ¥ã«æ¶¼ãããªã£ã¦ãã¦å®å
¨ã«ææãéãã¦ãã¾ã£ãã
æ®æã¨ã¯ä½ã ã£ãã®ãã
æ°ãåãç´ãã¦ãå¬ã®å¯ãã«åãã¦ãå¤ããã¨ã¢ã³ã³ãæä½ããä»çµã¿ãæ§ç¯ãããã¨ã«ããã
å¿ è¦ãªæ©è½
å¤ããã¨ã¢ã³ã³ãæä½ããä»çµã¿ãæ§ç¯ããã«å½ãããæä½ä»¥ä¸ã®ï¼ã¤ã®ä»çµã¿ãå¿ è¦ããã
- Raspberry Pi 2 ãã赤å¤ç·ã§ã¨ã¢ã³ã³ãæä½ãã
- Raspberry Pi 2 ãã¤ã³ã¿ã¼ãããçµç±ã§é éæä½ãã
ä»åã¯ã1ã® Raspberry Pi 2 ãã赤å¤ç·ã§ã¨ã¢ã³ã³ãæä½ããæã¾ã§ãå®é¨ãã¦ã¿ãã
ç¨æãããã®
- Raspberry Pi 2
- 赤å¤ç·LED(OSI5FU5111C-40)
- 赤å¤ç·ãªã¢ã³ã³åä¿¡ã¢ã¸ã¥ã¼ã«(OSRB38C9AA)
- æµæï¼100Ωç¨åº¦ï¼
赤å¤ç·ã使ãæºå
ã¨ã¢ã³ã³ãæä½ããã«ã¯ã
- ã¨ã¢ã³ã³ã®èµ¤å¤ç·ãªã¢ã³ã³ã®ã³ã¼ãã赤å¤ç·åä¿¡ã¢ã¸ã¥ã¼ã«ã«ç §å°ãã¦Raspberry Pi 2 ã«è¦ãããã
- è¦ããããã³ã¼ãã赤å¤ç·LEDããç §å°ãã¦ã¨ã¢ã³ã³ãæä½ãã
ã®2段éã®å·¥ç¨ãå¿ è¦ã
赤å¤ç·LED㯠GPIO20
赤å¤ç·åä¿¡ã¢ã¸ã¥ã¼ã«ã¯ GPIO21
ã«æ¥ç¶ãããã¨ã«ãããã
ã¾ãã¯åè·¯ãçµãåã«å¿
è¦ãªã¢ã¸ã¥ã¼ã«çãã¤ã³ã¹ãã¼ã«ããã
LIRCã®ã¤ã³ã¹ãã¼ã«
$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get install lirc
LIRCã®è¨å®ãã®ï¼
$ sudo vim /etc/lirc/hardware.conf
hardware.confã以ä¸ã®æ§ã«ä¿®æ£ããã
# /etc/lirc/hardware.conf # # Arguments which will be used when launching lircd LIRCD_ARGS="--uinput" #Don't start lircmd even if there seems to be a good config file #START_LIRCMD=false #Don't start irexec, even if a good config file seems to exist. #START_IREXEC=false #Try to load appropriate kernel modules LOAD_MODULES=true # Run "lircd --driver=help" for a list of supported drivers. DRIVER="default" # usually /dev/lirc0 is the correct setting for systems using udev DEVICE="/dev/lirc0" MODULES="lirc_rpi" # Default configuration files for your hardware if any LIRCD_CONF="" LIRCMD_CONF=""
èµ·åæã«LIRCãæå¹ã«ããã
$ sudo vim /boot/config.txt
/boot/condig.txt ã®æ«å°¾ã«ä»¥ä¸ã®è¡ã追å
dtoverlay=lirc-rpi,gpio_in_pin=21,gpio_out_pin=20
ä¸æ¦åèµ·åããã
sudo reboot
åèµ·åå¾ãLIRCãæå¹ã«ãªã£ã¦ããã確èªãã
$ lsmod | grep lirc lirc_rpi 6638 0 lirc_dev 8169 1 lirc_rpi rc_core 16956 1 lirc_dev
åè·¯
åè·¯ã¯ä»¥ä¸ã®éããã¢ã¼ã¿ã¼å¶å¾¡ã«æ¯ã¹ãã大åç°¡ç´ ã
å³ã«ããã¨ã·ã³ãã«ã ããå®éã¯æå
ã«æµæã330Ωã®ãã®ããç¡ãã£ãã®ã§ãæµæãä¸ããããã«6å並åã«ä¸¦ã¹ã¦ç¹ãã§ããã
ãªã¢ã³ã³ã®å信確èª
$ sudo /etc/init.d/lirc stop $ mode2 -d /dev/lirc0
ã¨ã¢ã³ã³ã®ãªã¢ã³ã³ã赤å¤ç·åä¿¡ã¢ã¸ã¥ã¼ã«ã«åãã¦é©å½ãªãã¿ã³ãæ¼ãã¦ã¿ã¦ãå¤ãªæåã®ç¾ åãæµãã¦ãããåä¿¡æåã ã¨ãããããå種ãã¿ã³ãæ¼ããæã®ãã¼ã¿ãåå¥ã«ä¿åããã
$ mode2 -d /dev/lirc0 | tee airon.dat $ mode2 -d /dev/lirc0 | tee airoff.dat
赤å¤ç·ãã¼ã¿æ´å½¢
ä¿åãããã¼ã¿ã¯ãã®ã¾ã¾ã§ã¯ãlircã§ã¯ä½¿ããªãã®ã§æ´å½¢ããå¿
è¦ãããã
以ä¸ã®pythonã¹ã¯ãªãããä½ã£ã¦å¤æããããã«ããã
#coding: UTF-8 import sys argvs = sys.argv argc = len(argvs) if (argc < 2): print 'Error: argument not enough' quit() f = open(argvs[1]) line = f.readline() # ä¸è¡ç®ã¯ä¸è¦ãªã®ã§èªã¿æ¨ã¦ã line = f.readline() count = 0 while line: print line.split(' ')[1].strip(), line = f.readline() count += 1 if (count > 20): # 1è¡ãé·ãããã¨å¾ã§å°ãçºé©å½ã«æ¹è¡ãå ¥ãã count = 0 print f.close
ä½æããã¹ã¯ãªããã§ä¿åãããã¼ã¿ãæ´å½¢ãã
$ python lirc_cut.py airon.dat > airon_parse.dat
LIRCã®è¨å®ãã®ï¼
$ sudo vim /etc/lirc/lircd.conf
/etc/lirc/lircd.confã«å
ã»ã©æ´å½¢ãããã¼ã¿ã追å ãã¦ã³ãã³ãã«ããã
ã©ããè¨å®ãã¡ã¤ã«ã®1è¡ãé·ãããã¨lircãã¨ã©ã¼ãåºãããã§ã対çã®ããæ´å½¢ãã¼ã¿ãé©å½ãªé·ãã§æ¹è¡ããããã«ããã
# Please make this file available to others # by sending it to <[email protected]> # # this config file was automatically generated # using lirc-0.9.0-pre1(default) on Sat Mar 22 16:16:12 2014 # # contributed by # # brand: # model no. of remote control: # devices being controlled by this remote: # begin remote name aircon flags RAW_CODES eps 30 aeps 100 gap 200000 toggle_bit_mask 0x0 begin raw_codes name off 420 450 373 506 367 493 375 493 380 507 377 25279 3425 1794 383 1359 396 475 386 488 378 490 378 1360 379 494 378 491 379 491 378 493 420 1320 380 492 378 1360 381 1359 379 493 (çç¥ï¼ name on 401 496 377 497 372 500 368 505 366 525 357 25256 3450 1770 409 1332 415 488 376 514 365 480 383 1333 404 493 380 488 379 492 380 489 381 1335 408 488 381 1334 406 1334 407 489 (çç¥ï¼ name cooler28 360 534 325 547 352 516 325 544 326 544 327 25318 3400 1820 355 1386 354 544 326 545 326 543 327 1386 355 569 301 544 326 544 326 544 327 1385 355 544 326 1387 354 1385 355 544 (çç¥ï¼ name heater26 430 485 385 440 427 467 409 441 428 464 415 25227 3480 1741 431 1309 457 419 431 438 431 445 425 1305 433 467 404 451 420 466 405 464 405 1311 429 465 403 1309 436 1317 420 445 (çç¥ï¼ end raw_codes end remote
ããã§ã¨ã¢ã³ã³ãæä½ããæºåãæ´ã£ãã
ã¨ã¢ã³ã³æä½
LIRCåèµ·å
LIRCãèµ·åããã
$ sudo /etc/init.d/lirc start
ããã§ã¨ã©ã¼ãåºãå ´åã¯ã/etc/lirc/lircd.confã®è¨å®ãããããã®ã§è¦ç´ããã¨ã
ãªã¢ã³ã³ã³ãã³ãã®ç¢ºèª
以ä¸ã®ã³ãã³ãã§ãªã¢ã³ã³ã³ãã³ãã®ç¢ºèªãåºæ¥ãã
å
¨ã¦è¡¨ç¤ºããã¦ããã°åé¡ãªãã
$ irsend LIST "" "" irsend: aircon $ irsend LIST aircon "" irsend: 0000000000000001 off irsend: 0000000000000002 on irsend: 0000000000000003 cooler28 irsend: 0000000000000004 heater26
赤å¤ç·ç §å°
ããããRaspberry Pi 2 ããã¨ã¢ã³ã³ãæä½ããã
$ irsend SEND_ONCE aircon on
ã¨ã¢ã³ã³ã®é»æºãONã«ãªãã°æåã
å®éã¯ã赤å¤ç·LEDã®åããåãããã®ãã·ãã¢ã ã£ãããåºåãå¼±ãã®ã1mç¨åº¦ã®è·é¢ã¾ã§èµ¤å¤ç·LEDãè¿ã¥ããªãã¨é»æºãONã«ãªããªãã£ãã
æ¹åããã«ã¯ã赤å¤ç·LEDã®åºåãä¸ããã®ã¨ãLEDãã£ããã被ãã¦æ¡æ£ãããã¨ããå¦ç½®ãå¿
è¦ã«ãªãããã
ããããä»å使ã£ã赤å¤ç·LED(OSI5FU5111C-40)ã®å®æ ¼ã100mAã§ãä»å使ã£ãæµæãåææµæ55Ωã§ãRaspberry Pi 2ã®GPIOã®é»å§ã5Vã ã¨ãã¦ã90mAç¨åº¦ã®é»æµãªã®ã§ãã以ä¸åºåãä¸ããã®ãé£ãããã
ãã£ã¨åºåãé«ã赤å¤ç·LEDã«å¤æ´ããæ¹ãããã®ãããããªãã
ã¨ãããã
ä»åã¯Raspberry Pi 2ããã¨ã¢ã³ã³ãæä½ããäºãã§ããããã«ãªã£ãã
次åã¯ãRaspberry Pi 2ãé éæä½ããä»çµã¿ã«ã¨ããããããã