树莓派3B+搭配Buster版本系统进行红外遥控开发

一、配件清单

  • 树莓派:3B+
  • 系统版本:Buster
  • 红外接收器:VS1838B

树莓派3B+搭配Buster版本系统进行红外遥控开发_第1张图片

  • 红外遥控器:未知型号(标有ar mp3字样)

树莓派3B+搭配Buster版本系统进行红外遥控开发_第2张图片 

  • 杜邦线若干

二、 线路组合准备

根据网上查找的VS1838B红外接收器的引脚定义

OUT GND VCC
信号输出 接地 电源输入

将红外接收器连接到树莓派对应引脚,此次OUT对应的IO引脚为 BCM2

三、安装服务,进行配置

官方文档:http://lirc.org/html/configuration-guide.html

安装LIRC服务

sudo apt-get install lirc

注意,在某些教程中,可能会让你修改 /etc/lirc/hardware.conf 等文件,但根据最新版本的文档,无需编辑这个文件

需要进行以下操作

  • 将lirc的配置dist文件转为有效配置文件
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
  •  修改lirc_options.conf文件
vi /etc/lirc/lirc_options.conf

将以下内容

driver          = devinput
device          = auto

替换为 

driver          = default
device          = /dev/lirc0
  • 编辑/boot/config.txt
sudo vi /boot/config.txt
  •  找到 dtoverlay 配置项,修改对应的GPIO接口(使用vim编辑器时,可按 / 键后输入dtoverlay直接查找)
#下面的gpio_pin=值为树莓派与接收器OUT端连接的gpio口
dtoverlay=gpio-ir,gpio_pin=2
#下面的配置是用于发送使用,当前只使用接收,直接注释
#dtoverlay=gpio-ir-tx,gpio_pin=17
  • 确认lirc服务工作正常
sudo systemctl stop lircd
sudo systemctl start lircd
sudo systemctl status lircd
  • 重启树莓派
sudo shutdown -r 0

 三、测试接收服务

  • 首先关闭lirc服务
sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0

 使用发射器对准接收器随便按几个按钮,会看见终端输出类似以下内容

space xxxxx
pulse xxx
space xxxxx
pulse xxx
space xxxxx

证明接收器工作正常

四、配置接收器编解码文件

有两种方式可以进行配置

  1. 使用 irrecord 指令 录制
  2.  使用现成配置文件

irrecord指令录制

irrecord录制指令如下

  • 查看命名空间
irrecord -list-namespace
  • 进行录制
irrecord -d /dev/lirc0 /etc/lirc/lircd.conf.d/test.lircd.conf

直接获取配置文件

根据stack overflow上的讨论,和本人实际测试,因为遥控器特殊及新版本lirc录制算法的原因,实际录制出来的文件无法正常工作

推荐使用以下方式获取配置文件

  1. 使用 irdb-get 工具
  2. 官方配置文件库下载 http://lirc.sourceforge.net/remotes/
  3. 克隆git仓库获取 https://git.code.sf.net/p/lirc-remotes/code

 

  • 对应本文所示的控制器,经测试有效的配置文件如下
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
  • 重启lirc服务,即可正常使用
sudo systemctl restart lircd

 

你可能感兴趣的:(树莓派)