19 January, 2014

Raspberry Pi and IR remote control with LIRC

I have been planing for a while to add an IR remote control to my RPi and the day came with the discovery of a IR set with remote control sold by Kjell&Company for a symbolic price.

First step first. I have added the receiver part since it does not require soldering at all. I have followed this manual to set and test LIRC on RPi with one exception - I use GPIO 18 as input from the IR detector. The set does not include any manual, so some research was necessary. The example code is for Arduino without any references to the specific hardware. Anyway, here I found the most relevant information. One can find example lircd.conf for some similar remotes but they did not work with the one in the package with label KEYES and distinct key pattern.


Setting up LIRC was nearly breeze. I managed to install the TV-box lircd.conf almost without problems but I kept failing to create a proper configuration for the KEYES IR control. After some struggle I managed to assemble something that fits quite well with what works with Arduino, so here it is. It might not be perfect but it is better start than nothing. If you find better parameterization, please let me know in the comment section.

# Please make this file available to others
# by sending it to
#
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Sun Jan 19 10:13:19 2014
#
# contributed by
#
# brand:                      KEYES
# model no. of remote control:
# devices being controlled by this remote:
#


begin remote

  name  KEYES
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       9281  4484
  one           622  1657
  zero          622   513
  ptrail        622
  repeat       9241  2236
  pre_data_bits   16
  pre_data       0xFF
  gap          109259
  toggle_bit_mask 0x0

      begin codes
          KEY_UP                   0x629D
          KEY_DOWN                 0xA857
          KEY_LEFT                 0x22DD
          KEY_RIGHT                0xC23D
          KEY_OK                   0x02FD
          KEY_1                    0x6897
          KEY_2                    0x9867
          KEY_3                    0xB04F
          KEY_4                    0x30CF
          KEY_5                    0x18E7
          KEY_6                    0x7A85
          KEY_7                    0x10EF
          KEY_8                    0x38C7
          KEY_9                    0x5AA5
          KEY_0                    0x4AB5
          KEY_NUMERIC_STAR         0x42BD
          KEY_NUMERIC_POUND        0x52AD
      end codes

end remote
Now, the receiver is vs1838b and here again you can find the pins. Be careful, the GND and VCC pins are flipped on the connectors and here is a sketch what I have identified. There is also a small LED that blinks when signal is detected.
 


While we are on the subject, here is one more remote (iZound FM-sändare FMT-950 or 1.8" LCD Car MP4 Player ) and the corresponding lircd.conf:

begin remote

  name  car_mp4_player
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       9022  4421
  one           610  1621
  zero          610   505
  ptrail        602
  repeat       8992  2194
  pre_data_bits   16
  pre_data       0xFD
  gap          107225
  toggle_bit_mask 0x0

      begin codes
          KEY_1                    0x08F7
          KEY_2                    0x8877
          KEY_3                    0x48B7
          KEY_4                    0x28D7
          KEY_5                    0xA857
          KEY_6                    0x6897
          KEY_7                    0x18E7
          KEY_8                    0x9867
          KEY_9                    0x58A7
          KEY_0                    0x30CF
          KEY_POWER                0x00FF
          KEY_MENU                 0x807F
          KEY_PLAYPAUSE            0x40BF
          KEY_MEDIA_REPEAT         0x20DF
          KEY_CHANNELDOWN          0xA05F
          KEY_CHANNELUP            0x609F
          KEY_VOLUMEDOWN           0x906F
          KEY_VOLUMEUP             0x50AF
          KEY_PREVIOUS             0xB04F
          KEY_NEXT                 0x708F
          BTN_EXTRA                0x10EF
      end codes

end remote



16 comments:

SvenM said...

Very nice. I got the same kit from Kjell for my Pi last week, and had almost given up on using the included remote control because I couldn't seem to get a reliable configuration with irrecord. Every other remote control I had seemed to work much better. I found this page after googling for "KEYES lircd.conf" or something like that. Your file works much better than any I'd managed to come up with (often being forced into irrecord in raw mode), so thanks!

Uncle Scrooge said...

After so much struggle with it, I am glad that it is appreciated. Cheers!

mh said...

You saved my day

Dan G said...

Thanks a ton mate! This got me up and running with my keyes remote. Saved me a bunch of time. Appreciate it!

Anonymous said...

Thanks for the lirc.conf, made my day.

Luipez said...

Ho un IR KEYES su PI con XBMC che ho configurato con la tua guida.
Ho un problema perchè funzionano solo i tasti Up, Down, Left, Right, mentre gli altri non sembrano funzionare.

Mi puoi aiutare?
---------------------------------------------------------------------------------
I have an IR KEYES of PI with XBMC I've configured your guide.
I have a problem because they only work the Up, Down, Left, Right, while others do not seem to work.

You can help me

Luipez said...

Funzionano anche i tasti numerici.
Non funzionano i tasti OK, # e *.

1) alla pressione di un tasto e come se venisse premuto 2 volte. Si puo risolvere?
2) il tasto OK può diventare il tasto ENTER? Se è si, come?
-----------------------------------------------------------------------------------


