LIRC audio_alsa
LIRC is a package that allows you to decode and send infra-red signals of many (but not all) commonly used remote controls.
Be aware you'll need a sound card with microphone input. A cheap usb sound card can do the job.
The audio_alsa module lets you to use a soundcard input to receive infrarred signals. The basic idea is that the output of the IR module (somewhere in the range from 0 to ~3-4V) can be limited by using the attenuator built into every audio-card (also known as “mixer sliders”).
Prepare your hardware
These are some schematics for connecting the IR module to our soundcard input
- Using a diode, see http://www.lirc.org/ir-audio.html
Tested with a small signal switching diode BAV20PH, but other diodes (not all) should also work.
One drawback for keeping it simple is the power supply. We can just modify our USB audiostick isolating one minijack contact and bridging it to the +5V usb power supply.
The circuit then can be wired with a minijack cable. We need a little case for the circuit with the IR module receiver, an ADSL microfilter case is perfect for this purpose (you have for sure tons of them from ISPs).
Prepare your software
To use the audio_alsa module you'll need to build Openwrt with the package lirc and alsamixer. Install both before building your own firmware.
./scripts/feeds update -a ./scripts/feeds install lirc alsa-utils
The lirc package is not built as default with audio_alsa, and it seems partially broken. As a result of this you must modify the Makefile for lirc. Or just download this fixed one:
Mirror: lirc-audio_alsa-for-openwrt
Tested with OpenWrt Attitude Adjustment, but it may also work with Backfire. Replace the lirc directory under feeds with this new one.
As usually build your custom firmware but select alsa-utils, lirc:
Location: -> Utilities
┌─────────────────────────────────── Utilities ───────────────────────────────────┐ │ ┌─────────────────────────────────────────────────────────────────────────────┐ │ │ │ Boot Loaders ---> │ │ │ │ Editors ---> │ │ │ │ Filesystem ---> │ │ │ │ Terminal ---> │ │ │ │ disc ---> │ │ │ │ <*> alsa-utils............ ALSA (Advanced Linux Sound Architecture) utilitie│ │ │ │ < > alsa-utils-seq.................................. ALSA sequencer utilitie│ │ │ │ < > alsa-utils-tests.......... ALSA utilities test data (adds ~1.3M to image│ │ │ │ < > bzip2.................................... bzip2 is a compression utility│ │ │ │ < > cal................................................... display a calenda│ │ │ │ < > comgt............................... Option/Vodafone 3G/GPRS control too│ │ │ │ < > dmesg............................ print or control the kernel ring buffe│ │ │ │ < > dropbearconvert.......................... Utility for converting SSH key│ │ │ │ < > fconfig..................................... RedBoot configuration edito│ │ │ │ < > flock.................................... manage locks from shell script│ │ │ │ < > gdb......................................................... GNU Debugge│ │ │ │ < > gdbserver................................. Remote server for GNU Debugge│ │ │ │ < > getopt.................................. parse command options (enhanced│ │ │ │ < > gpioctl................................... Tool for controlling gpio pin│ │ │ │ < > hwclock.................................. query or set the hardware cloc│ │ │ │ < > iconv................................... Character set conversion utilit│ │ │ │ < > iwcap.................................... Simple radiotap capture utilit│ │ │ │ < > iwinfo.......................... Generalized Wireless Information utilit│ │ │ │ --- jshn................................................. JSON SHell Notatio│ │ │ │ < > kexec-tools.......................................... Kernel boots kerne│ │ │ │ < > ldconfig............................... Shared library path configuratio│ │ │ │ < > ldd.................................................... LDD trace utilit│ │ │ │ <*> lirc................................ LIRC - Linux Infrared Remote Contro│ │ │ │ < > logger......... a shell command interface to the syslog system log modul│ │ │ │ < > look......................... display lines beginning with a given strin│ │ │ └─v(+)────────────────────────────────────────────────────────────────────────┘ │ ├─────────────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └─────────────────────────────────────────────────────────────────────────────────┘
and lirc utitilities:
Location: -> Utilities -> lirc
┌─────────── lirc............. LIRC - Linux Infrared Remote Control ────────────┐ │ ┌───────────────────────────────────────────────────────────────────────────┐ │ │ │ --- lirc.................. LIRC - Linux Infrared Remote Control │ │ │ │ <*> lircdaemonadd...................... Daemon Additional Files │ │ │ │ <*> lirctools....................................... LIRC tools │ │ │ │ │ │ │ └───────────────────────────────────────────────────────────────────────────┘ │ ├───────────────────────────────────────────────────────────────────────────────┤ │ <Select> < Exit > < Help > │ └───────────────────────────────────────────────────────────────────────────────┘
Build openwrt, and flash your custom firmware. Now you have lirc prepared to work.
Note the file /etc/lircd.conf is specific for your remote. You'll may need to use irrecord to get one for your own remote if you don't find any in the lirc database. |
Build with a transmitter
You may want to use the LIRC GPIO blaster kernel module together with audio_alsa receiver. We can use two lirc instances connected via TCP/IP or rather to patch lirc for having only one daemon running, this way it's more compact and saves some bytes. Link with the LIRC package and the patch, and also the lirc_gpioblaster module
LIRC audio_alsa patched to work with lirc_gpioblaster kernel module
lirc_0.9.0-audio_alsa-plus_gpioblaster.zip
(Tested under Openwrt Attitude Adjustment)
Make it work
Execute the lirc daemon
mkdir /var/run/lirc lircd --driver=audio_alsa -d plughw@24000
LIRC sometimes is affected by an alsa bug, see → alsa_bug
Now execute irw, to test your remote, the codes are shown when you press any button.
root@OpenWrt:/# irw 00000000000005e9 00 + rct3004 00000000000005ea 00 - rct3004 00000000000005ea 01 - rct3004 00000000000005dd 00 power rct3004 00000000000005d0 00 3 rct3004 00000000000005d0 01 3 rct3004 00000000000005c9 00 5 rct3004 00000000000005c9 01 5 rct3004 00000000000005c1 00 4 rct3004 00000000000005c1 01 4 rct3004
If nothing is shown you may need to calibrate the infrared receiver with alsamixer:
┌───────── AlsaMixer v1.0.24.2 ─────────┐ │ Card: Generic USB Audio Device │ │ Chip: USB Mixer │ │ View: Playback │ │ Item: Speaker [dB gain: -0.06, -0.06] │ │ ┌──┐ ┌──┐ │ │ │▒▒│ │ │ │ │ │▒▒│ │ │ │ │ │▒▒│ │ │ │ │ │▒▒│ │ │ │ │ │▒▒│ │ │ │ │ │▒▒│ │▒▒│ │ │ │▒▒│ │▒▒│ │ │ │▒▒│ │▒▒│ │ │ │▒▒│ │▒▒│ │ │ │▒▒│ │▒▒│ │ │ ├──┤ ├──┤ ┌──┐ │ │ │OO│ │MM│ │OO│ │ │ └──┘ └──┘ └──┘ │ │ 100<>100 52 │ │ < Speaker > Mic Auto Gain C │ └───────────────────────────────────────┘
Sometimes is better to use Auto Gain other times not (m key to disable/enable). So play with it together with the next control:
Press F4 to enter the Capture control.
┌───────── AlsaMixer v1.0.24.2 ─────────┐ │ Card: Generic USB Audio Device │ │ Chip: USB Mixer │ │ View: Capture │ │ Item: Mic [dB gain: 14.88] │ │ │ │ ┌──┐ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │▒▒│ │ │ │▒▒│ │ │ │▒▒│ │ │ │▒▒│ │ │ │▒▒│ │ │ │▒▒│ │ │ L└──┘R │ │ CAPTURE │ │ 62 │ │ < Mic > │ └───────────────────────────────────────┘
Now play with the gain (arrow up/down) until your remote shows its codes with irw. Once calibrated press Esc key to exit alsamixer.
irexec
Ok nothing new here, just configure lircrc as described in the LIRC website. The file /etc/wifiradio/lircrc is an example. Run the irexec daemon with a command like this:
irexec --daemon /etc/wifiradio/lircrc
Now everytime you press a button in your remote, irexec will execute the associated commands in the lircrc file.
You can put the commands to calibrate alsamixer and execute commands in /etc/rc.local, to autostart lircd and irexec once you got it working.
mkdir /var/run/lirc amixer -q set Mic capture 62% lircd --driver=audio_alsa -d plughw@24000 irexec --daemon /etc/wifiradio/lircrc
alsa bug
Sometimes lirc is unable to open correctly the recording device. The cause is still unknown. But fortunatelly when opening several times the alsa recording device we can see it fails with a defined pattern.
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test01.wav ← good
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test02.wav ← bad
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test03.wav ← bad
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test04.wav ← bad
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test05.wav ← good
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test06.wav ← bad
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test07.wav ← bad
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test08.wav ← bad
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test09.wav ← good
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test10.wav ← bad
arecord -q -d 1 -r44100 -f S16_LE -c1 -t wav test11.wav ← bad
......
This happens in bcm63xx, the pattern is 3 good recordings, 1 bad. In bcm47xx the pattern is 1 good recording, 1 bad recording.
Considering this known predictable bug, we can solve the problem with an ugly workaround: make dummy recordings before running lirc.
Put this command before the line that executes the lirc daemon
/usr/bin/arecord -q -d 1 -r48000 -f S16_LE -c1 -t raw > /dev/null
You may need to put 1, 2 or 3 lines depending on the state of the recording device. Just test it adding more lines with a router reboot in every added recording line until lirc starts working ok.
Notes
Successfully tested with a Livebox 1 router under Backfire, using a CSOUNDU Conceptronic usb audio card, and TSOP1736 --- danitool 2012/11/04 15:02