Note: Guide Updated May 2017, as I realise that /dev/input/event3 may not always be the IR receiver device on your armbian installation.
Hi All,
I recently bought an Orange PI PC and the best thing I ever did was install Armbian straight away (and donate). Now that I have a bit of spare time, I wanted to configure my Orange PI PC to do something ridiculous like play Rick Ashley 'Never going to give you up' upon pressing the 'red button' on some generic Chinese IR remote for an LED light strip I have in my living room.
Thanks to Armbian, most of the pieces are in place (such as the SunXI IR package) with the distribution, you just need to glue it all together.
However there are few configuration issues with the default Armbian install on the Orange PI PC that need to be adjusted, otherwise you'll encounter infuriating issues such as:
No IR device existing or being detected (root cause: sunxi-cir module not loaded)
No LIRC 'irw' output even after successfully using irrecord (root cause: DRIVER=devinput doesn't work, though it could be my remote), like this poor sod was experiencing.
I should also note that this guide on the terrible Orange PI forums, helped me with my issues.
Step 1) Adjust /etc/lirc/hardware.conf
Updated: This guide was originally written for Armbian based on Debian 'Jessie'. The latest Armbian (as at September 2017) is now based on Ubuntu Xenial. This introduces a new lirc package which yet again comes with a broken hardware.conf
For Ubuntu Xenial (September 2017):
The default hardware.conf that comes with Armbian is broken. It's assigning the 'remote' and 'transmitter' to the same device, this breaks everything. Ensure the TRANSMITTER_MODULES="" and TRANSMITTER_DEVICE = ""
# /etc/lirc/hardware.conf
#
#Chosen Remote Control
REMOTE="None"
REMOTE_MODULES="sunxi_cir"
REMOTE_DRIVER="default"
REMOTE_DEVICE="/dev/lirc0"
REMOTE_SOCKET="" # FYI - /run/lirc/lircd will probably be the socket that the system uses
REMOTE_LIRCD_CONF=""
REMOTE_LIRCD_ARGS=""
#Chosen IR Transmitter
TRANSMITTER="None"
TRANSMITTER_MODULES=""
TRANSMITTER_DRIVER=""
TRANSMITTER_DEVICE="/dev/null"
TRANSMITTER_SOCKET=""
TRANSMITTER_LIRCD_CONF=""
TRANSMITTER_LIRCD_ARGS=""
#Disable kernel support.
#Typically, lirc will disable in-kernel support for ir devices in order to
#handle them internally. Set to false to prevent lirc from disabling this
#in-kernel support.
#DISABLE_KERNEL_SUPPORT="true"
#Enable lircd
START_LIRCD="true"
#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD="false"
#Try to load appropriate kernel modules
LOAD_MODULES="true"
# Default configuration files for your hardware if any
LIRCMD_CONF=""
#Forcing noninteractive reconfiguration
#If lirc is to be reconfigured by an external application
#that doesn't have a debconf frontend available, the noninteractive
#frontend can be invoked and set to parse REMOTE and TRANSMITTER
#It will then populate all other variables without any user input
#If you would like to configure lirc via standard methods, be sure
#to leave this set to "false"
FORCE_NONINTERACTIVE_RECONFIGURATION="false"
START_LIRCMD=""
For Debian Jessie (~year 2016):
By default Armbian doesn't have the suxi-cir module enabled at boot-up, but it is available, so you will need to edit hardware.conf to enable this, as well as correct the DRIVER= line and the DEVICE= line, as the defaults in there are WRONG.
Also I suggest commenting out Igor's code in the top five lines. A hardware.conf that works:
# Cubietruck automatic lirc device detection by Igor Pecovnik
#str=$(cat /proc/bus/input/devices | grep "H: Handlers=sysrq rfkill kbd event" | awk '{print $(NF)}')
#sed -i 's/DEVICE="\/dev\/input.*/DEVICE="\/dev\/input\/'$str'"/g' /etc/lirc/hardware.conf
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS=""
#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.
# 'devinput' driver on Orange PI PC causes NO EVENTS TO OCCUR
# via irw for some reason.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="sunxi-cir"
# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
Step 2) Restart lircd service
As lirc is actually already running and installed in Armbian, do the following:
root@orangepipc:/etc# /etc/init.d/lirc stop
root@orangepipc:/etc# /etc/init.d/lirc start
To reboot the service.
Then perform an 'lsmod' to see if it loaded the sunxi_cir module (because otherwise nothing will work):
user@orangepipc:~$ lsmod
Module Size Used by
mali_drm 2732 1
drm 178255 2 mali_drm
mali 123208 0
ump 29379 3 mali
sunxi_cir 1601 0
8189es 1076034 0
Step 3) Find out what '/dev/input/eventX' device is your IR receiver
If you do a:
ls /dev/input/event*
You will most likely get a bunch of possible event devices to choose from, for example:
anonymouspi@orangepipc:~$ ls /dev/input/event*
/dev/input/event0 /dev/input/event2 /dev/input/event4
/dev/input/event1 /dev/input/event3 /dev/input/event5
For my installation, /dev/input/event3 is the IR receiver, but if you have other devices installed (i.e. USB cameras, keyboards etc.) then the number could be different. For example, executing 'evtest /dev/input/event3' reveals:
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "sunxi-ir"
A device name of 'sunxi-ir' means that we are using the right device for the purposes of evtest
Step 4) Do a quick test with with 'evtest' (OrangePI PC armbian seems to use /dev/input/event3 for IR input )
Armbian has the 'evtest' program installed, point the IR remote (in my case a LED colour remote) at your Orange PI PC and as root 'evtest /dev/input/event3'.
root@orangepipc:/etc# evtest /dev/input/event3
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "sunxi-ir"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 152 (KEY_SCREENLOCK)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Key repeat handling:
Repeat type 20 (EV_REP)
Repeat code 0 (REP_DELAY)
Value 500
Repeat code 1 (REP_PERIOD)
Value 125
Properties:
Testing ... (interrupt to exit)
Pressing the remote reveals events like:
Testing ... (interrupt to exit)
Event: time 1472917554.113967, type 4 (EV_MSC), code 4 (MSC_SCAN), value 58
Event: time 1472917554.113981, -------------- EV_SYN ------------
Event: time 1472917554.464390, type 4 (EV_MSC), code 4 (MSC_SCAN), value 59
Event: time 1472917554.464398, -------------- EV_SYN ------------
Event: time 1472917554.842832, type 4 (EV_MSC), code 4 (MSC_SCAN), value 45
Event: time 1472917554.842839, -------------- EV_SYN ------------
Event: time 1472917555.345584, type 4 (EV_MSC), code 4 (MSC_SCAN), value 58
That was the red, green, blue and white buttons being pressed. This is a good news.
Step 5) Configure lirc to map IR input to key presses or events.
Again, Armbian has irrecord installed (great work Igor), but given I'm re-using this remote to configure the output of a LED strip I have, I'll need to map the IR data sent, to something more meaningful. In other use-cases this isn't generally required as lircs provides a database of media remotes which is pre-mapped to Linux commands/keyboard keys.
There's plenty of information on how to use irrecord, command I used was:
/etc/init.d/lirc stop
...to first stop the service, then:
irrecord -H default -d /dev/lirc0 /etc/lirc/lircd.conf
... to record my remote and bind to 'keys'.
Step 6) Test with irw
Now that I recorded my configuration file with irrecord:
/etc/init.d/lirc start
.. to start lird service again
then type 'irw' and check that the key mapping works when I point the remote at the Orange PI PC and press a button:
root@orangepipc:/etc# irw
0000000000ff1ae5 00 KEY_R /etc/lirc/lircd.conf
0000000000ff1ae5 01 KEY_R /etc/lirc/lircd.conf
0000000000ff9a65 00 KEY_G /etc/lirc/lircd.conf
0000000000ff9a65 01 KEY_G /etc/lirc/lircd.conf
0000000000ffa25d 00 KEY_B /etc/lirc/lircd.conf
0000000000ffa25d 01 KEY_B /etc/lirc/lircd.conf
0000000000ff22dd 00 KEY_W /etc/lirc/lircd.conf
0000000000ff22dd 01 KEY_W /etc/lirc/lircd.conf
Hoo Ray!
Step 7) Create a /etc/lirc/lircrc file to run commands
sudo vi /etc/lirc/lircrc
I'd actually call mpv here and call the player:
# http://www.lirc.org/html/configure.html
begin
button = KEY_R
prog = irexec
config = mpv /home/root/Rick\\ Astley\\ -\\ Never\\ Gonna\\ Give\\ You\\ Up.m4a & echo "COMMENT RICK ROLLING" &
end
begin
button = KEY_W
prog = irexec
config = killall mpv & echo "SADFACE!" &
end
begin
button = KEY_B
prog = irexec
config = mpv http://sj256.hnux.com &
end
You could also create a file for each user of the system if you want, eg: /root/.lircrc, /home/userXXX/.lircrc
However if you do this, you will need to start the irexec service manually. If you have a /etc/lirc/lircrc file, the irexec service will start automatically at boot - this service is what actually converts the key press to the command.
So there you go, Rickrolling with a simple press of the red (KEY_R) button :-)
Additional References:
[Guide] Android + InfraRed (IR) + Kodi
How to setup Remote Control for Linux
I am not sure if this is what you want to know, but:
- Debian.org or Ubuntu.com officially does not support any of those boards/boxes,
- Armbian userspace has many small but vital performance or security adjustments,
- Armbian fancy some kernel development and a lot of its maintaining. Debian relies on upstream sources for ARM hardware which can be years behind and/or lack of many functions,
- Armbian userspace is lean, clean but 100% Debian (or Ubuntu) compatible
- many stock Debian bugs are fixed on the way, "better than original :)"
- a build system is a central part of this whole ecosystem. You can DIY. Debian much harder.
- dedicated support forums per boards/boxes
- plug and play vs. complicated install scenarios on Stock Debian
- unified development scenarios and user experience vs. mess of different setup instructions scattered all around