树莓派安装红外遥控器

By | 2018-11-26

Raspberry 1代 B版一台 [512MB] + Toshiba红外遥控器

系统: Raspbian-jessie-lite
一、安装 Lirc
1)安裝Lirc

apt-get install lirc

sudo modprobe lirc_rpi

如无法加载出现以下提示:

[email protected]:/dev# modprobe lirc_rpi
modprobe: ERROR: could not insert ‘lirc_rpi’: No such device

2)编辑 /etc/modules ,添加下面的内容

lirc_dev

lirc_rpi gpio_in_pin=18 gpio_out_pin=17

3)修改 /boot/config.txt , 加入以下一行代码:

dtoverlay=lirc-rpi

再重新加载 lirc_rpi , 然后 reboot 即可正常加载了!

测试红外接收是否正常:

sudo mode2 -d /dev/lirc0

 

如果按遥控器上的键,屏幕上能显示出一串pluse和space值的话,多半就是正常了。

配置下/etc/lirc/hardware.conf:

LIRCD_ARGS=”–uinput”

DRIVER=”default”

DEVICE=”/dev/lirc0″

让lirc学习一下你遥控器上的按键,在我的例子中,请至少学习5个按键,分别做为上(up)、下(down)、左(left)、右(right)、选择(sel):

sudo /etc/init.d/lirc stop
#学习按键
irrecord -n -d /dev/lirc0 ~/lircd.conf
#把学习后生成的配置文件作为lircd的配置文件
sudo mv ~/lircd.conf /etc/lirc/lircd.conf
sudo /etc/init.d./lirc start

配置完后,可以用irw命令测试遥控器是否工作正常。

配置~/.lircrc.conf文件,把按键与需要触发的行为进行关联: [以下是针对mplayer的lirc按键定义]

Map buttons

create a file called ~/.lircrc (this file configures what every key does),
here is a sample ~/.lircrc file to control mplayer, beep-media-player and volume:

#Mplayer buttons
begin
button = VOL+
prog = mplayer
config = volume 1
repeat = 1
end
begin
button = VOL-
prog = mplayer
config = volume -1
repeat = 1
end
begin
button = ||
prog = mplayer
config = pause
end
begin
button = Prog+
prog = mplayer
config = pt_step 1
end
begin
button = Prog-
prog = mplayer
config = pt_step -1
end
begin
button = MENU
prog = mplayer
config = vo_fullscreen
end
begin
button = 1
prog = mplayer
config = seek -10
end
begin
button = 4
prog = mplayer
config = seek -60
end
begin
button = 3
prog = mplayer
config = seek 10
end
begin
button = 6
prog = mplayer
config = seek 60
end
begin
button = 7
prog = mplayer
config = audio_delay +0.1
end
begin
button = 9
prog = mplayer
config = audio_delay -0.1
end

#Beep-Media-Player Control
begin
button = >
prog = irexec
config = beep-media-player –play-pause
repeat = 0
end

begin
button = >>
prog = irexec
config = beep-media-player –fwd
end

begin
button = <<
prog = irexec
config = beep-media-player –rew
end

begin
button = #
prog = irexec
config = beep-media-player –stop
end

#Volume
begin
button = Start+
prog = irexec
config = aumix -v+5
repeat = 0
end

begin
button = Start-
prog = irexec
config = aumix -v-5
repeat = 0
end
—————————————————————————

按键定义:[以下是定义在命令行下通过lirc执行相应的指令]

sudo vi /etc/lirc/lircrc

#/etc/lirc/lircrc 内容
begin
    prog = irexec  #这个可随意
    button = KEY_1 #按钮的名称
    config = sudo reboot #执行的命令
end
begin
    prog = irexec
    button = KEY_2
    config = echo "hello lirc one!"
end

http://ukonline2000.com/?p=296

打造增强型Raspberry Pi-红外遥控篇

教程:
http://www.shumeipai.net/forum.php?mod=viewthread&action=printable&tid=12265&_dsign=44ba63f0

WIFI设置:
配置文件路径: /etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid=”test-wifi”
psk=”37214832″
scan_ssid=1
}

發佈回覆