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

This is a schematic for connecting the IR module to our soundcard input

A TSOP1736 IR module also works. The +5V should be as stable as possible to avoid power supply disturbances.

Prepare your 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:
lirc-audio_alsa-AA.zip
Prepared to work 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.

Make it work

Execute the lirc daemon

mkdir /var/run/lirc
lircd --driver=audio_alsa -d plughw@24000

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

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

Tags

Back to top

doc/howto/lirc-audio_alsa.txt · Last modified: 2012/11/08 18:15 by danitool