라즈베리파이 적외선 리모컨 - lajeubelipai jeog-oeseon limokeon

하루종일 고생했는데 적외선 led가 고장난 놈이었다...

먼저 쉬운방법이 있고 조금 복잡한 방법이 있다.
쉬운 방법은 ircodec모듈을 사용하는것이다.

pip install pigpio
pip install ircodec

sudo pigpiod

이제 파이썬 코드에서

# Create a CommandSet for your remote control
# GPIO for the IR receiver: 23
# GPIO for the IR transmitter: 22
from ircodec.command import CommandSet
controller = CommandSet('name',emitter_gpio=22, receiver_gpio=23, description='TV remote')

# Add the volume up key
controller.add('volume_up')
# Connected to pigpio
# Detecting IR command...
# Received.

# Send the volume up command
controller.emit('volume_up')

# Remove the volume up command
controller.remove('volume_up')

# Examine the contents of the CommandSet
controller
# CommandSet(emitter=22, receiver=23, description="TV remote")
# {}

# Save to JSON
controller.save_as('tv.json')

# Load from JSON
new_controller = CommandSet.load('another_tv.json')

그냥 나온대로 쓰면 된다.

복잡한 방법은
1. https://blog.aliencube.org/ko/2020/08/12/turning-raspberry-pi-into-remote-controller/
2. https://blog.nakwonelec.com/2017/09/13/%EB%9D%BC%EC%A6%88%EB%B2%A0%EB%A6%AC%ED%8C%8C%EC%9D%B4-lirc%EC%A0%81%EC%99%B8%EC%84%A0-%EC%86%A1%EC%88%98%EC%8B%A0-%EC%84%A4%EC%A0%95/

이 두 글을 참고했다.

irsend를 파이썬에서 제어하기 위해 python-irsend모듈을 다운받는다

라즈베리파이 적외선 리모컨 - lajeubelipai jeog-oeseon limokeon

이렇게 사용하면 된다

센서를 쓸땐 고장났는지를 꼭 확인하자...

하루종일 고생했는데 적외선 led가 고장난 놈이었다...

먼저 쉬운방법이 있고 조금 복잡한 방법이 있다.
쉬운 방법은 ircodec모듈을 사용하는것이다.

pip install pigpio
pip install ircodec

sudo pigpiod

이제 파이썬 코드에서

# Create a CommandSet for your remote control
# GPIO for the IR receiver: 23
# GPIO for the IR transmitter: 22
from ircodec.command import CommandSet
controller = CommandSet('name',emitter_gpio=22, receiver_gpio=23, description='TV remote')

# Add the volume up key
controller.add('volume_up')
# Connected to pigpio
# Detecting IR command...
# Received.

# Send the volume up command
controller.emit('volume_up')

# Remove the volume up command
controller.remove('volume_up')

# Examine the contents of the CommandSet
controller
# CommandSet(emitter=22, receiver=23, description="TV remote")
# {}

# Save to JSON
controller.save_as('tv.json')

# Load from JSON
new_controller = CommandSet.load('another_tv.json')

그냥 나온대로 쓰면 된다.

복잡한 방법은
1. https://blog.aliencube.org/ko/2020/08/12/turning-raspberry-pi-into-remote-controller/
2. https://blog.nakwonelec.com/2017/09/13/%EB%9D%BC%EC%A6%88%EB%B2%A0%EB%A6%AC%ED%8C%8C%EC%9D%B4-lirc%EC%A0%81%EC%99%B8%EC%84%A0-%EC%86%A1%EC%88%98%EC%8B%A0-%EC%84%A4%EC%A0%95/

이 두 글을 참고했다.

irsend를 파이썬에서 제어하기 위해 python-irsend모듈을 다운받는다

라즈베리파이 적외선 리모컨 - lajeubelipai jeog-oeseon limokeon

이렇게 사용하면 된다

센서를 쓸땐 고장났는지를 꼭 확인하자...

안녕하세요.

오늘은 라즈베리파이로 리모컨 신호를 받아보겠습니다.

제품구매↓↓

준비물

회로

lirc라고 하는 라이브러리를 사용하면 편리하게 IR센서를 사용할 수 있습니다.

다운로드

sudo apt-get install lirc

ir센서를 사용하기 위해서 설정을 해주겠습니다.

1.

sudo nano /boot/config.txt

맨 마지막에

dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22

를 입력하고 저장해줍니다.

2.

sudo nano /etc/modules

맨 마지막에

Lirc_dev

Lirc_rpi gpio_in_pin=23 gpio_out_pin=22

를 입력하고 저장해줍니다.

 저장 Ctrl+o

sudo nano /etc/lirc/lirc_options.conf

표시된 부분을 사진처럼 바꿔줍니다.

sudo reboot

서비스를 실행해보겠습니다.

sudo /etc/init.d/lircd start

sudo /etc/init.d/lircd status

위 사진 처럼 나오면 설정이 잘 된 것입니다.

sudo /etc/init.d/lircd stop

을 해줘야 다음 명령어가 동작합니다.

mode2 –d /dev/lirc0

아래 사진처럼 spacepulse가 반복해서 나오면 제대로 동작하고 있다는 뜻입니다.

이제 리모컨의 신호를 저장해 보겠습니다.

저장하기 전에 lirc라이브러리에서 사용할 수 있는 코드 이름들을 먼저 확인하도록 하겠습니다.

Irrecord --list-namespace

이제 리모컨 신호를 저장하겠습니다. 

sudo /etc/init.d/lircd stop

sudo irrecord –d /dev/lirc0

Press RETURN now to start recording. 다음에 리모컨의 아무 버튼이나 눌러줍니다.

버튼을 누르고 있으면 점이 차오르는게 보일 겁니다. 다 찰 때까지 꾹 눌러줍니다.

그러면 다음 버튼의 이름을 입력하라고 합니다,

리모컨의 버튼을 모두 입력할때 까지 이과정을 반복해 줍니다.

다 입력했으면 enter를 치면 종료합니다.

리모컨의 정보가 담긴 파일은 위 사진 처럼  /hone/pi 에 저장됩니다. 

이 파일을 /etc/lirc/lircd.conf.d 폴더에 옮겨야 합니다.

sudo cp –rf ~/(파일명).lircd.conf /etc/lirc/lircd.conf.d/

irw

를 입력하고 리모컨을 누르면 입력된 이름이 나옵니다.

신호 내보내기

irsend SEND_ONCE (파일일명) 내보낼 코드

ex) irsend SEND_ONCE remote KEY_left

이렇게 입력하면 라즈베리파이에서 신호를 보내는 것도 가능합니다.

아래 링크는 기존에 있는 리모컨들의 conf 파일입니다.

https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/

IR신호를 이용해 다양한 예제에 활용해 보세요^^

감사합니다.