라즈베리파이 LIRC(적외선 송수신) 설정

서론

외국인을 위한 튜토리얼은 차후 작성할 예정입니다.
For english developer, I’ll release guide(tutorial) in english as soon as possible.

라즈비안과 lirc의 버전이 올라가면서 웹상의 많은 강좌들을 따라했을 때 제대로 작동하지 않는 문제점들이 있었습니다. 이에, 제가 라즈베리파이로 lirc 기능을 구현하면서 설정했던 방법을 강좌로 다루고자 합니다.

기존의 강좌와 다른점은 강조 표시를 하겠습니다.

개발환경

본 강좌에서 사용한 라즈비안 버전, lirc 버전은 아래와 같습니다.

Raspberry Pi 1 B+ model version specification.

pi@raspberrypi:~ $ cat /proc/version
Linux version 4.9.48+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #1034 Fri Sep 8 13:55:13 BST 2017

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.9.48+ #1034 Fri Sep 8 13:55:13 BST 2017 armv6l GNU/Linux

pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd version
Sep 8 2017 15:49:41
Copyright (c) 2012 Broadcom
version 6929ccae610034e2279dd785c74455086b55f095 (clean) (release)

LIRC version.

pi@raspberrypi:~ $ lircd –version
lircd 0.9.4c

참고로, ‘(pi@raspberrypi:~ )$’으로 시작하는 줄은 직접 입력한 명령어를 뜻합니다.

 

1. 설치

apt-get install을 통해 간단하기 설치할 수 있습니다.

pi@raspberrypi:~ $ sudo apt-get install lirc

1.2 lircd 서비스의 실행과 종료

lirc의 서비스 데몬의 이름이 lirc에서 lircd로 변경되었습니다. 그리고 ‘service lircd start’나 ‘systemctl start lircd’와 같이 ‘service’와 ‘systemctl’로 서비스를 시작/종료/상태확인을 하는 경우 로그가 출력되지 않으니 아래와 같이 init.d로 서비스를 실행 종료하여주시기 바랍니다.

서비스 시작

pi@raspberrypi:~ $ sudo /etc/init.d/lircd start
[ ok ] Starting lircd (via systemctl): lircd.service.

서비스 종료

pi@raspberrypi:~ $ sudo /etc/init.d/lircd stop
[….] Stopping lircd (via systemctl): lircd.serviceWarning: Stopping lircd.service, but it can still be activated by:
lircd.socket
. ok

서비스 상태 확인

