- LIRC setup in Raspberry PI Raspbian Jessie.
- Install LIRC packages with,
sudo apt-get install lirc
.
- Set up pin connection in
/etc/modules
. Please remember to put /
in front of etc
, so it is /etc/modules
and not etc/modules
.
lirc_dev
lirc_rpi gpio_in_pin=23 gpio_out_pin=22
echo "test test" | sudo tee -a /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/config-test.conf
- From the example code above I have "test" and then after I applied the code it becomes "testtest test". So I need to apply line break manually.
echo "\ntest test" | sudo tee -a /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/config-test.conf
- After I execute code above my .conf file is like this.
testtest test
\ntest test
- Apparently
\n
is not registered as an escape character.
- I checked other example command to add line into configuration file,
sudo /bin/sh -c 'echo "nameserver 192.168.1.6" >> /etc/resolv.conf'
.
- I modify it into my need.
sudo /bin/sh -c 'echo "test test test" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/config-test.conf'
sudo /bin/sh -c 'printf "test test printf" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/config-test.conf'
- Adding line break before adding the modified codes.
sudo /bin/sh -c 'printf "\n\ntest test printf" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/config-test.conf'
- Apparently
printf
is capable to understand \n
which is nice. However, as you can see from the code above I need to add 2 \n
to get 1 line break.
- I guess the 1st line break is neglected?
- So I need to add these into
/etc/modules
.
lirc_dev
lirc_rpi gpio_in_pin=23 gpio_out_pin=22
sudo /bin/sh -c 'printf "\n\nlirc_dev\nlirc_rpi gpio_in_pin=23 gpio_out_pin=22" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/config-test.conf'
- The bash codes above is perfect. So now I need to adjust it into
/etc/modules
.
sudo /bin/sh -c 'printf "\n\nlirc_dev\nlirc_rpi gpio_in_pin=23 gpio_out_pin=22" >> /etc/modules'
/etc/modules
is used to list an optional kernel that should be loaded.
- Testing to write configuration file from shell script.
sudo /bin/sh -c 'printf "########################################################\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# /etc/lirc/hardware.conf\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "#\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# Arguments which will be used when launching lircd\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "LIRCD_ARGS=\"--uinput\"\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# Do not start lircmd even if there seems to be a good config file\n"` >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# START_LIRCMD=false\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# Do not start irexec, even if a good config file seems to exist.\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# START_IREXEC=false\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# Try to load appropriate kernel modules\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "LOAD_MODULES=true\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# Run \"lircd --driver=help\" for a list of supported drivers.\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "DRIVER=\"default\"\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# usually /dev/lirc0 is the correct setting for systems using udev\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "DEVICE=\"/dev/lirc0\"\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "MODULES=\"lirc_rpi\"\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "# Default configuration files for your hardware if any\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "LIRCD_CONF=\"\"\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "LIRCMD_CONF=\"\"\n" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "########################################################" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
sudo /bin/sh -c 'printf "########################################################\n# /etc/lirc/hardware.conf\n#\n# Arguments which will be used when launching lircd\nLIRCD_ARGS=\"--uinput\"\n\n# Do not start lircmd even if there seems to be a good config file\n# START_LIRCMD=false\n\n# Do not start irexec, even if a good config file seems to exist.\n# START_IREXEC=false\n\n# Try to load appropriate kernel modules\nLOAD_MODULES=true\n\n# Run \"lircd --driver=help\" for a list of supported drivers.\nDRIVER=\"default\"\n# usually /dev/lirc0 is the correct setting for systems using udev\nDEVICE=\"/dev/lirc0\"\nMODULES=\"lirc_rpi\"\n\n# Default configuration files for your hardware if any\nLIRCD_CONF=\"\"\nLIRCMD_CONF=\"\"\n########################################################" >> /home/notalentgeek/Downloads/project-commitment/pc-ut-bachelor-thesis-2016/deliverable-programming/test-bash-add-config-file-1/lircd.conf'
- Change the target into
/etc/lirc/hardware.conf
. But we need first to delete the original LIRC configuration file.
sudo rm /etc/lirc/hardware.conf
sudo /bin/sh -c 'printf "########################################################\n# /etc/lirc/hardware.conf\n#\n# Arguments which will be used when launching lircd\nLIRCD_ARGS=\"--uinput\"\n\n# Do not start lircmd even if there seems to be a good config file\n# START_LIRCMD=false\n\n# Do not start irexec, even if a good config file seems to exist.\n# START_IREXEC=false\n\n# Try to load appropriate kernel modules\nLOAD_MODULES=true\n\n# Run \"lircd --driver=help\" for a list of supported drivers.\nDRIVER=\"default\"\n# usually /dev/lirc0 is the correct setting for systems using udev\nDEVICE=\"/dev/lirc0\"\nMODULES=\"lirc_rpi\"\n\n# Default configuration files for your hardware if any\nLIRCD_CONF=\"\"\nLIRCMD_CONF=\"\"\n########################################################" >> /etc/lirc/hardware.conf'
- After this I need to restart the LIRC service.
sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start
- There is this safety measure, add these lines into
/boot/config.txt
.
dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22
sudo /bin/sh -c 'printf "dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22" >> /boot/config.txt'
- So the full LIRC setup would be.
sudo apt-get install lirc
sudo /bin/sh -c 'printf "\n\nlirc_dev\nlirc_rpi gpio_in_pin=23 gpio_out_pin=22" >> /etc/modules'
sudo rm /etc/lirc/hardware.conf
sudo /bin/sh -c 'printf "########################################################\n# /etc/lirc/hardware.conf\n#\n# Arguments which will be used when launching lircd\nLIRCD_ARGS=\"--uinput\"\n\n# Do not start lircmd even if there seems to be a good config file\n# START_LIRCMD=false\n\n# Do not start irexec, even if a good config file seems to exist.\n# START_IREXEC=false\n\n# Try to load appropriate kernel modules\nLOAD_MODULES=true\n\n# Run \"lircd --driver=help\" for a list of supported drivers.\nDRIVER=\"default\"\n# usually /dev/lirc0 is the correct setting for systems using udev\nDEVICE=\"/dev/lirc0\"\nMODULES=\"lirc_rpi\"\n\n# Default configuration files for your hardware if any\nLIRCD_CONF=\"\"\nLIRCMD_CONF=\"\"\n########################################################" >> /etc/lirc/hardware.conf'
sudo /bin/sh -c 'printf "dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22" >> /boot/config.txt'
sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start
- Full shell executable file (there is an updated version, check below).
#!/bin/bash
sudo apt-get install lirc
sudo /bin/sh -c 'printf "\n\nlirc_dev\nlirc_rpi gpio_in_pin=23 gpio_out_pin=22" >> /etc/modules'
sudo rm /etc/lirc/hardware.conf
sudo /bin/sh -c 'printf "########################################################\n# /etc/lirc/hardware.conf\n#\n# Arguments which will be used when launching lircd\nLIRCD_ARGS=\"--uinput\"\n\n# Do not start lircmd even if there seems to be a good config file\n# START_LIRCMD=false\n\n# Do not start irexec, even if a good config file seems to exist.\n# START_IREXEC=false\n\n# Try to load appropriate kernel modules\nLOAD_MODULES=true\n\n# Run \"lircd --driver=help\" for a list of supported drivers.\nDRIVER=\"default\"\n# usually /dev/lirc0 is the correct setting for systems using udev\nDEVICE=\"/dev/lirc0\"\nMODULES=\"lirc_rpi\"\n\n# Default configuration files for your hardware if any\nLIRCD_CONF=\"\"\nLIRCMD_CONF=\"\"\n########################################################" >> /etc/lirc/hardware.conf'
sudo /bin/sh -c 'printf "dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22" >> /boot/config.txt'
sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start
$SHELL
- There is actually one thing left! The
lircd.conf
file in /etc/lirc/lircd.conf
. Here are all the configurations.
# Please make this file available to others
# by sending it to <lirc@bartelmus.de>
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Sat Jan 7 22:45:56 2017
#
# contributed by
#
# brand: /home/pi/lircd.conf
# model no. of remote control:
# devices being controlled by this remote:
#
begin remote
name pysoc
bits 13
flags RC5|CONST_LENGTH
eps 30
aeps 100
one 924 840
zero 924 840
plead 970
gap 113287
toggle_bit_mask 0x0
begin codes
KEY_1 0x1001
KEY_2 0x1002
KEY_3 0x1003
end codes
end remote
- Shell command to make the
lircd.conf
.
sudo /bin/sh -c 'printf "\n# Please make this file available to others\n# by sending it to <lirc@bartelmus.de>\n#\n# this config file was automatically generated\n# using lirc-0.9.0-pre1(default) on Sat Jan 7 22:45:56 2017\n#\n# contributed by \n#\n# brand: /home/pi/lircd.conf\n# model no. of remote control: \n# devices being controlled by this remote:\n#\n\nbegin remote\n\n name pysoc\n bits 13\n flags RC5|CONST_LENGTH\n eps 30\n aeps 100\n\n one 924 840\n zero 924 840\n plead 970\n gap 113287\n toggle_bit_mask 0x0\n\n begin codes\n KEY_1 0x1001\n KEY_2 0x1002\n KEY_3 0x1003\n end codes\n\nend remote" >> /home/pi/lircd.conf'
- Make a copy for the original configuration file.
sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_backup.conf
- Creating
.lircrc
in ~
and in /etc/lirc/lircrc
.
- Whole runcom file.
begin
button = KEY_1
config = KEY_1
prog = pysoc
end
begin
button = KEY_2
config = KEY_2
prog = pysoc
end
begin
button = KEY_3
config = KEY_3
prog = pysoc
end
printf "begin\n button = KEY_1\n config = KEY_1\n prog = pysoc\nend\nbegin\n button = KEY_2\n config = KEY_2\n prog = pysoc\nend\nbegin\n button = KEY_3\n config = KEY_3\n prog = pysoc\nend" >> ~/.lircrc
sudo /bin/sh -c 'printf "begin\n button = KEY_1\n config = KEY_1\n prog = pysoc\nend\nbegin\n button = KEY_2\n config = KEY_2\n prog = pysoc\nend\nbegin\n button = KEY_3\n config = KEY_3\n prog = pysoc\nend" >> /etc/lirc/lircrc'
- Updated shell executable file for LIRC setting.
#!/bin/bash
# Install LIRC packages for Raspbian Jessie.
sudo apt-get install lirc
# Add pinouts mapping into `/etc/modules`.
sudo /bin/sh -c 'printf "\n\nlirc_dev\nlirc_rpi gpio_in_pin=23 gpio_out_pin=22" >> /etc/modules'
# Deleting `hardware.conf` and then re - create it back.
sudo rm /etc/lirc/hardware.conf
sudo /bin/sh -c 'printf "\n########################################################\n# /etc/lirc/hardware.conf\n#\n# Arguments which will be used when launching lircd\nLIRCD_ARGS=\"--uinput\"\n# Do not start lircmd even if there seems to be a good config file\n# START_LIRCMD=false\n# Do not start irexec, even if a good config file seems to exist.\n# START_IREXEC=false\n# Try to load appropriate kernel modules\nLOAD_MODULES=true\n# Run \"lircd --driver=help\" for a list of supported drivers.\nDRIVER=\"default\"\n# usually /dev/lirc0 is the correct setting for systems using udev\nDEVICE=\"/dev/lirc0\"\nMODULES=\"lirc_rpi\"\n# Default configuration files for your hardware if any\nLIRCD_CONF=\"\"\nLIRCMD_CONF=\"\"\n########################################################" >> /etc/lirc/hardware.conf'
# Add line into boot configuration.
sudo /bin/sh -c 'printf "\ndtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22" >> /boot/config.txt'
# Backup the original IR codes dictionary and then add our own.
sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_backup.conf
sudo /bin/sh -c 'printf "\n# Please make this file available to others\n# by sending it to <lirc@bartelmus.de>\n#\n# this config file was automatically generated\n# using lirc-0.9.0-pre1(default) on Sat Jan 7 22:45:56 2017\n#\n# contributed by \n#\n# brand: /home/pi/lircd.conf\n# model no. of remote control: \n# devices being controlled by this remote:\n#\nbegin remote\n name pysoc\n bits 13\n flags RC5|CONST_LENGTH\n eps 30\n aeps 100\n one 924 840\n zero 924 840\n plead 970\n gap 113287\n toggle_bit_mask 0x0\n begin codes\n KEY_1 0x1001\n KEY_2 0x1002\n KEY_3 0x1003\n end codes\nend remote" >> /home/pi/lircd.conf'
# Add local and system wide `lircrc`.
printf "\nbegin\n button = KEY_1\n config = KEY_1\n prog = pysoc\nend\nbegin\n button = KEY_2\n config = KEY_2\n prog = pysoc\nend\nbegin\n button = KEY_3\n config = KEY_3\n prog = pysoc\nend\" >> ~/.lircrc
sudo /bin/sh -c 'printf "\nbegin\n button = KEY_1\n config = KEY_1\n prog = pysoc\nend\nbegin\n button = KEY_2\n config = KEY_2\n prog = pysoc\nend\nbegin\n button = KEY_3\n config = KEY_3\n prog = pysoc\nend\" >> /etc/lirc/lircrc'
# Restart `lirc` service.
sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start
$SHELL