Edit...I now use @FizzyTea version as it is simpler, more up to date and more secure. The key mapping I show is still valid though...especially for power off and webradio.
Here is my 'from scratch' set up. It was made for my own reference when Raspbian moved to Stretch release and some major changes were made to Lirc.
It was cobbled together from the old Jessie How-to from the Just-Boom site and what I could glean from Googling.
It still works and I use it on new installs.
Note that @FizzyTea has a version that works too and some comments about security here....http://moodeaudio.org/forum/showthread.php?tid=187&pid=1383#pid1383
LIRC for STRETCH
Step 1 Install Lirc
Step 2 Edit /etc/modules
and add your IR input pin by adding the following lines to the end of the file with the Pi GPIO pin you used (mine is 27, replace this with yours):
Step 3 Create /etc/lirc/hardware.conf
then copy and paste into it the following content:
Step 4 Edit /etc/lirc/lirc_options.conf
and make sure that driver and devices lines are changed to:
driver = default
device = /dev/lirc0
Step 5 Edit /boot/config.txt
and configure kernel extensions by adding the following lines to the end of the file:
# Enable the lirc-rpi module
dtoverlay=lirc-rpi
# Override the defaults for the lirc-rpi module
dtparam=gpio_in_pin=xx
(where 'xx' is the gpio pin used for input... eg gpio_in_pin=27)
Step 6 Reboot Raspberry Pi:
If all went well you should now have a lirc0 device. Verify this by issuing the following command:
this command should return a file named lirc0. If this command doesn’t output go back and verify the configuration once again as the drivers have not been loaded.
Step 7 Testing the IR remote and Receiver
Follow the steps below to verify that the IR receiver is working as expected:
Stop LIRC systemd service:
Start outputting raw data from the IR receiver....run this command.
Point a remote control at the IR receiver and press its buttons. If the IR receiver is configured successfully you will see output like this:
space 3662230
pulse 2428
space 594
pulse 1201
space 596
pulse 1230
space 595
pulse 1209
space 590
pulse 1204
(CTRL+C to stop output and return to command line)
Stop LIRC systemd service
If you need to run the training because your IR remote is not in the LIRC Remote Database (http://lirc-remotes.sourceforge.net/remotes-table.html) then do step 8a.
If you already have a lirc configuration file then go to step 8b. (do a or b not both)
Step 8a – To start the training run:
This will initiate the training for your remote and save the configuration in /home/pi/lircd.conf
Follow the instructions given by the program.
Note that the program will ask for a name for the file. Leave it blank.
Note that if you run this and save the file but it is incorrect and you need to run the training again then you have to remove the old ~/lircd.conf (and /etc/lirc/lircd.conf if you have run step 9 as well) otherwise the training will not initiate for subsequent runs.
Step 8b If you already have a lirc configuration file then create a new file called lircd.conf by typing:
and paste the file into it.
Step 9 Backup the old configuration and replace it with the newly created one by running:
Launch LIRC systemd service again:
This will reload LIRC with the new configuration and you should now have a lircd daemon running. Type the following to verify that to be the case.
You should get lircd and lircd.pid files .....proof that the daemon has been loaded properly and LIRC is working.
Once LIRC is configured you need to create a file that will match the remote control IR signals to commands for the MPD used in the distro that you are running.
Step 10 – Create a file called .lircrc in your home folder
by issuing the command:
and add as appropriate using this template and the buttons mapped in your recently created /etc/lirc/lircd.conf...
begin
prog = irexec
button = <your new button>
config = mpc <command>
end
for example.....
begin
prog = irexec
button = OK
config = mpc toggle
end
begin
prog = irexec
button = Volume-Up
config = mpc volume +2
end
begin
prog = irexec
button = Volume-Down
config = mpc volume -2
end
begin
prog = irexec
button = Right
config = mpc next
end
begin
prog = irexec
button = Left
config = mpc prev
end
begin
prog = irexec
button = Up
config = mpc seek +00:00:10
end
begin
prog = irexec
button = Down
config = mpc seek -00:00:10
end
begin
prog = irexec
button = Back
config = mpc repeat on
end
begin
prog = irexec
button = Menu
config = mpc repeat off
end
At this point you can test the configuration created by running :
Point the remote control to the IR sensor and press some of the buttons, you should get an output similar to this:
000000000000141a 00 Up lircd.conf
000000000000141a 01 Up lircd.conf
0000000000001414 00 Right lircd.conf
0000000000001414 01 Right lircd.conf
(CTRL+C to exit execution)
This means that the remote is correctly mapped and all should be working fine. Lastly test that the file .lircrc is also working fine and that the remote can issue commands to MPD. :
By pressing buttons on your remote you should now get an output similar to the following:
volume: 39% repeat: off random: off single: off consume: off
volume: 37% repeat: off random: off single: off consume: off
(CTRL+C to exit execution)
With this last test you have verified that all is working as it should.
With irexec running you should have also seen things happening within the player of your distribution. If you had a song playing and you pressed the buttons of the volume, the audio level should have also changed.
Step 11 Make irexec run at boot time.
Edit the rc.local file by issuing the following command:
and add this line just before the ‘exit 0’ line....
sudo -u pi irexec -d
so it looks like this
/usr/bin/udisks-glue/dev/null
/var/www/command/worker.php/dev/null
sudo -u pi irexec -d
exit 0
Step 12 Shutdown and restart. Your remote should be working now..:-)
TROUBLESHOOTING....
NOTE 1.... occasionally when making changes elsewhere in moOde then /boot/config.txt can be overwritten and the line that reads dtoverlay=lirc-rpi is removed.
This can lead to some strange behaviour such as no audio output, the remote not working and sometimes the U/I being slow or unresponsive.
Simply ssh in and re-add the missing line then reboot.
and add....
# Enable the lirc-rpi module
dtoverlay=lirc-rpi
NOTE2... Most remotes work with Lirc but not ALL remotes.
If you have one that has a matching config in the Lirc database then you're in luck, use that.
If you need to run the training using irrecord and cannot get your chosen remote to work then try another remote.
Thrift shops have boxes full of them for spare change.
Choosing a major brand and a single common device remote will have a greater chance of success than little known and/or multi-device controllers.
So a dedicated eg Sony dvd remote (not a tv/dvd dual type) will be better than a 'Wishbangopop' Dvd/TV/Hi-fi/Aircon/Toaster multi-remote.
Here is my 'from scratch' set up. It was made for my own reference when Raspbian moved to Stretch release and some major changes were made to Lirc.
It was cobbled together from the old Jessie How-to from the Just-Boom site and what I could glean from Googling.
It still works and I use it on new installs.
Note that @FizzyTea has a version that works too and some comments about security here....http://moodeaudio.org/forum/showthread.php?tid=187&pid=1383#pid1383
LIRC for STRETCH
Step 1 Install Lirc
Code:
sudo apt-get update
sudo apt-get install -y lirc
Step 2 Edit /etc/modules
Code:
sudo nano /etc/modules
and add your IR input pin by adding the following lines to the end of the file with the Pi GPIO pin you used (mine is 27, replace this with yours):
Code:
lirc_dev
lirc_rpi gpio_in_pin=27
Step 3 Create /etc/lirc/hardware.conf
Code:
sudo nano /etc/lirc/hardware.conf
then copy and paste into it the following content:
Code:
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"
#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD=false
#Don't start irexec, even if a good config file seems to exist.
#START_IREXEC=false
#Try to load appropriate kernel modules
LOAD_MODULES=true
# Run "lircd --driver=help" for a list of supported drivers.
#DRIVER="UNCONFIGURED"
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
Step 4 Edit /etc/lirc/lirc_options.conf
Code:
sudo nano /etc/lirc/lirc_options.conf
and make sure that driver and devices lines are changed to:
driver = default
device = /dev/lirc0
Step 5 Edit /boot/config.txt
Code:
sudo nano /boot/config.txt
and configure kernel extensions by adding the following lines to the end of the file:
# Enable the lirc-rpi module
dtoverlay=lirc-rpi
# Override the defaults for the lirc-rpi module
dtparam=gpio_in_pin=xx
(where 'xx' is the gpio pin used for input... eg gpio_in_pin=27)
Step 6 Reboot Raspberry Pi:
Code:
sudo reboot
If all went well you should now have a lirc0 device. Verify this by issuing the following command:
Code:
ls /dev/lirc0
this command should return a file named lirc0. If this command doesn’t output go back and verify the configuration once again as the drivers have not been loaded.
Step 7 Testing the IR remote and Receiver
Follow the steps below to verify that the IR receiver is working as expected:
Stop LIRC systemd service:
Code:
sudo systemctl stop lircd
Start outputting raw data from the IR receiver....run this command.
Code:
mode2 -d /dev/lirc0
Point a remote control at the IR receiver and press its buttons. If the IR receiver is configured successfully you will see output like this:
space 3662230
pulse 2428
space 594
pulse 1201
space 596
pulse 1230
space 595
pulse 1209
space 590
pulse 1204
(CTRL+C to stop output and return to command line)
Stop LIRC systemd service
Code:
sudo systemctl stop lircd
If you need to run the training because your IR remote is not in the LIRC Remote Database (http://lirc-remotes.sourceforge.net/remotes-table.html) then do step 8a.
If you already have a lirc configuration file then go to step 8b. (do a or b not both)
Step 8a – To start the training run:
Code:
irrecord -d /dev/lirc0
This will initiate the training for your remote and save the configuration in /home/pi/lircd.conf
Follow the instructions given by the program.
Note that the program will ask for a name for the file. Leave it blank.
Note that if you run this and save the file but it is incorrect and you need to run the training again then you have to remove the old ~/lircd.conf (and /etc/lirc/lircd.conf if you have run step 9 as well) otherwise the training will not initiate for subsequent runs.
Step 8b If you already have a lirc configuration file then create a new file called lircd.conf by typing:
Code:
nano ~/lircd.conf
and paste the file into it.
Step 9 Backup the old configuration and replace it with the newly created one by running:
Code:
sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd-backup.conf
Code:
sudo cp ~/lircd.conf /etc/lirc/lircd.conf
Launch LIRC systemd service again:
Code:
sudo systemctl start lircd
This will reload LIRC with the new configuration and you should now have a lircd daemon running. Type the following to verify that to be the case.
Code:
ls /var/run/lirc/
You should get lircd and lircd.pid files .....proof that the daemon has been loaded properly and LIRC is working.
Once LIRC is configured you need to create a file that will match the remote control IR signals to commands for the MPD used in the distro that you are running.
Step 10 – Create a file called .lircrc in your home folder
by issuing the command:
Code:
nano ~/.lircrc
and add as appropriate using this template and the buttons mapped in your recently created /etc/lirc/lircd.conf...
begin
prog = irexec
button = <your new button>
config = mpc <command>
end
for example.....
begin
prog = irexec
button = OK
config = mpc toggle
end
begin
prog = irexec
button = Volume-Up
config = mpc volume +2
end
begin
prog = irexec
button = Volume-Down
config = mpc volume -2
end
begin
prog = irexec
button = Right
config = mpc next
end
begin
prog = irexec
button = Left
config = mpc prev
end
begin
prog = irexec
button = Up
config = mpc seek +00:00:10
end
begin
prog = irexec
button = Down
config = mpc seek -00:00:10
end
begin
prog = irexec
button = Back
config = mpc repeat on
end
begin
prog = irexec
button = Menu
config = mpc repeat off
end
At this point you can test the configuration created by running :
Code:
irw
Point the remote control to the IR sensor and press some of the buttons, you should get an output similar to this:
000000000000141a 00 Up lircd.conf
000000000000141a 01 Up lircd.conf
0000000000001414 00 Right lircd.conf
0000000000001414 01 Right lircd.conf
(CTRL+C to exit execution)
This means that the remote is correctly mapped and all should be working fine. Lastly test that the file .lircrc is also working fine and that the remote can issue commands to MPD. :
Code:
irexec
By pressing buttons on your remote you should now get an output similar to the following:
volume: 39% repeat: off random: off single: off consume: off
volume: 37% repeat: off random: off single: off consume: off
(CTRL+C to exit execution)
With this last test you have verified that all is working as it should.
With irexec running you should have also seen things happening within the player of your distribution. If you had a song playing and you pressed the buttons of the volume, the audio level should have also changed.
Step 11 Make irexec run at boot time.
Edit the rc.local file by issuing the following command:
Code:
sudo nano /etc/rc.local
and add this line just before the ‘exit 0’ line....
sudo -u pi irexec -d
so it looks like this
/usr/bin/udisks-glue/dev/null
/var/www/command/worker.php/dev/null
sudo -u pi irexec -d
exit 0
Step 12 Shutdown and restart. Your remote should be working now..:-)
TROUBLESHOOTING....
NOTE 1.... occasionally when making changes elsewhere in moOde then /boot/config.txt can be overwritten and the line that reads dtoverlay=lirc-rpi is removed.
This can lead to some strange behaviour such as no audio output, the remote not working and sometimes the U/I being slow or unresponsive.
Simply ssh in and re-add the missing line then reboot.
Code:
sudo nano /boot/config.txt
and add....
# Enable the lirc-rpi module
dtoverlay=lirc-rpi
NOTE2... Most remotes work with Lirc but not ALL remotes.
If you have one that has a matching config in the Lirc database then you're in luck, use that.
If you need to run the training using irrecord and cannot get your chosen remote to work then try another remote.
Thrift shops have boxes full of them for spare change.
Choosing a major brand and a single common device remote will have a greater chance of success than little known and/or multi-device controllers.
So a dedicated eg Sony dvd remote (not a tv/dvd dual type) will be better than a 'Wishbangopop' Dvd/TV/Hi-fi/Aircon/Toaster multi-remote.
----------
bob
bob