Monday, 22 June 2020

Raspberry Pi IR


Notes to make IR shield (made by LinkSprite) work in Raspberry Pi 3 (bought from Amazon [1]).

The vendor has some documentation [2] but that is not complete and sufficient for Raspbian Stretch.
Following are the changes that I made to make it work.

$ sudo apt-get update
$ sudo apt-get install lirc

# Add the following lines to /etc/modules file
lirc_dev
lirc_rpi gpio_in_pin=18 gpio_out_pin=17

# Add the following lines to /etc/lirc/hardware.conf file
LIRCD_ARGS="--uinput --listen"
LOAD_MODULES=true
DRIVER="default"
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"

# Update the following line in /boot/config.txt (incomment if required)
dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17

# Update the following lines in /etc/lirc/lirc_options.conf
# Update the following lines in /etc/lirc/lircd.conf
driver    = default
device    = /dev/lirc0

# Reboot before testing
$ reboot

$ sudo /etc/init.d/lirc stop
$ sudo /etc/init.d/lirc start

# Check status to make lirc is running
$ sudo /etc/init.d/lirc status


# Populate lircd.conf

#
# this config file was automatically generated
# using lirc-0.8.6(default) on Fri Sep 10 22:02:46 2010
#
# contributed by
#
# brand:                       TV LG 42"LD420
# model no. of remote control: AKB72915207
# devices being controlled by this remote:
#

begin remote

  name  LG_AKB72915207
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       9056  4448
  one           601  1647
  zero          601   538
  ptrail        601
  repeat       9081  2199
  pre_data_bits   16
  pre_data       0x20DF
  gap          108229
  toggle_bit_mask 0x0

      begin codes
          KEY_POWER                0x10EF                    #  Was: power
          energy                   0xA956
          avmode                   0x0CF3
          input                    0xD02F
          tvrad                    0x0FF0
          KEY_1                    0x8877                    #  Was: 1
          KEY_2                    0x48B7                    #  Was: 2
          KEY_3                    0xC837                    #  Was: 3
          KEY_4                    0x28D7                    #  Was: 4
          KEY_5                    0xA857                    #  Was: 5
          KEY_6                    0x6897                    #  Was: 6
          KEY_7                    0xE817                    #  Was: 7
          KEY_8                    0x18E7                    #  Was: 8
          KEY_9                    0x9867                    #  Was: 9
          KEY_0                    0x08F7                    #  Was: 0
          KEY_LIST                 0xCA35                    #  Was: list
          q.view                   0x58A7
          KEY_VOLUMEUP             0x40BF                    #  Was: vol_up
          KEY_VOLUMEDOWN           0xC03F                    #  Was: vol_down
          KEY_CHANNELUP            0x00FF                    #  Was: ch_up
          KEY_CHANNELDOWN          0x807F                    #  Was: ch_down
          KEY_FAVORITES            0x7887                    #  Was: fav
          ratio                    0x9E61
          KEY_MUTE                 0x906F                    #  Was: mute
          KEY_MENU                 0xC23D                    #  Was: menu
          KEY_INFO                 0xD52A                    #  Was: guide
          q.menu                   0xA25D
          KEY_UP                   0x02FD                    #  Was: up
          KEY_DOWN                 0x827D                    #  Was: down
          KEY_LEFT                 0xE01F                    #  Was: left
          KEY_RIGHT                0x609F                    #  Was: right
          KEY_OK                   0x22DD                    #  Was: ok
          KEY_BACK                 0x14EB                    #  Was: back
          KEY_INFO                 0x55AA                    #  Was: info
          KEY_EXIT                 0xDA25                    #  Was: exit
          KEY_RED                  0x4EB1                    #  Was: red
          KEY_GREEN                0x8E71                    #  Was: green
          ellow                    0xC639
          KEY_BLUE                 0x8679                    #  Was: blue
          exit2                    0x04FB
          t.opt                    0x847B
          KEY_SUBTITLE             0x9C63                    #  Was: subtitle
          KEY_STOP                 0x8D72                    #  Was: stop
          KEY_PLAY                 0x0DF2                    #  Was: play
          KEY_PAUSE                0x5DA2                    #  Was: pause
          KEY_REWIND               0xF10E                    #  Was: <<
          KEY_FORWARD              0x718E                    #  Was: >>
          simplink                 0x7E81
      end codes

end remote


# To test if lirc output driver is working
$ irsend SEND_ONCE LG_AKB72915207 KEY_POWER


# To test if lirc input driver is working
$ sudo /etc/init.d/lircd stop
$ mode2 -d /dev/lirc0
<press a key in remote and you should see multple lines like below>
pulse 560
space 1706
pulse 535

# to record a custom remote/register a remote device
$ sudo /etc/init.d/lircd stop
$ sudo irrecord -d /dev/lirc0 ~/lircd.conf
# follow the instruction prompted by the above command carefully
# at the end ~/lircd.conf file will be generated

# backup the original lircd.conf
$ sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf
$ sudo cp ~/lircd.conf /etc/lirc/lircd.conf
$ sudo /etc/init.d/lircd start

# you can test if the recorded remote works by
$ irsend SEND_ONCE <device-name> KEY_POWER
$ irsend SEND_ONCE <device-name> KEY_VOLUMEUP

[1] https://www.amazon.com/Infrared-Shield-for-Raspberry-Pi/dp/B00K2IICKK/ref=pd_sbs_328_1?_encoding=UTF8&psc=1&refRID=1QPY33VFCGETBJ17K8QE
[2] http://learn.linksprite.com/raspberry-pi/shield/infrared-transceiver-on-raspberry-pi-lirc-software-installation-and-configuration/

No comments:

Post a comment