Project: Analyze Infrared Remote Signals with PiFace Control and Display

As part of being selected for the element14 RoadTest of the XBMC kit, I was also provided a PiFace Control and Display for some reviewing. As you can appreciate, it’s been very much busy on my end, and my inability to walk has cost me plenty when it comes to getting things done. While sitting in my chair today, I got bored with whatever else I was doing, so I stopped and decided to set up a secondary Raspberry Pi (as the original one is used for media centre duties) to see just how easy it is to get the PiFace Control and Display up and running, and start analyzing infrared remote codes with it.

Hardware and Software Installation

PiFace Control and Display PCB Physical installation of the board is without difficulty – it merely plugs into the GPIO header and props itself up on the Ethernet connector. A thoughtful cut-out is provided to allow for the camera flexible cable to pass through if you wish to use one. Software installation is also a breeze. On the latest edition of Raspbian, under raspi-config in advanced, you can already enable the SPI bus thus making the installation of PiFace products easier. Then one merely has to follow the instructions here to get it up and running. Note that after running the apt-get install line, you will need to reboot your Raspberry Pi before you can use the sysinfo test. You should be greeted with something nice, like this: PiFace Control and Display Sysinfo Demo Reading through the sysinfo.py code, it looks quite simple but introduces you to a fair amount of functionality. If you’ve gotten this far, great – you’re ready to roll. If the LCD lights up but no text shows, you may need to adjust the contrast potentiometer which is just above the solder points of the screen. If you would like, you should continue with the examples in the documentation to teach yourself how best to use the supplied functions. They’re very handy for making easy menus and inputs with the rocker switch, thus obviating the need for a keyboard and mouse.

Configuring LIRC for Infrared

By default, following the above instructions will not install and configure the remote receiver. You must follow these instructions to start getting it working. Note that you may also want to change /etc/lirc/hardware.conf after installing to comment out LIRCD_ARG=”–uninput” if you don’t want your infrared button presses to be treated like a keyboard input. To test the IR receiver, just grab any unused 36/38khz remote control and point it at the receiver. Execute mode2 -d /dev/lirc0 and hopefully you will see lots of scrolling pulse/space lines as follows. mode2test If so, you’re all good and your remote is good too. If not, check the batteries in your remote, try another remote (in case it’s got the wrong carrier frequency) and ensure that the IR receiver is firmly plugged into its socket.

Training Up Your Remote

Before you can use your remote, you will need to “teach” lirc how to recognize its signals. This can be achieved through the irrecord -f -d /dev/lirc0 /etc/lirc/lircd.conf command. This will ask you to push a few buttons to determine the signal format, and then start typing in names from irrecord –list-namespace and push the appropriate button to generate a raw configuration.

irrecord

This can be sufficient to use irw to check your remote and play with irexec examples on the PiFace Control and Display documentation.

Analyzing Remote Signals

Note that if you type irrecord –help, you can find a full list of options. One good option is the –analyze option which allows for irrecord to “convert” raw recordings to an interpreted form. Another good option is the one which allows for you to pick button names outside the namespace list, although this may mean that those buttons cannot be mapped by some end-user applications depending on how they use lirc. This board is actually a good board for analyzing 36/38kHz IR signals because the IR receiver is plugged into the GPIO. This allows it to have a good timing resolution which ensures that the signals can be captured more reliably. Skinny Remote For this little experiment where I analyze infrared remote signals, I’ve got three low-quality almost pointless remotes which are supplied with various TV tuners I have purchased over the years. They’re weak (in terms of IR emission), limited in function (in terms of buttons), screwy with compatibility (depending on software) and I’ve generally found them more useful for stealing an IR LED and coin-cell battery than actually being a remote. But it would still be nice to see what happens when I use irrecord on them … the raw and analyzed configuration files are below:

Information contained within these configuration files are in plain text, and a fairly good understanding of the data can be had if you read this WinLIRC reference.

The Meaning of the .conf Files

In order to examine the meaning of the .conf files, lets consider snipped versions of the raw versions of just one remote.

