Cheap IR receiver

Intro

Turning an iMX6 board into a perfect mediacenter certainly requires to be able to interact thanks to an IR remote command.
Some of you may think it is a thing of the past and a nice remote application on a smartphone is the way to go but I may be quite old school as I still think that a plain old remote is very useful.
If your TV and your board support CEC, then your TV remote can be the right candidate. Unfortunately, as I pointed in a previous article, only a few products (utilite being the only one I have successfully tested so far) wire correctly the CEC signal.
If you are unlucky with CEC, a IR receiver may be very welcome. Here again there are no many imx6 boards/products which have such a feature. As far as I know solidrun cuboxi products/boards are the only one.

So when a user, Rene vand den Braken, sent to me a way to add this feature thanks to a very cheap component 2 months ago, I though it is worth sharing this with all of you. (I am ashamed for being so long to write this article).
The wandboard will be used here but the same kind of hack can be done on any imx6 board with VCC/GND and a GPIO available on headers with minor modifications.

At last, it is worth mentioning that the initial driver/idea comes from Aron Robert Szabo and his work on RaspberryPi and that even if this hack works fine at least for Rene and I, you decide to realize it under your own responsibility and we will not be responsible if you damage your board…

Hardware

At hardware level, we use a Vishay TSOP4838. It is a very affordable component : I have been able to order 5 pieces for 2.6$ (shipment included) on ebay.
You can read the whole datasheet but here is what you need to know :
The TSOP has 3 pins :
tsop4838
1 = OUT, 2 = GND, 3 = Vs

For our example, we will connect the TSOP on the JP4 header
pins
And we will connect :

  • TSOP 2 to JP4 pin 19
  • TSOP 3 to JP4 pin 1
  • TSOP 1 to JP4 pin 18

Here is how it looks like on my own wandboard
tsop_wand

Software

Changes are required in the kernel (they will be included in my next image of course).
First the GPIO has to be freed from the generic GPIO framework to be usable for our needs. For now, the used pin is hardcoded and you will have to change this by yourself if you decide to use another GPIO.
Then, a dedicated lirc driver (lirc_wand.c) is required : This driver has been provided by Renรฉ (as a derivative work from Aron lirc_rpi.c driver).
All the required changes are available in this commit

This new kernel driver will behave as a lirc_serial driver and the standard userspace lirc tools will be usable after loading it by :

modprobe lirc_wand

Maybe I can summarize how to start quickly with lirc user tools :

irrecord -n -d /dev/lirc0 myremote.conf

will enable to create a new configuration file for your remote.
You can launch lircd that way :

lircd -d /dev/lirc0 /path/to/myremote.conf

And, at last, you can test the correct behavior by launching

irw

and pressing buttons on your remote
Many LIRC tutorials will give you further details…

Conclusion

That’s it ! Now, you can have fun with your IR remotes.
All this work can easily be adapted for another imx6 board…

