从左到右以此是
接信号(我接的是gpio.29 bcm21(可通过gpio.readall查看))
接电源(我的5v 3v都可 虽然建议3v)
接地
sudo apt-get install lirc
用sudo打开
sudo vim /boot/config.txt
修改或在最后加上指令,将其设置为红外接受和发射口.
dtoverlay=gpio-ir,gpio_pin=21 #bcm号 红外接受
dtoverlay=gpio-ir-tx,gpio_pin=22 #bcm号 红外发射
但我没有发射模块,第二个代码没有上
driver = default
device = /dev/lirc1
好像1是输入,0是输出,不知道............
mode2 -m -d /dev/lirc1
点击遥控器,有输出一串数字就行.
如果没有,试试这个(重启服务)
sudo service lircd restart
还不行就重新安装lirc.
irrecord -f -d /dev/lirc1
会打开一个窗口,这就是官方的录入系统,按照提示完成录入即可
(不告诉你们具体步骤是想让你们练练英语(doge))
(这是快速录入模式,主要是因为官方的bug多,本教程采取手动输入红外信息方式完成)
然后会在/etc/lirc生成一个lircd.conf
这个就是现在可以识别的按键列表,向这样
# Please take the time to finish this file as described in
# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
# and make it available to others by sending it to
#
#
# This config file was automatically generated
# using lirc-0.10.1(default) on Fri May 20 18:50:03 2022
# Command line used: -f -d /dev/lirc1
# Kernel version (uname -r): 5.15.32-v8+
#
# Remote name (as of config file): pi
# Brand of remote device, the thing you hold in your hand:
# Remote device model nr:
# Remote device info url:
# Does remote device has a bundled capture device e. g., a
# usb dongle? :
# For bundled USB devices: usb vendor id, product id
# and device string (use dmesg or lsusb):
# Type of device controlled
# (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :
# Device(s) controlled by this remote:
begin remote
name pi
flags RAW_CODES|CONST_LENGTH
eps 30
aeps 100
gap 108265
begin raw_codes
name key_close
9062 4480 597 532 605 530
603 531 605 530 603 531
606 529 604 530 600 534
604 1643 596 1645 601 1639
596 1668 575 1665 548 1695
576 1661 577 1670 574 1667
580 528 602 1667 549 559
602 531 603 531 602 1648
597 533 602 532 603 1647
600 529 604 1668 577 1645
598 1670 574 533 602 1669
577
end raw_codes
end remote
命令行输入
mode2 -m -d /dev/lirc1
然后点击遥控器
会出现一段代码
Using driver default on device /dev/lirc1
Trying device: /dev/lirc1
Using device: /dev/lirc1
16777215
8976 4585 513 620 538 596
515 620 514 619 514 623
541 591 515 645 486 621
516 1730 514 1729 543 1703
540 1700 522 1736 558 1704
487 1753 490 1737 508 617
542 620 516 620 490 619
540 592 558 555 536 1745
529 589 516 1764 500 1732
492 1727 538 1707 543 1702
539 1704 512 620 514 1729
514 131464-pulse
复制下2个数字之间代码(第一个和最后一个数字)
8976 4585 513 620 538 596
515 620 514 619 514 623
541 591 515 645 486 621
516 1730 514 1729 543 1703
540 1700 522 1736 558 1704
487 1753 490 1737 508 617
542 620 516 620 490 619
540 592 558 555 536 1745
529 589 516 1764 500 1732
492 1727 538 1707 543 1702
539 1704 512 620 514 1729
514
然后打开lircd.conf
修改
# Please take the time to finish this file as described in
# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
# and make it available to others by sending it to
#
#
# This config file was automatically generated
# using lirc-0.10.1(default) on Fri May 20 18:50:03 2022
# Command line used: -f -d /dev/lirc1
# Kernel version (uname -r): 5.15.32-v8+
#
# Remote name (as of config file): pi
# Brand of remote device, the thing you hold in your hand:
# Remote device model nr:
# Remote device info url:
# Does remote device has a bundled capture device e. g., a
# usb dongle? :
# For bundled USB devices: usb vendor id, product id
# and device string (use dmesg or lsusb):
# Type of device controlled
# (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :
# Device(s) controlled by this remote:
begin remote
name pi
flags RAW_CODES|CONST_LENGTH
eps 30
aeps 100
gap 108265
begin raw_codes
name key_close
9062 4480 597 532 605 530
603 531 605 530 603 531
606 529 604 530 600 534
604 1643 596 1645 601 1639
596 1668 575 1665 548 1695
576 1661 577 1670 574 1667
580 528 602 1667 549 559
602 531 603 531 602 1648
597 533 602 532 603 1647
600 529 604 1668 577 1645
598 1670 574 533 602 1669
577
name key_1
8976 4585 513 620 538 596
515 620 514 619 514 623
541 591 515 645 486 621
516 1730 514 1729 543 1703
540 1700 522 1736 558 1704
487 1753 490 1737 508 617
542 620 516 620 490 619
540 592 558 555 536 1745
529 589 516 1764 500 1732
492 1727 538 1707 543 1702
539 1704 512 620 514 1729
514
end raw_codes
end remote
有的人说这个代码要空格严格右对齐,反正我的不用,如果你的跑不了,可以试试.
这样按键就录入完毕了.
就是在end和begin间加入代码 按键名称和录入红外信息
sudo service lircd restart # 重启服务
irw
点击按键,看看有没有输出
xxxxxxxxx 0xXX key_1
有就行.
新建一个文件在/etc/lirc 叫lircrc
(或者看看当前目录下有没有一个文件内容是这样的
begin
prog = irexec
button = KEY_1
config = echo "KEY_1"
end
begin
prog = irexec
button = KEY_2
config = echo "KEY_2"
end
然后把它改名叫lircrc。。。。。。。。。。。。。
这个就是配置按键的文件,使用方法为打开命令框,然后输入irexe,点击对应按键,就可以识别到了。并执行config内容(可以sh echo 啥的,自己探索吧)
有人说要在系统命名空间内部的名称才可以用,反正我这没有,名字随便起
或者链接.py文件,打开python文件,运行,然后点击按键,使用
写个python文件,命名为star.py (为啥不是start??-----懒)
import lirc
import superb
def pasreset(data): #解析按键
if data == 'echo "KEY_1"':
print("1 按下") #遥控器按下1:
superb.star()
elif data == 'echo "KEY_2"':
print("2 按下") #遥控器按下2:
elif data == 'echo "KEY_3"':
print("3 按下") #遥控器按下3:
with lirc.LircdConnection("star.py",) as conn:
print("ok1")
while True:
print("ok2")
string = conn.readline()#读取输入
print("ok3")
pasreset(string)
然后修改lircrc
begin
prog = satr.py
button = KEY_1
config = echo "KEY_1"
end
begin
prog = satr.py
button = KEY_2
config = echo "KEY_2"
end
这样,当运行py时,点击按键,就会返回config值,然后运行模块.