begin remote

  name  /home/pi/remote1.conf
  flags RAW_CODES|CONST_LENGTH
  eps            30
  aeps          100

  gap          108196

      begin raw_codes

          name KEY_POWER
             9084    4445     579     554     605     504
              629     509     576     558     605     505
              629     506     575     562     636     475
              628    1643     604    1646     570    1669
              630    1643     604    1641     573    1672
              664     477     589    1656     649     490
              570     562     631     479     635     498
              572     567     611     498     635     501
              581     554     611    1634     582    1664
              636    1638     610    1634     579    1667
              632    1641     607    1639     577    1672
              628
[...]

Notice how the raw codes mode is just an array of numbers? These numbers represent the number of microseconds at alternating mark, space, mark, space conditions. Lets take a look at a snip of the analyzed output for all three remotes. Remote 1

begin remote

  name  /home/pi/remote1.conf
  bits           32
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       9055  4465
  one           608  1644
  zero          608   520
  ptrail        600
  gap          108196
  toggle_bit_mask 0x0

      begin codes
          KEY_POWER                0x00FD00FF
[...]

Remote 2

begin remote

  name  /home/pi/remote2.conf
  bits           32
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       9131  4468
  one           607  1649
  zero          607   519
  ptrail        609
  gap          108693
  toggle_bit_mask 0x0

      begin codes
          KEY_POWER                0x01FE48B7
[...]

Remote 3

begin remote

  name  /home/pi/remote3.conf
  bits           32
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       9082  4484
  one           616  1643
  zero          616   515
  ptrail        615
  gap          108584
  toggle_bit_mask 0x0

      begin codes
          KEY_POWER                0x00FFB24D
[...]

It’s clear that all three remotes are very similar. They have similar mark/space times and preamble pulse times (these will vary due to temperature, battery condition, ceramic oscillator reference used in constructing the remote). They also have the same number of bits – 32. Notice how the whole code is condensed – instead of an array of times, a generalization of what times make a zero and a one is made, and the stream is decomposed into a header, trailer and code data encoded in space-encoding with constant-length signal. You will see what this means graphically later. PinOutTo verify it with the actual signals, we will have to capture the signal from the IR receiver itself. By probing, the pin-out of the receiver on the PiFace Control and Display was determined. The data and ground were connected to the PoScope 2 Basic (a USB based low-rate oscilloscope which I have endless hate for because of bugs – I cannot recommend it to anybody due to its limitations) as the capture device. This allows us to gain a trace which represents the decoded waveform of the remote button code. The button I chose to analyze to verify the analyzed .conf file was KEY_POWER from Remote 3. The actual scope capture of the signal is as follows – notice inverted logic which is common with such receivers. remote3-power Lets just say, I put in the extra effort, and here you can see the meaning behind the terms in the .conf file. With the analyzed representation, it can be quite easy to write code for a microcontroller to regenerate these signals (click for larger). Cool! remote3-power-annotated

Conclusion

Playing with lirc and the PiFace Control and Display proved to be a lot simpler than I envisioned in getting set-up for training and analyzing remote controls. Within an hour, I went from setting up Raspbian to completely having trained three remote controls for use with the Raspberry Pi and having applications/commands launched on remote command. I was also able to follow the tutorials to write messages to the LCD. It really isn’t that difficult, even for a complete newbie to Python (as long as you have experience with something else, e.g. C, Arduino). I’m actually quite happy about the product itself, although without an output or an IR emitter, I feel that some opportunity had been missed.

Postamble

Well, I’ve been on a bit of a roll lately when it comes to posting, but rest assured, this won’t necessarily be the case coming up. Because of increasing workload, and the dramas with my ankle, it looks like I won’t have too much time to blog … lets see what happens!

About lui_gough

I'm a bit of a nut for electronics, computing, photography, radio, satellite and other technical hobbies. Click for more about me!
This entry was posted in Computing, Electronics, Raspberry Pi and tagged , , , , , . Bookmark the permalink.

Error: Comment is Missing!