20 thoughts on “Cheap IR receiver

  1. Hi stephan

    Thank you very much for share this topic. : )

    You connect Vishay TSOP4838 to GPIO 19,but after checked your patch
    code,nothing change about GPIO 19,
    just like this:
    + //RvdB let lirc use IMX_GPIO_NR(4, 5) “external_gpio_7”

    I am puzzled why need to use IMX_GPIO_NR(4, 5) instand of GPIO 19.

    Can you help me with this . : )

    Thanks

    Kind Regards

    steven

  2. Hi Steve,

    The gpio numbering is a mess ๐Ÿ™‚
    A good explanation can be found at http://android.serverbox.ch/?p=972.

    In the kernel : #define IMX_GPIO_NR(bank, nr) (((bank) – 1) * 32 + (nr))
    so IMX_GPIO_NR(4, 5) == gpio101 (same number as used in /sys/class
    interface.)
    In the wandboard documentation this is external_gpio_7, which they name GPIO_19, do not ask me why ๐Ÿ™

    Greetings Rene

  3. Hi,

    Sorry for the delay of my answer,
    Thanks to Rene for pointing the kernel numbering scheme.
    In fact there is always a convention to number the gpio in, the Linux GPIO framework. ..
    Other numbering is “normal” the GPIO_19 is the real name of the pin as you will find it on wandboard schematics and freescale reference manual. In this RM (p284) you can see that the pin GPIO_19 is called (ALT5 mux conf) : GPIO4_IO05

    I hope this helps…
    Regards
    Stephan

  4. Hi stephan

    Today i success load the LIRC module as you provide. : )
    I can see the debug information

    lirc_wand lirc_matrix.0: lirc_dev: driver lirc_wand registered at minor = 1
    lirc_wand: driver registered!
    lirc_wand: using irq 275
    auto-detected active high receiver on GPIO pin 19,
    The GIPO we are using GPIO 19.

    But when i using
    irrecord -n -d /dev/lirc0 myremote.conf

    to detect IR remote input , It can not detect anythings, We can success detect the wave in GPIO 19.

    We have tested NEC32 and RC6 remote both can not.

    Can you give us some ideal about this?

    Thank you very much.

    Regards

    steven

    • Hi steven

      Which version of lirc usertools do you use ?
      I will post you the ones I have used to perform my tests tomorrow…
      Regards

      • Hi stephan

        All is ok now, I missed the init GPIO pin to imx6q, : )

        After add
        _MX6Q_PAD_SD1_DAT2__GPIO_1_19
        to imx6q all is ok now.

        Thanks again for your help. : )

        Regards

        steven

        • Yes !
          It is worthy to mention it : The IOMUX has also to be properly configured…
          Thanks for the update…
          Stephan

  5. Hmm registered at minor=1, doesn’t that mean you need dev/lirc1 ?
    (lirc_matrix.0 is that another lirc device ?)

    Greetings rene

  6. Hi Rene

    Here have three lirc in dev

    ls /dev/lirc
    lirc lirc0 lirc1

    just have tried lirc1 , and lirc
    irrecord -n -d /dev/lirc1 myremote.conf
    irrecord -n -d /dev/lirc myremote.conf
    It is the same nothing happen when i press the remote bottom .

    Thanks

    Kind Regards

    steven

  7. Hi stephan&Rene

    Now all is ok now, I missed the init GPIO pin to imx6q, : )

    After add
    _MX6Q_PAD_SD1_DAT2__GPIO_1_19
    to imx6q all is ok now.

    Thanks again for your help. : )

    Regards

    steven

  8. Pingback: First look at Matrix TBS2910 | Stephan's blog

  9. Pingback: Yet another yocto image | Stephan's blog

  10. Hi, I have udoo board, I also want to have this ir receiver on my board.
    so I ported it to udoo – it is the same code like yours I just changed name and pin nr. I recompiled yours kernel src with this driver. I also use your image for udoo. driver is loaded correctly. but when I am trying to use irrecord I see:
    irrecord: usb_irtoy: could not reset tty
    irrecord: WARNING: invalid lockfile (/var/lock/browse.dat) detected
    irrecord: WARNING: invalid lockfile (/var/lock/gencache_notrans.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/gencache.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/printer_list.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/serverid.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/notify_onelevel.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/notify.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/locking.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/brlock.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/connections.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/sessionid.tdb) detected
    irrecord: WARNING: invalid lockfile (/var/lock/messages.tdb) detected
    irrecord: could not init hardware (lircd running ? –> close it, check permissions)
    and then I listed
    irrecord -H dumy
    Driver `dumy’ not supported.
    Supported drivers:
    usb_irtoy
    I checked on web and packages for udoo and for wandboard are diffirent.
    I suppose that wanboards rpm contain proper drivers?
    Could you prowide the same lirc package for udoo or can you suggest me what is wrong with my lirc?

  11. Hi Stephen,

    first of all, thank you very much for all your hard work to put those images together. You’ve done an incredible job.

    My setup is a Wandboard quad. I have been able to go all the way to issue an “irw” command with success. The lircd is running and gets well any key that I send from my Apple TV2 remote. So far so good. The problem is that XBMC does not seem to get any command from the remote and after several hours of testing I am totally desperate. I have tried many config files for XBMC and lirc with no success.

    It be great if you could give me a hand and head me to the right direction, namely where do I start to debug this problem.

    best regards,
    Pepe

  12. Pingback: Make IR working on the wandboard | JB's DEV STORY

  13. Hi, I appreciate this is an old post, but I am a recent wanda-user,
    I would like to try this component but I dont use linux, I use RISC OS. Any chance you could give me a link to the driver source where the data is sampled and decoded please. Thanks, Matt

Leave a Reply

Your email address will not be published. Required fields are marked *