Some were old and contained incorrect commands and some were new but missed other steps.
I'll assume people reading this are OK installing versions of linux and using editors such as nano.
- Install the Energenie board into your Pi (in my example I'm using a Pi version A) and the board just plugs into the Pi.
- Install Raspbian Sketch - I'm using the lite version because I don't need a graphics interface, I created my SD card using Etcher.
- I've set my Pi up for a fixed IP (so I can ssh into it easily)
- As it's a Pi Version A I've configured a USB dongle to connect to Wi-Fi.
- SSH is configured so I can remote into the Pi
- I've changed the root password for security.
- The Pi is configured so it boots into the operating system without requiring the password (for automatic operation).
Using SSH means I can run the Pi "headless" without a monitor connected and any changes or commands can be done from a remote computer - for example rebooting or changing configuration.
At this point you should have a Raspberry Pi, configured with Raspbian Sketch and ready to go.
Check all updates are installed
sudo apt-get update
sudo apt-get upgrade
Now install lirc
sudo apt-get install lirc
sudo apt-get install lirc-x
The Energenie uses pin 12 - GPIO18 for Input and Pin 11 - GPIO17 for output.
edit /etc/modules and add the following lines
lirc_dev
lirc_rpi gpio_in_pin=18 gpio_out_pin17
edit /boot/config.txt and add the following line
dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17
Edit /etc/lirc/hardware.conf and add the lines below
LOAD_MODULES=true |
DRIVER="default" |
DEVICE="/dev/lirc0" |
LIRCD_ARGS="--uinput --listen" | ||||||||
If /etc/lirc/hardware.conf does not exist you can create it with the "touch" command i.e. touch /etc/lirc/hardware.conf
(If you get permission errors you might need to precede your command with sudo so you've got higher level permissions).
device = /dev/lirc0
driver = default |
I had issues getting the service to start, the reason is most guides contain old command references for the service
stop and start the service with the following commands
sudo /etc/init.d/lircd stop
sudo /etc/init.d/lircd start
You can check if the service is running with the following command.
sudo /etc/init.d/lircd status
At this point you should be able to test the IR is working.
You might want to reboot so everything is running and all files are in sync.
Stop the service
sudo /etc/init.d/lircd stop
Run this command
mode2 -d /dev/lirc0
Point a remote control at your pi and press some buttons, you should see output similar to this.
Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
space 16777215
pulse 15319054
space 3441
pulse 1772
space 395
pulse 485
space 385
pulse 1341
space 392
pulse 473
space 485
pulse 397
At this point the IR interface is receiving commands, the next step is to program it up to store commands and transmit them.
The following command will create a custom remote control configuration file in your home directory, the filename is specified when you are running the irrecord program.
sudo irrecord -d /dev/lirc0 ~/lircd.conf |
You will see output similar to the text below (not all the | output is shown). | |||||||||||
Running as regular user pi
Using driver default on device /dev/lirc0
irrecord - application for recording IR-codes for usage with lirc
Copyright (C) 1998,1999 Christoph Bartelmus(lirc@bartelmus.de)
This program will record the signals from your remote control
and create a config file for lircd.
A proper config file for lircd is maybe the most vital part of this
package, so you should invest some time to create a working config
file. Although I put a good deal of effort in this program it is often
not possible to automatically recognize all features of a remote
control. Often short-comings of the receiver hardware make it nearly
impossible. If you have problems to create a config file READ THE
DOCUMENTATION at https://sf.net/p/lirc-remotes/wiki
If there already is a remote control of the same brand available at
http://sf.net/p/lirc-remotes you might want to try using such a
remote as a template. The config files already contains all
parameters of the protocol used by remotes of a certain brand and
knowing these parameters makes the job of this program much
easier. There are also template files for the most common protocols
available. Templates can be downloaded using irdb-get(1). You use a
template file by providing the path of the file as a command line
parameter.
Please take the time to finish the file as described in
https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ an send it
to
Press RETURN to continue.
Checking for ambient light creating too much disturbances.
Please don't press any buttons, just wait a few seconds...
No significant noise (received 0 bytes)
Enter name of remote (only ascii, no spaces) :Soundbar
Using Soundbar.lircd.conf as output filename
Now start pressing buttons on your remote control.
It will guide you through pressing buttons randomly and then create the custom keys.
For a list of valid lirc command keys type
irrecord --list
To test the functionality I programmed keys for
KEY_VOLUMEUP
KEY_VOLUMEDOWN
KEY_POWER
KEY_MUTE
The file "Soundbar.lircd.conf" was created in the home folder.
From lirc version 0.9.2 you don't need to merge configuration files into one, you just copy the conf file to a folder and they are automatically included in the list of commands.
In this case I'll copy "Soundbar.lircd.conf" to the correct folder (/etc/lirc/lirc.conf.d)
The first command will make sure I'm in my home directory.
cd ~/
You could list the files in the directory to check the file is there.
ls
Soundbar.lircd.conf
Now copy the file, be careful typing in the command, the file is filename.lircd.conf but the directory it's going into is under /etc/lirc - i.e. it doesn't have the "d" at the end.
If you use the command below as reference just replace "Soundbar" with whatever you called your file.
sudo cp Soundbar.lircd.conf /etc/lirc/lircd.conf.d/
The original file will still be in your home directory should you need it.
At this point we should be at the point we can test the transmission.
I would restart the lircd service so it reloads any configuration files.
sudo /etc/init.d/lircd restart
The command to send an IR function is "irsend" and the syntax is
irsend SEND_ONCE Remote_Name Remote_Button
For my test file I'll see if the Soundbar turns on, then I'll send Volume UP and DOWN etc.
irsend SEND_ONCE Soundbar KEY_POWER
The Soundbar should turn on (as long as the Pi is pointing reasonably in the right direction).
To test the other keys just repeat the command with the key name
irsend SEND_ONCE Soundbar KEY_VOLUMEUP
irsend SEND_ONCE Soundbar KEY_VOLUMEDOWN
irsend SEND_ONCE Soundbar KEY_MUTE
You can use a command "irw" to confirm your programmed buttons, type irw and then press your remote buttons, you'll see confirmation of the ones you've programmed with their command value.
irw
0000400405000401 00 KEY_VOLUMEUP Soundbar
0000400405008481 00 KEY_VOLUMEDOWN Soundbar
0000400405004c49 00 KEY_MUTE Soundbar
Press Ctrl + C to exit the irw program.
At this point you should
1) Have lirc working on a Pi
2) Be able to stop and start the lircd service
3) Be able to create a custom remote control key file
4) Be able to copy this file from your home directory to the correct lirc folder.
My next step is to get Alexa skill and see how to control it - the ultimate aim is to get the remote downstairs and for my wife to issue a macro such as "Alexa, Media ON" to turn the TV, Cable and Soundbar on.
Ki Kev,
ReplyDeleteGood guide that, looks to be working
Think you need
sudo cp Soundbar.lircd.conf /etc/lirc/lircd.conf.d/
Also I think I has to
Create /etc/lirc/hardware.conf and add the lines
Good stuff,
Thanks
Thanks Dave, I've amended the command, also put a comment that hardware.conf can be created using the touch command.
DeleteKev