pi@raspberrypi:~ $ /etc/init.d/lircd status
● lircd.service – Flexible IR remote input/output application support
Loaded: loaded (/lib/systemd/system/lircd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-09-13 06:54:31 UTC; 2min 11s ago
Docs: man:lircd(8)
http://lirc.org/html/configure.html
Main PID: 2662 (lircd)
CGroup: /system.slice/lircd.service
└─2662 /usr/sbin/lircd –nodaemon

Sep 13 06:56:38 raspberrypi lircd[2662]: lircd-0.9.4c[2662]: Info: Using remote: BRITZ-T3400.
Sep 13 06:56:38 raspberrypi lircd[2662]: lircd-0.9.4c[2662]: Info: Using remote: TIENA-custom.
Sep 13 06:56:38 raspberrypi lircd-0.9.4c[2662]: Info: Using remote: BRITZ-T3400.
Sep 13 06:56:38 raspberrypi lircd-0.9.4c[2662]: Info: Using remote: TIENA-custom.
Sep 13 06:56:42 raspberrypi lircd[2662]: lircd-0.9.4c[2662]: Notice: accepted new client on /var/run/lirc/lircd
Sep 13 06:56:42 raspberrypi lircd-0.9.4c[2662]: Notice: accepted new client on /var/run/lirc/lircd

리모컨 설정 파일(/etc/lirc/lircd.conf.d/ 폴더 내) 다시 불러오기

pi@raspberrypi:~ $ sudo /etc/init.d/lircd reload
[ ok ] Reload configuration for remote control daemon: LIRCD.

 

2. 설정

2.1 /boot/config.txt 설정

/etc/modules 파일을 수정하여 lirc_rpi 모듈을 불러오는 방식은 라즈베리파이에 DT가 도입되면서 의미가 없게 되었습니다. 아래의 방법을 통하여 부팅시 lirc-rpi 모듈을 호출하게 됩니다.

pi@raspberrypi:~ $ sudo nano /boot/config.txt

/boot/config.txt의 제일 마지막 줄에 아래의 문장을 추가합니다. (‘# dtoverlay=lirc-rpi’의 주석을 해제하고 수정해서 사용해도 동일합니다.

gpio_in_pin= 뒤에는 수신모듈을 연결한 핀의 GPIO## 번호를, gpio_out_pin= 뒤에는 적외선 LED를 연결한 핀의 GPIO## 번호를 각각 입력해줍니다. gpio_in_pin과 gpio_out_pin을 명시해주지 않으면(‘dtoverlay=lirc-rpi’ 만 입력하였을 때) 기본값은 각각 18과 17입니다.
(Raspberry 1 Model B+의 GPIO18은 실제 PIN12과, GPIO17은 실제 PIN11과 대응됩니다. 각 모델의 핀 배치를 확인하세요.)

dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17

또한 아래의 문장들도 위의 문장과 동일한 효력을 지닙니다.

dtoverlay=lirc-rpi:gpio_in_pin=18,gpio_out_pin=17

dtoverlay=lirc-rpi
dtparam=gpio_in_pin=18,gpio_out_pin=17

(https://www.raspberrypi.org/documentation/configuration/device-tree.md
3.2: DT PARAMETERS 참조)

2.2 /etc/lirc/lirc_options.conf 설정

lirc 0.9.4 버전 전후로 hardware.conf 파일 대신에 lirc_options.conf 파일을 수정하는 것으로 변경되었습니다. 실제로 hardware.conf파일이 /etc/lirc/ 폴더에 존재하지 않습니다. driver와 device 설정은 lirc_options.conf에서 합니다.

lirc_options.conf는 lircd, mode2, irw, irrecord 등에서 사용하는 기본 driver와 device를 설정해줍니다. 변경된 lirc_options.conf을 서비스 데몬에 반영하기 위해서는 서비스를 종료했다가 다시 시작해야합니다.

pi@raspberrypi:~ $ sudo nano /etc/lirc/lirc_options.conf

아래의 lirc_options.conf 내용 중 이탤릭, 강조 표시된 부분을 수정합니다.

# These are the default options to lircd, if installed as
# /etc/lirc/lirc_options.conf. See the lircd(8) and lircmd(8)
# manpages for info on the different options.
#
# Some tools including mode2 and irw uses values such as
# driver, device, plugindir and loglevel as fallback values
# in not defined elsewhere.

[lircd]
nodaemon = False
driver = default
device = /dev/lirc0
output = /var/run/lirc/lircd
pidfile = /var/run/lirc/lircd.pid
plugindir = /usr/lib/arm-linux-gnueabihf/lirc/plugins
permission = 666
allow-simulate = No
repeat-max = 600
#effective-user =
#listen = [address:]port
#connect = host[:port]
#loglevel = 6
#uinput = …
#release = …
#logfile = …

[lircmd]
uinput = False
nodaemon = False

# [modinit]
# code = /usr/sbin/modprobe lirc_serial
# code1 = /usr/bin/setfacl -m g:lirc:rw /dev/uinput
# code2 = …

# [lircd-uinput]
# release-timeout = 200

 

3. 설정 확인

mode2는 적외선 신호를 받은 그대로 출력해주는 명령어 입니다.  mode2를 사용할 때에는 lircd 서비스를 종료한 후에 사용해야 합니다. 사용법은 다음과 같습니다.

pi@raspberrypi:~ $ mode2 -h
Usage: mode2 [options]
-d –device=device Read from given device <- 적외선 신호를 읽을 장치를 지정합니다.
-H –driver=driver Use given driver <- 장치를 구동할 드라이버를 지정합니다.
(후략)

이 중에서 기존의 강좌에서 설정이 잘 되었는지 확인하기 위하여 mode2를 호출하는 일반적인 방법은 ‘mode2 -d /dev/lirc0’ 였습니다.  하지만, 제가 추천드리는 호출법은 아래와 같습니다.

$ mode2 -d /dev/lirc0 -H default

위의 호출로는 /boot/config.txt 설정만 정상이라면 /etc/lirc/lirc_options.conf 설정이 되지 않았더라도 lirc 테스트는 가능하기 때문입니다. 이 팁은 /etc/lirc/hardware.conf 파일을 수정하는 버전의 lirc에도 동일하게 적용됩니다.

아래의 명령어를 입력하여 lircd를 종료하고 mode2를 실행하여 리모컨의 버튼을 눌렀을 때 pulse와 space가 번갈아 나오면 정상입니다. 만약 예상했던 응답이 나오지 않을 경우에는 trubleshoot에서 회로 확인 또는 설정 확인 부분을 참고합시다.

pi@raspberrypi:~ $ sudo /etc/init.d/lircd stop
(중략)
pi@raspberrypi:~ $ mode2 -d /dev/lirc0 -H default
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
space ###
pulse ###
space ###
pulse ###

마지막으로 아래의 명령어를 입력하여 위와 비슷하게 pulse와 space가 번갈아 나오는지 확인합니다. lirc_options.conf 설정이 정상적으로 되었다면 mode2, irrecord를 device와 driver를 명시하지 않고도 정상적으로 작동합니다. 이 과정에서 pulse와 space가 나오지 않는다면 /etc/lirc/lirc_options.conf (또는 구버전인 경우 /etc/lirc/hardware.conf)의 설정을 다시 확인합니다.

pi@raspberrypi:~ $ sudo /etc/init.d/lircd stop
(중략)
pi@raspberrypi:~ $ mode2
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
space ###
pulse ###
space ###
pulse ###

여기까지 왔으면 lirc을 사용할 준비가 완료되었습니다.

4. 리모컨 설정값 추가하기

기존의 강좌들에서 lirc의 리모컨 설정값 파일(리모컨이름.conf)을 추가할 때 lircd.conf 파일에 포함할 리모컨 설정 파일들의 이름을 적어주거나 lircd.conf 파일을 직접 수정했습니다. 본 lirc 0.9.4 버전 전후로는 lircd.conf 파일이 아래와 같이 /etc/lirc/lircd.conf.d/ 폴더에 있는 모든 *.conf 파일을 불러오게 설정이 되어있습니다.

pi@raspberrypi:~ $ nano /etc/lirc/lircd.conf
# Populated config files can be found at http://sf.net/p/lirc-remotes. The
# irdb-get(1) and lirc-setup(1) tools can be used to search and download
# config files.
#
# From 0.9.2 config files could just be dropped as-is in the lircd.conf.d
# directory and be included by this file.

include “lircd.conf.d/*.conf”

따라서 확장자가 *.conf 인 리모컨 파일들을 그대로 cp 명령어를 통하여 /etc/lirc/lircd.conf.d/ 폴더에 넣어주면 서비스를 껐다 켜거나 다시 불러오기를 통해 리모컨 설정 파일을 아래와 같이 읽어옴을 확인할 수 있습니다.

pi@raspberrypi:~ $ ls /etc/lirc/lircd.conf.d/
BRITZ-T3400.lircd.conf devinput.lircd.conf.bak README.conf.d TIENA-custom.lircd.conf
pi@raspberrypi:~ $ sudo /etc/init.d/lircd reload
[ ok ] Reload configuration for remote control daemon: LIRCD.
pi@raspberrypi:~ $ sudo /etc/init.d/lircd status
● lircd.service – Flexible IR remote input/output application support
Loaded: loaded (/lib/systemd/system/lircd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2017-09-12 20:02:20 UTC; 2min 13s ago
Docs: man:lircd(8)
http://lirc.org/html/configure.html
Main PID: 832 (lircd)
CGroup: /system.slice/lircd.service
└─832 /usr/sbin/lircd –nodaemon

Sep 12 20:04:29 raspberrypi lircd[832]: lircd-0.9.4c[832]: Info: Using remote: BRITZ-T3400.
Sep 12 20:04:29 raspberrypi lircd[832]: lircd-0.9.4c[832]: Info: Using remote: TIENA-custom.
Sep 12 20:04:29 raspberrypi lircd-0.9.4c[832]: Info: Using remote: BRITZ-T3400.
Sep 12 20:04:29 raspberrypi lircd-0.9.4c[832]: Info: Using remote: TIENA-custom.
Sep 12 20:04:32 raspberrypi lircd[832]: lircd-0.9.4c[832]: Notice: accepted new client on /var/run/lirc/lircd
Sep 12 20:04:32 raspberrypi lircd-0.9.4c[832]: Notice: accepted new client on /var/run/lirc/lircd
Sep 12 20:04:32 raspberrypi lircd[832]: lircd-0.9.4c[832]: Info: removed client
Sep 12 20:04:32 raspberrypi lircd-0.9.4c[832]: Info: removed client
Sep 12 20:04:33 raspberrypi lircd[832]: lircd-0.9.4c[832]: Notice: accepted new client on /var/run/lirc/lircd
Sep 12 20:04:33 raspberrypi lircd-0.9.4c[832]: Notice: accepted new client on /var/run/lirc/lircd

 

Trubleshoot

각 출력 정보는 재부팅을 하여 갓 부팅했을 때 상황입니다.

/boot/config.txt 설정 안됨.

(/etc/lirc/lirc_options.conf 설정은 관계없음)

pi@raspberrypi:~ $ dmesg | grep lirc
[ 29.507572] input: lircd-uinput as /devices/virtual/input/input0

pi@raspberrypi:~ $ sudo /etc/init.d/lircd status
● lircd.service – Flexible IR remote input/output application support
Loaded: loaded (/lib/systemd/system/lircd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2017-09-12 18:28:25 UTC; 13min ago
Docs: man:lircd(8)
http://lirc.org/html/configure.html
Main PID: 391 (lircd)
CGroup: /system.slice/lircd.service
└─391 /usr/sbin/lircd –nodaemon

Sep 12 18:42:22 raspberrypi lircd[391]: lircd-0.9.4c[391]: Error: Cannot glob /sys/class/rc/rc0/input[0-9]*/event[0-9]*
Sep 12 18:42:22 raspberrypi lircd-0.9.4c[391]: Error: Cannot glob /sys/class/rc/rc0/input[0-9]*/event[0-9]*

pi@raspberrypi:~ $ ls /dev/lirc*
ls: cannot access ‘/dev/lirc*’: No such file or directory

pi@raspberrypi:~ $ mode2 -d /dev/lirc0 -H default
Using driver default on device /dev/lirc0
Cannot initiate device /dev/lirc0

/boot/config.txt 설정됨.
/etc/lirc/lirc_options.conf 설정 안됨.

pi@raspberrypi:~ $ dmesg | grep lirc
[ 10.021134] lirc_dev: IR Remote Control driver registered, major 243
[ 10.062988] lirc_rpi: module is from the staging directory, the quality is unknown, you have been warned.
[ 11.152768] lirc_rpi: auto-detected active low receiver on GPIO pin 18
[ 11.153629] lirc_rpi lirc_rpi: lirc_dev: driver lirc_rpi registered at minor = 0
[ 11.153645] lirc_rpi: driver registered!
[ 35.977066] input: lircd-uinput as /devices/virtual/input/input0

pi@raspberrypi:~ $ /etc/init.d/lircd status
● lircd.service – Flexible IR remote input/output application support
Loaded: loaded (/lib/systemd/system/lircd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2017-09-12 18:19:26 UTC; 4min 3s ago
Docs: man:lircd(8)
http://lirc.org/html/configure.html
Main PID: 389 (lircd)
CGroup: /system.slice/lircd.service
└─389 /usr/sbin/lircd –nodaemon

Sep 12 18:23:29 raspberrypi lircd[389]: lircd-0.9.4c[389]: Error: Cannot glob /sys/class/rc/rc0/input[0-9]*/event[0-9]*
Sep 12 18:23:29 raspberrypi lircd-0.9.4c[389]: Error: Cannot glob /sys/class/rc/rc0/input[0-9]*/event[0-9]*

pi@raspberrypi:~ $ ls /dev/lirc*
/dev/lirc0

pi@raspberrypi:~ $ mode2 -d /dev/lirc0 -H default
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
space ###
pulse ###
space ###
pulse ###

pi@raspberrypi:~ $ mode2
Using driver devinput on device auto
Cannot initiate device auto

(### : 임의의 수)

/boot/config.txt /etc/lirc/lirc_options.conf 설정됨

pi@raspberrypi:~ $ dmesg | grep lirc
[ 9.957341] lirc_dev: IR Remote Control driver registered, major 243
[ 9.979650] lirc_rpi: module is from the staging directory, the quality is unknown, you have been warned.
[ 11.065561] lirc_rpi: auto-detected active low receiver on GPIO pin 18
[ 11.066023] lirc_rpi lirc_rpi: lirc_dev: driver lirc_rpi registered at minor = 0
[ 11.066036] lirc_rpi: driver registered!
[ 31.846638] input: lircd-uinput as /devices/virtual/input/input0

pi@raspberrypi:~ $ /etc/init.d/lircd status
● lircd.service – Flexible IR remote input/output application support
Loaded: loaded (/lib/systemd/system/lircd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-09-13 09:27:43 UTC; 2min 1s ago
Docs: man:lircd(8)
http://lirc.org/html/configure.html
Main PID: 431 (lircd)
CGroup: /system.slice/lircd.service
└─431 /usr/sbin/lircd –nodaemon

Sep 13 09:27:44 raspberrypi lircd-0.9.4c[431]: Notice: accepted new client on /var/run/lirc/lircd
Sep 13 09:27:44 raspberrypi lircd-0.9.4c[431]: Info: Cannot configure the rc device for /dev/lirc0
Sep 13 09:27:44 raspberrypi lircd-0.9.4c[431]: Notice: accepted new client on /var/run/lirc/lircd
Sep 13 09:27:44 raspberrypi lircd-0.9.4c[431]: Notice: accepted new client on /var/run/lirc/lircd
Sep 13 09:28:59 raspberrypi lircd[431]: lircd-0.9.4c[431]: Notice: accepted new client on /var/run/lirc/lircd
Sep 13 09:28:59 raspberrypi lircd-0.9.4c[431]: Notice: accepted new client on /var/run/lirc/lircd

pi@raspberrypi:~ $ ls /dev/lirc*
/dev/lirc0

pi@raspberrypi:~ $ mode2 -d /dev/lirc0 -H default
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
space ###
pulse ###

pi@raspberrypi:~ $ mode2
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
space ###
pulse ###

 

상황별 Trubleshoot

mode2

/boot/config.txt 설정 안됨 또는
lircd 서비스 실행중,
lircd.socket으로 통신하는 프로그램 실행중(python, php, node.js 등등)

pi@raspberrypi:~ $ mode2 -d /dev/lirc0 -H default
Using driver default on device /dev/lirc0
Cannot initiate device /dev/lirc0

/etc/lirc/lirc_options.conf 설정 안됨

pi@raspberrypi:~ $ mode2
Using driver devinput on device auto
Cannot initiate device auto

pi@raspberrypi:~ $ mode2 -d /dev/lirc0
Using driver devinput on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
(code: 0x5501000059000001813b00005a000001)
Partial read 8 bytes on /dev/lirc0pi@raspberrypi:~ $

 

라즈베리파이 LIRC(적외선 송수신) 설정”의 9개의 생각

  1. 안녕하세요 IR 도움이 많이되네요
    옛날꺼 보고하다 안되서 여기까지 왔습니다.

    리모컨 값 찾아 내는건 어떻게 하는겁니까 ?
    irrecord -d /dev/lirc0 ~/lircd.conf
    옛날꺼는 저렇게 하는거 같은데…..

    좋아요

    1. 일단, 전체적인 상황을 알 수 없어서 기본적인 것으로 말씀드리면,
      1. 리모콘에서 정상적인 신호가 나오는지 확인한다->스마트폰의 카메라로 리모콘의 송신부를 보면서 버튼을 눌러봅니다. 센서에 아무리 IR 필터가 적용되어있더라도 바로 앞의 IR 불빛정도는 보입니다.
      2. 라즈베리파이에 연결 된 수신부가 제대로 작동하는지 확인합니다. 정확하게 확인하는법은 OUT 단자를 오실로스코프로 찍어보는 것이나 보통은 없을 것이기에 멀티미터로 전압이 “변동”하는지, 또는 LED와 저항을 연결해서 LED가 깜빡 또는 불이 들어오는지 확인합니다. 이때 어떠한 변화도 없으면 수신부 센서에 무언가 잘 못 된 것입니다.
      2.1 보통 리모컨 신호의 Carrier 주파수가 보통은 38kHz 이고 위아래로 2kHz 정도는 허용되나 50kHz 같은 멀리 떨어진 주파수의 IR신호는 못받는 경우가 있습니다. 이 때는 사용하는 리모콘과 적외선 센서를 인터넷에서 검색해서 Carrier 주파수가 비슷한지 확인합니다.
      2.2 다른 리모컨을 가져와서 확인합니다.
      2.3 배선 연결을 잘못한 것인지 확인합니다. 판매처에서 제공하는 데이터시트를 참조하여 거기에 나와있는대로 연결해야 제대로 된 신호를 수신할 수 있습니다.
      3. 수신부에서 신호가 정상적으로 나오면 라즈베리파이의 모델을 확인하고 본문 2.1절을 참조하여 수신부의 OUT 단자를 연결한 핀이 적절한 핀인지, 그리고 핀 번호를 /boot/config.txt에 제대로 입력했는지 확인합니다. 기판 또는 설명서에 표시된 번호랑 내부 번호랑 다를겁니다.

      좋아요

  2. 답변 감사합니다!!! 하나 더 여쭤 볼게 있어서 글을 남깁니다. 리모콘 정보를 받았는데 이 파일을 어떻게 해야 codesys로 활용을 할 수 있을까요?? 이거에 대한 정보가 없어서 여쭤봅니다..ㅠㅠ

    좋아요

  3. 작성해주신 가이드 감사합니다.

    그런데 여러번 따라했음에도 불구하고
    /boot/config.txt 설정이 안되는 trubleshooting 상태입니다.ㅜㅜ
    분명 바꿔서 설정하고 재부팅했는데
    dmesg | grep lirc 를 입력하면 계속
    [ 6.234575] input: lircd-uinput as /devices/virtual/input/input0
    출력되네요 ㅠㅠ

    혹시 도와주실수 있을까요?? 감사합니다.

    좋아요

댓글 남기기