树莓派4b--红外遥控模块
1.接线(因人而异)
从左到右以此是
接信号(我接的是gpio.29 bcm21(可通过gpio.readall查看))
接电源(我的5v 3v都可 虽然建议3v)
接地
2.安装必要模块
sudo apt-get install lirc
3.修改配置文件
1 进入/boot/config.txt
用sudo打开
sudo vim /boot/config.txt
修改或在最后加上指令,将其设置为红外接受和发射口.
dtoverlay=gpio-ir,gpio_pin=21 #bcm号 红外接受
dtoverlay=gpio-ir-tx,gpio_pin=22 #bcm号 红外发射
但我没有发射模块,第二个代码没有上
2 进入/etc/lirc/lirc_options.conf
driver = default
device = /dev/lirc1
好像1是输入,0是输出,不知道............
4.测试
mode2 -m -d /dev/lirc1
点击遥控器,有输出一串数字就行.
如果没有,试试这个(重启服务)
sudo service lircd restart
还不行就重新安装lirc.
5.录入按键
1.获得源文件:
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
# <lirc@bartelmus.de>
#
# 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 remotename piflags RAW_CODES|CONST_LENGTHeps 30aeps 100gap 108265begin raw_codesname key_close9062 4480 597 532 605 530603 531 605 530 603 531606 529 604 530 600 534604 1643 596 1645 601 1639596 1668 575 1665 548 1695576 1661 577 1670 574 1667580 528 602 1667 549 559602 531 603 531 602 1648597 533 602 532 603 1647600 529 604 1668 577 1645598 1670 574 533 602 1669577end raw_codesend remote
2.获取详细按键信息
命令行输入
mode2 -m -d /dev/lirc1
然后点击遥控器
会出现一段代码
Using driver default on device /dev/lirc1
Trying device: /dev/lirc1
Using device: /dev/lirc1167772158976 4585 513 620 538 596515 620 514 619 514 623541 591 515 645 486 621516 1730 514 1729 543 1703540 1700 522 1736 558 1704487 1753 490 1737 508 617542 620 516 620 490 619540 592 558 555 536 1745529 589 516 1764 500 1732492 1727 538 1707 543 1702539 1704 512 620 514 1729514 131464-pulse
复制下2个数字之间代码(第一个和最后一个数字)
8976 4585 513 620 538 596515 620 514 619 514 623541 591 515 645 486 621516 1730 514 1729 543 1703540 1700 522 1736 558 1704487 1753 490 1737 508 617542 620 516 620 490 619540 592 558 555 536 1745529 589 516 1764 500 1732492 1727 538 1707 543 1702539 1704 512 620 514 1729514
然后打开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
# <lirc@bartelmus.de>
#
# 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 remotename piflags RAW_CODES|CONST_LENGTHeps 30aeps 100gap 108265begin raw_codesname key_close9062 4480 597 532 605 530603 531 605 530 603 531606 529 604 530 600 534604 1643 596 1645 601 1639596 1668 575 1665 548 1695576 1661 577 1670 574 1667580 528 602 1667 549 559602 531 603 531 602 1648597 533 602 532 603 1647600 529 604 1668 577 1645598 1670 574 533 602 1669577name key_18976 4585 513 620 538 596515 620 514 619 514 623541 591 515 645 486 621516 1730 514 1729 543 1703540 1700 522 1736 558 1704487 1753 490 1737 508 617542 620 516 620 490 619540 592 558 555 536 1745529 589 516 1764 500 1732492 1727 538 1707 543 1702539 1704 512 620 514 1729514end raw_codesend remote
有的人说这个代码要空格严格右对齐,反正我的不用,如果你的跑不了,可以试试.
这样按键就录入完毕了.
就是在end和begin间加入代码 按键名称和录入红外信息
3.测试
sudo service lircd restart # 重启服务
irw
点击按键,看看有没有输出
xxxxxxxxx 0xXX key_1
有就行.
6.设置按键
新建一个文件在/etc/lirc 叫lircrc
(或者看看当前目录下有没有一个文件内容是这样的
beginprog = irexecbutton = KEY_1config = echo "KEY_1"
endbeginprog = irexecbutton = KEY_2config = 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
beginprog = satr.pybutton = KEY_1config = echo "KEY_1"
endbeginprog = satr.pybutton = KEY_2config = echo "KEY_2"
end
这样,当运行py时,点击按键,就会返回config值,然后运行模块.
树莓派4b--红外遥控模块相关推荐
- python连接传感器_树莓派4B之光敏传感器模块(python3)
背景 本人最因工作原因接触到各种电路板,传感器,而自己又是一个小白,随意在其他朋友的推荐下决定从树莓派开始玩传感器:本例子为树莓派控制红外避障传感器 材料 1.树莓派4b 2.火焰传感器模块 3.导线 ...
- 电视盒子刷linux树莓派,用树莓派4B打造纯ATV 10代替电视盒子
家里的电视买的比较早,"创*"什么的牌子,开机有广告.而且用了几年了,速度比较卡.无法接受的是不让装第三方软件,下定决心要搞一个性能比较猛的盒子了.但是看了一圈,普遍都不再预算范围 ...
- 树莓派4B之火焰传感器模块(python3)
背景 本人最因工作原因接触到各种电路板,传感器,而自己又是一个小白,随意在其他朋友的推荐下决定从树莓派开始玩传感器:本例子为树莓派控制红外避障传感器 材料 1.树莓派4b 2.火焰传感器模块 3.导线 ...
- 树莓派4B之超声波传感器模块(python3)
背景 本人最因工作原因接触到各种电路板,传感器,而自己又是一个小白,随意在其他朋友的推荐下决定从树莓派开始玩传感器:本例子为树莓派控制红外避障传感器 材料 1.树莓派4b 2.火焰传感器模块 3.导线 ...
- 树莓派4B之声音传感器模块(python3)
背景 本人最因工作原因接触到各种电路板,传感器,而自己又是一个小白,随意在其他朋友的推荐下决定从树莓派开始玩传感器:本例子为树莓派控制红外避障传感器 材料 1.树莓派4b 2.火焰传感器模块 3.导线 ...
- 开发者方案 · 久坐提醒 / 喝水提醒小助手·树莓派4B/咕咕机G2/涂鸦 Link SDK
本文方案来自CSDN博主「机灵鹤」 方案详情可查看原文:https://smartcrane.blog.csdn.net/article/details/121837850 1. 项目介绍 本项目实现 ...
- 树莓派配置红外遥控及关联python程序
前言 关于树莓派配置红外遥控的过程,我相信玩过的人知道这里的坑有多少,在这写一下我配置的过程,仅供参考 硬件 1.树莓派4B 2.红外遥控器及接收模块,我用的 这里不得不提一下有关红外接收模,之前我用 ...
- 树莓派4B + HX1838
文章目录 树莓派4B 4GB Hardware v1.4 安装配置 lirc 录制按键 继续配置lirc 在python 程序中使用lirc 树莓派4B 4GB Hardware v1.4 HX183 ...
- linux烟雾传感器程序,树莓派4B之烟雾传感器模块(python3)
背景 本人最因工作原因接触到各种电路板,传感器,而自己又是一个小白,随意在其他朋友的推荐下决定从树莓派开始玩传感器:本例子为树莓派控制红外避障传感器 材料 1.树莓派4b 2.火焰传感器模块 3.导线 ...
- 基于树莓派4B的智能无人巡逻小车设计
计算机工程实训报告 题目 智能警用无人巡逻小车 视频演示地址:树莓派暑期工程实训-模拟警用无人巡逻小车_哔哩哔哩_bilibili 一.实验内容与要求 1.1 实验内容 本实验使用 Yahboom 生 ...
最新文章
- java8异步_Java8新特性之:CompletableFuture
- Ubuntu12.04下arm交叉编译环境的建立
- 开放医疗交通大数据技术 服务于公共便民领域
- 创建一个国家的下拉菜单(magento2)
- 软件测试整理复习(简答题)转载请经由作者同意
- 修改android开机动画
- 死链对网站的影响、产生过程、解决办法汇总
- mysql如何创建用户代码_mysql 创建用户 并 受权_mysql
- ceph 代码分析 读_Ceph代码分析
- 【概率论】范畴分布 Categorical / Multinoulli Distribution
- 安全访问(ISO14229系列之27服务)
- python实现 把列表中数字0移动到末尾
- 小组项目--闲置物品交换系统-第一周
- 输入等值线参数绘制等值线图python_ArcGIS绘图—空气质量站点数据插值绘制等值线图...
- 【自动化办公】python处理PDF文件操作指南
- CTF杂项之总结(一)
- 关于浏览器输入一个网址后页面经历的过程总结
- 广告动画 android,age动漫官方网软件app-AGE动漫无广告纯净版下载v1.4安卓版-西西软件下载...
- 前端常用开发环境、软件等
- 惠普(hp)3803tx xp 驱动程序 安装教程