They also work the number keys.
Do not work the buttons OK, #, and *.

1) by pressing a button and as if it came down 2 times. You can solve?
2) OK button can become the ENTER key? If it is so, how?

Uncle Scrooge said...

First try to check if your Lirc is working correct.

Verify the results using irw(1). Pressing buttons should give something like:

$ irw
000000037ff07bef 00 KEY_VOLUMEUP KEYES
000000037ff07bef 01 KEY_VOLUMEUP KEYES
000000037ff07bdd 00 KEY_ENTER KEYES
000000037ff07bdd 02 KEY_ENTER KEYES

If this is correct, then something in the XBMC configuration needs to be changed to map the correct buttons. If the first test is wrong, then the config file is not appropriate for the remote control you are using.

They are rather generic, so I will not be surprised if the IR remote you have uses different protocols in which case you should go through the painful procedure of training your lirc configuration.

Luipez said...

Problema 2) risolto.

Nel file lircd.conf ho cambiato il nome da KEY_OK a KEY_ENTER e ora esso ha la funzionalità del tasto ENTER.

Vorrei sapere se è possibile risolvere il problema 1).
----------------------------------------------------------------------------------
Problem 2) solved.

File lircd.conf I changed the name from KEY_OK to KEY_ENTER and now it has the functionality of the ENTER key.

Let me know if you can solve the problem 1).

Uncle Scrooge said...

Look here: https://www.youtube.com/watch?v=ENCXM16NGE4

Luipez said...

Nel file lircd.conf ho cambiato il nome da KEY_NUMERIC_STAR a KEY_ESC e ora esso ha la funzionalità del tasto ESC.

Vorrei sapere il nome del KEY_....... per poter tornare alla pagina iniziale di XBMC, se esso esiste.
------------------------------------------------------------------------------------
File lircd.conf I changed the name from KEY_NUMERIC_STAR to KEY_ESC and now it has the functionality of the ESC key.

I would like to know the name of the KEY _....... to return to the start page of XBMC, if it exists.

Luipez said...

Problema 1) risolto.
--------------------
Problem 1) solved.

Luipez said...

Vorrei sapere il nome del KEY_....... per poter tornare alla pagina iniziale di XBMC, se esso esiste.
------------------------------------------------------------------------------------
I would like to know the name of the KEY _....... to return to the start page of XBMC, if it exists.

Uncle Scrooge said...

I do not use XBMC but I just Google your question "I would like to know the name of the KEY _....... to return to the start page of XBMC" and seems that the first 10 hits will give you the answer.

Unknown said...

hello I made a rx and tx circuit with TSOP4838 and LED IR , could you tell me how I can make a python program that enable a key on/off with a script? Thank you very much...help

Uncle Scrooge said...

I have not tried it myself, but this link seems to have all the information that you might need https://pypi.python.org/pypi/python-lirc/1.2.1