根据网上查找的VS1838B红外接收器的引脚定义
OUT | GND | VCC |
信号输出 | 接地 | 电源输入 |
将红外接收器连接到树莓派对应引脚,此次OUT对应的IO引脚为 BCM2
官方文档:http://lirc.org/html/configuration-guide.html
安装LIRC服务
sudo apt-get install lirc
注意,在某些教程中,可能会让你修改 /etc/lirc/hardware.conf 等文件,但根据最新版本的文档,无需编辑这个文件
需要进行以下操作
sudo cp /etc/lirc/lirc_options.conf.dist /etc/lirc/lirc_options.conf
sudo cp /etc/lirc/lircd.conf.dist /etc/lirc/lircd.conf
sudo cp /etc/lirc/lircd.conf.d/devinput.lircd.conf.dist /etc/lirc/lircd.conf.d/devinput.lircd.conf
vi /etc/lirc/lirc_options.conf
将以下内容
driver = devinput
device = auto
替换为
driver = default
device = /dev/lirc0
sudo vi /boot/config.txt
#下面的gpio_pin=值为树莓派与接收器OUT端连接的gpio口
dtoverlay=gpio-ir,gpio_pin=2
#下面的配置是用于发送使用,当前只使用接收,直接注释
#dtoverlay=gpio-ir-tx,gpio_pin=17
sudo systemctl stop lircd
sudo systemctl start lircd
sudo systemctl status lircd
sudo shutdown -r 0
sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0
使用发射器对准接收器随便按几个按钮,会看见终端输出类似以下内容
space xxxxx
pulse xxx
space xxxxx
pulse xxx
space xxxxx
证明接收器工作正常
有两种方式可以进行配置
irrecord录制指令如下
irrecord -list-namespace
irrecord -d /dev/lirc0 /etc/lirc/lircd.conf.d/test.lircd.conf
根据stack overflow上的讨论,和本人实际测试,因为遥控器特殊及新版本lirc录制算法的原因,实际录制出来的文件无法正常工作
推荐使用以下方式获取配置文件
sudo vi /etc/lirc/lircd.conf.d/carmp3.lircd.conf
# Please make this file available to others
# by sending it to
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Sat Mar 7 11:28:13 2015
# running on a Raspberry Pi 2 with Raspbian GNU/Linux 7 (Kernel 3.18.7-v7+)
# and then edited
#
# contributed by Martin Kilgus
#
# brand: No-Name YK-001 as included in "GPIO Electronics Starter Kit" sourced from eBay
# model no. of remote control: YK-001
# devices being controlled by this remote: universal
#
#
# Remote layout:
# (it appears that the same remote is also available with
# different labels printed on the buttons)
#
# +----------------------------------+
# | |
# | Power Mode Mute |
# | |
# | Previous Next Play/Pause |
# | |
# | (Vol)- Vol(+) EQ |
# | |
# | 0 100+ Back |
# | |
# | 1 2 3 |
# | |
# | 4 5 6 |
# | |
# | 7 8 9 |
# | |
# +----------------------------------+
begin remote
name car-mp3
bits 16
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100
header 9007 4448
one 581 1658
zero 581 542
ptrail 578
repeat 9005 2231
pre_data_bits 16
pre_data 0xFF
gap 107592
toggle_bit_mask 0x0
begin codes
KEY_CHANNELDOWN 0xA25D # Symbol "Power", color of button: red
KEY_CHANNEL 0x629D # Text "Mode", color of button: black
KEY_CHANNELUP 0xE21D # Symbol "Mute", color of button: black
KEY_PREVIOUS 0x22DD # Symbol "|<<" / Text "Prev", color of button: red
KEY_NEXT 0x02FD # Symbol ">>|" / Text "Next", color of button: red
KEY_PLAYPAUSE 0xC23D # Symbol ">||" / Text "Play/Pause", color of button: red
KEY_VOLUMEDOWN 0xE01F # Symbol "-" / Text "Vol-", color of button: black
KEY_VOLUMEUP 0xA857 # Symbol "+" / Text "Vol+", color of button: black
KEY_EQUAL 0x906F # Text "EQ", color of button: black
KEY_0 0x6897 # Text "0", color of button: white
KEY_100+ 0x9867 # Text "100+", color of button: white
KEY_200+ 0xB04F # Symbol "Return", color of button: black
KEY_1 0x30CF # Text "1", color of button: white
KEY_2 0x18E7 # Text "2", color of button: white
KEY_3 0x7A85 # Text "3", color of button: white
KEY_4 0x10EF # Text "4", color of button: white
KEY_5 0x38C7 # Text "5", color of button: white
KEY_6 0x5AA5 # Text "6", color of button: white
KEY_7 0x42BD # Text "7", color of button: white
KEY_8 0x4AB5 # Text "8", color of button: white
KEY_9 0x52AD # Text "9", color of button: white
end codes
end remote
sudo systemctl restart lircd