Android with root Git for version control Lircd with Raspberry Pi for IR receiver and sender Tips for Windows Depolying your own password management tool -- KeeWeb Depoly your flask app into Heroku Fix shit IE code manually ISBN to Book Category by Scraping DangDang A Generic Makefile for C/C++ Program Configure Raspberry pi Remove watermark with PyPDF2 tips for docker Anaconda+TensorFlow+CUDA Snippets Configure Remote Mathematica Kernel Build your own ngrok server Access Array SSL VPN 使用Rstudio制作html5幻灯片 tips for Mac OS X system Tips for ipython notebook 配置Ubuntu server + Openbox (Obuntu) tips for Vimperator tips for Vim 安装CUDA My First Jekyll Blog rsync常见选项 在Linux中读取Ipod touch的文件 tip for texmacs 在VPS上建站的一些tip Gnuplot绘图札记 Samba系统和autofs自动挂载 Linux中alsamixer声卡无法录音 搭建自己的RSS订阅器——Tiny Tiny RSS Grub2引导安装Ubuntu awk tips 将Ubuntu系统装入U盘 The Great Rtorrent 编译GCC 再这样剁手!!!该死的libgd 使用ulimit进行资源限制 使用SSH代理上IPV6 使用RCurl抓取网页数据 修复Ubuntu Grub记 openbox中的文件关联 在Ubuntu 12.04下编译qtiplot 处理BCM4312网卡驱动纪实 配置我的Ubuntu Server记 Cygwin杂记 Linux 使普通用户具有以超级权限执行脚本 让firefox自定义地处理文件类型 WordPress优秀主题及插件 在phpcloud上搭建wordpress UBUNTU下用pptpd做VPN server ubuntu升级内核过后的一些问题 安装telnet服务 kubuntu札记 64位kubuntu札记 统计软件R Virtualbox stardict星际译王 Ubuntu重装windows系统后的grub引导修复 SSH服务及花生壳域名解析 采用cbp2make工具由code::blocks工程创建makefile文件 UBUNTU 札记

Lircd with Raspberry Pi for IR receiver and sender

2019年08月06日

connect the hardware

https://pi4j.com/1.2/images/j8header-zero-large.png, https://pi4j.com/1.2/images/j8header-photo-zero-large.png or following command show how to connect the PINs.

sudo apt install python3-gpiozero
pinout

I got a KY-022 IR receiver and a unknown type IR sender. I think the symbol S or DAT mean signal or data to be send, should connect to any GPIO pins in raspberry pi, while GND or - stand for Ground or 0 votage. VCC should be the positive votage, here in my case are both 5V.

install lircd service

I have seen people use pulseio or pigpio to control the IR. But in most case, lirc should be a default choose.

sudo apt install lircd
tee -a /boot/config.txt <<EOF
dtoverlay=lirc-rpi
dtparam=gpio_in_pin=14
dtparam=gpio_out_pin=15
EOF

Now the system should reboot.

configure the lircd remote

One may create a remote device file /etc/lirc/lircd.conf.d/midea.lircd.conf to define the parameters/signal sequence for the remote device.

begin remote

  name  midea
  flags RAW_CODES
  eps       30
  aeps      100

  ptrail    0
  repeat    0  0
  gap       108229

      begin raw_codes

          name toogle
              8922 4396 581 1615 598 531 577 528 579 528 578 529 577 535 602 501 575 532 576 532 604 1587 599 1611 601 1612 606 1609 604 1608 603 1612 603 1610 607 1606 601 1615 598 529 580 530 573 531 573 534 598 508 578 532 572 535 574 530 577 1617 597 1617 595 1616 599 1612 597 1615 603 1609 610 1611 596 1619 594 528 580 530 576 531 588 516 577 527 603 507 578 529 578 527 576 1623 615 1587 628 1608 581 1616 607 1602 601 1609 604

      end raw_codes

end remote

man lircd.conf to see the meaning of those configurations.

There mighe be already a configuration devinput.lircd.conf which can be removed or disabled (rename to *.dist) without any concern.

Notice the raw_codes integer sequence, to understand it, see something like the NEC/RC-5 protocol.

For the IR sender follow NEC protocol, command irrecord -d /dev/lirc0 ~/base.lircd.conf can be used to record the buttons. But in my case, the hardware do not send NEC codes, so when using irrecord, I can not complete the collection parameter stage(the one irrecord need you to randomly push buttons to get two rows of dots). People might suggest use irrecord -f to force the raw codes mode, but it still do not work for me.

So I stopped the lirc with command sudo systemctl stop lircd, and then use mode2 -d /dev/lirc0 to collect the pulse/space data myself, that is how I got the raw_codes above. The codes usually start with a pulse last for 890 ms and end with a pulse, then might be a space with randomly duration(should be the space between you to button press).

For a complex IR sender, like the one for Air Conditioners, the raw codes should be carefully analysised because when you press the same button twice, you might get different signals.

I attached following python script when plotting the signals.

import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
from itertools import chain, islice

signal_seq = []
with open('/tmp/midea.history', 'r') as fp:
    for l in fp:
        s, t = l.split(' ')
        if s == 'space' and int(t) > 10000:
            signal_seq.append([])
        else:
            signal_seq[-1].append((len(signal_seq), 1 if s=='pulse' else 0, int(t)))


dat = pd.DataFrame(list(chain.from_iterable(signal_seq)), columns=['id', 'signal', 'period'])
fig, axs = plt.subplots(nrows=1, ncols=1, figsize=(20, 10))

for i, d in islice(dat.groupby(dat.id), 300):
    axs.set_ylim([-0.2, 3.5])
    #axs.set_xlim([-1, 10000])

    s = list(chain.from_iterable(((l-e, s), (l, s))
                                 for s, l, e in zip(d.signal, np.cumsum(d.period), d.period)))

    axs.plot(*zip(*[(t, s*2+i*0.1) for t, s in s]), '-')

    code = ''.join((d.period[1::2][1:]>1000).astype(np.int).astype(str))

    print(code[:16], code[16: (16+(len(code)-16)//2)]==code[-(len(code)-16)//2:])

fig.show()

Simulate press button

irsend SEND_ONCE midea toogle