IR센서 보고서 #49
Seungjun07
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
라즈베리 파이로 TV를 제어하기 위해서는 리모컨의 신호가 필요하다.
리모컨 신호는 IR 수신기를 통해 받을 수 있고 받은 신호를 저장하여 IR 송신기로 내보내면 TV를 제어할 수 있게 된다.
리모컨 신호를 받기 위해서는 라즈베리 파이에 LIRC 패키지를 설치하여야 한다.
LIRC(Linux Infrared Remote Control)란 리모컨의 적외선 신호를 디코딩하고 전송할 수 있는 패키지이다.
LIRC 설치
라즈베리 파이의 OS의 패키지들을 업데이트하고 LIRC 모듈을 설치한다.
부트 로더 설정
antl@raspberrypi:~ $ sudo nano /boot/config.txt
config.txt 파일을 열어서 dtoverlay의 수신기 핀 번호를 18로, 송신기 핀 번호를 17로 설정한다.
부트 로더를 설정하여 라즈베리 파이를 시작할 때 LIRC 모듈도 구동하게 한다.
LIRC 모듈 하드웨어 설정
antl@raspberrypi:~ $ sudo nano /etc/lirc/hardware.conf
/etc/lirc폴더에 hardware.conf 파일을 열어 위의 내용을 입력한 후 저장한다.
LIRC 모듈 옵션 설정
antl@raspberrypi:~ $ sudo nano /etc/lirc/lirc_options.conf
lirc_options.conf 파일을 열어 driver와 device의 값을 변경한 후 저장한다.
antl@raspberrypi:~ $ sudo reboot
부트 로더 설정 및 변경한 값들을 인식 시키기 위해 재부팅을 해준다.
리모컨 신호 등록하기 - IR 수신기
LIRC 모듈 동작 확인
antl@raspberrypi:~ $ sudo /etc/init.d/lircd status
재부팅을 한 후 LIRC 모듈이 동작을 하고 있는지 확인한다. Active: active (running)과 끝 부분에 IR remote input/output이 출력되면 동작을 하고 있다는 뜻이다.
리모컨 신호 확인
리모컨 신호를 직접 등록하기 위해서는 IR 수신기가 신호를 제대로 받는지 먼저 확인을 해주어야 한다.
antl@raspberrypi:~ $ sudo /etc/init.d/lircd stop
antl@raspberrypi:~ $ sudo mode2 -m -d /dev/lirc0
단, 리모컨 신호를 받아서 데이터를 만들어야 하므로 아까 설정했던 부트 로더 파일에서 송신기 부분을 주석 처리 한 후, 재부팅하여 진행해야 한다.
재부팅이 끝났으면, 첫번째 명령어를 사용하여 LIRC 모듈을 중지시키고, 다음 명령어를 통해 IR 수신기에 리모컨을 대고 버튼을 눌러 신호를 잘 받는지 확인한다.
리모컨 신호 저장
IR 수신기를 통해 받은 리모컨 신호를 (remote_name).lircd.conf 파일에 저장한다. 여기서 (remote_name)은 직접 설정할 수 있다.
리모컨 신호 코딩
(remote_name).lircd.conf 파일을 열면 신호가 입력된 것을 확인할 수 있다.
여기서 필요한 신호는 중간에 있는 숫자 부분이다. 앞에 긴 숫자 부분과 마지막의 큰 숫자 부분은 삭제하고 명령어와 정보를 입력해준다.
여기서 이름으로 지정한 KEY_POWER와 같이 버튼마다 지정된 이름이 있으므로 알아본 후 사용해야 한다.
파일 복사
수정한 파일을 LIRC 디렉토리로 복사한다.
LIRC 디렉토리에 파일이 있는지 확인한다.
antl@raspberrypi:~ $ sudo nano /boot/config.txt
부트 로더 파일을 연 후, 주석 처리 했던 송신기 부분을 다시 해제하고 저장한 후 재부팅한다.
antl@raspberrypi:~ $ sudo /etc/init.d/lircd status
LIRC 모듈이 정상 동작하는지 확인한다.
신호 전송하기 - IR 송신기
(remote_name)에 등록되어 있는 신호들의 목록을 확인한다.
위의 명령어를 보냈을 때 TV가 동작하면 정상적으로 등록이 된 것이다.
Beta Was this translation helpful? Give feedback.
All reactions