Professional Documents
Culture Documents
articles
Q&A
forums
Sign in
lounge
CPOL
Rate this:
This article describes the development of C# code that allows you to send consumer IR codes from your mobile device using the audio port.
Download PocketBeamer PocketPC binaries - 9.66 KB
Download PocketBeamer source - 15.2 KB
Introduction
One of the most exciting aspects of a mobile device is its ability to let you to interact with your surroundings. This article takes a look at a method of
controlling consumer appliances (stereo, DVD player, VCR, television, hobby robots, etc...) using their built-in infrared (IR) receivers. There are several good
applications available that allow you to send/receive IR signals from your Pocket PC, but they all suffer from the same problem: the IRDA port on most models
is too weak to produce a consumer IR signal that can go further than 8 feet. The clever developers at Griffin Technology came up with a nifty device that
plugs into your mobile PC's audio port and can send much stronger signals. My hat is off to their developers for coming up with this idea, as it is truly
inventive. This article will explore how they can accomplish the feat of sending of consumer IR signals using, well, ... sound, and how you can use it in your own
applications.
Note: This is NOT a paid advertisement, and I have absolutely no relationship with the Griffin Technology people. Rather, when this device first came, I
contacted Griffin about getting access to an SDK so that I could incorporate the sending of IR codes in my own applications. I was very disappointed with the
one-line response I received and the attitude towards consumers in their postings on other web forums. So I decided to work work this puzzle out for myself.
Hey, how hard could it be? Famous last words.
converted by W eb2PDFConvert.com
Now, behind the scenes, your television remote is doing a little extra work than is outlined above. Yes, it sends a series of ON and OFF pulses and their
sequence determines the specific command it is trying to send (power on, power off, change channel, etc...). But these ON and OFF pulses are really made up
of a wave of IR light at a given carrier frequency. All this means is that the long pulse of ON is comprised of many little ON/OFF flickering of IR light. The IR
light goes on-off-on-off-on-off... for a duration of the total ON time. Each little on-off duration is at the carrier frequency.
This carrier frequency serves several purposes including power savings and the better handling of "noise". (Note: even though IR signals are at a higher
wavelength than visible light, they are still subject to the introduction of noise produced by visible light and other radiating sources). The carrier frequency
varies from remote-to-remote and brand-to-brand. Normally, consumer IR remotes operate in the 36KHz (that's 36,000 cycles per second) to 40Khz range.
Remember this range, as it is very important later on. An example of a wave using a carrier frequency can be seen below:
converted by W eb2PDFConvert.com
The fourth word (0x000D = 13 decimal) is the "repeat count" and indicates that there are also 13 signal bursts in the "repeat" signal. The "repeat" signal is the
signal that is sent if you hold a key down (say, the volume key) on your remote control. If you hold a key, the "once" signal is sent followed by as many
repetitions of the "repeat" signal as possible (while you are holding the remote control key down). When you let go off the key, the remote stops sending. So
again using the color coding, you can see that the purple signal is the repeat signal. If the value of this word is 0x0000, it means there is no "repeat" code and
the key doesn't repeat.
That's it! An extremely brief overview of a summarized version of a condensed beginner's guide to the workings of consumer IR codes. Now go grab yourself
that coffee and let's get on with the meat of the article.
2. How can we get enough power from the audio port to drive the IR signal further than a few feet?
OK, so we figured out how it was theoretically possible to send a 40Khz signal through the IR port, but that would be useless unless we can send it a
reasonable distance. After all, what good is a remote control that you have to get yourself out of your chair to use! I did some web searches and I found that
audio ports on PDAs are not really known for being very powerful. So I wondered how much power the Total Remote software was generating from the audio
port. There was only one way to conclusively find out: bring out the oscilloscope!
I plugged in my handy dandy USB oscilloscope, ran the Total Remote software, pressed a key to send a signal, and recorded the output. What I saw baffled
me at first. Here is a screenshot of the beginning of the signal:
converted by W eb2PDFConvert.com
Yes, I pretty much had the same reaction as you, looking at the beginning of the signal. What the heck is that? With a little more observation, I calculated that
when I pressed a remote control key (in the software), the signal that was generated started with this "preamble" of a 500Hz wave on both channels that was
out-of-phase. After this preamble, I could see what I expected: periods of on/off signal bursts that represented the IR code. This looked like:
So, I was curious. What is the purpose of the preamble? The answer appears to be that in order to boost the power from the audio port to send the IR signal
a reasonable distance, we need to "charge up" the total remote. My guess (because I never really pulled out the hammer and opened the hardware) is that
inside there is a little capacitor tuned to this preamble signal. The preamble charges up the capacitor and this power is subsequently released when the rest of
the IR signal is sent. This power boost enables the IR signal to travel further. Again, this is just a guess. Whether I am right or wrong is immaterial as long as I
can reproduce the same preamble.
PCMWaveGen
converted by W eb2PDFConvert.com
This class encapsulates the writing of a WAV file. If you look at the source code, you will see it basically consists of a list of properties and several Write
methods. All of the properties map to properties in the the WAV file format. The basic WAV file consists of headers followed by sample data. The sample data
is really data at-a-point-in-time, or a "sampling" of the output stream. The headers just describe what kind of sample data to expect. An overview of the file
format layout looks something like:
Hide Co p y Co de
This PCMWaveGen object is really not that interesting by itself, but the two methods to note are the WriteHeader and WriteFormat methods. At the very
beginning of a WAV file, there is a "RIFF" header. As you can see, it is very simple.
Hide Co p y Co de
The real meat-and-potatoes of the information is in the Format section. As you can see, it consists of the audio format, number of channels, bit rate, etc...
Hide Co p y Co de
ProntoCCF
This simple class takes the string representation of a Pronto CCF formatted IR code and translates it into signal arrays. The signal arrays are burst pairs just
like we discussed at the top of this article. Instead of creating yet another arbitrary format, I figured it would be easier in the long run to write a simple class
that parses out the Pronto codes. To use this class, you only need to pass the raw IR code string to its FromString() method. All of the processing is done
for you.
If you are looking for IR codes to use with your own devices, I would suggest RemoteCentral.com. They have a great database of different brands of remote
control codes that you can use. One thing to note: although a lot of times it is easy to grab an IR code from the web and have it work, they can sometimes be
very temperamental. If you have a method of learning your own IR codes, this is much more reliable than using someone's code that might not work for you
(for whatever reason). I only mention this because in the past, I have lost hours of work thinking there was an error in my code, when in reality, a simple
change of the IR code was the answer.
IRWav
This is the real workhorse class, as it encapsulates the generation of a WAV file from an IR code. To begin using this class, you only need to do the following:
Hide Co p y Co de
using DForge.IR.Formats;
using DForge.IR.TotalRemote;
ProntoCCF irCommand = new
ProntoCCF("0000 006D 001A 0000 ...rest of ir code here...");
IRWav totalRemote = new IRWav();
if(!totalRemote.SendSignal(irCommand,true))
MessageBox.Show("Failed to send the signal");
When designing this class, I wanted to make it as efficient as possible. You see, creating WAV files on the fly is no easy task for a little 'ole PDA. Sure, it can
handle it, but you really don't want the user waiting for 5 seconds every time you send an IR signal. To eliminate this waiting, I decided to cache the IR signals
so that they only get generated once. They are cached by using a unique ID (GUID) that is associated with every IR command. So when you see methods that
take a Guid idCommand parameter, this is the reason. When you send a command and it doesn't find the ID in the cache, it will generate the signal and
cache it for later use. The next time you send the signal, it looks up the ID form the cache and sends the pre-generated signal. If you want to just send a
temporary signal (like in the above example), either leave off the ID or send Guid.Empty in its place. If you do this, the code will generate the IR WAV file
every time (and you won't gain the benefits of caching).
One thing to note: if you change the actual IR code, you must clear the cache before sending the new code. Otherwise, it will look in the cache and pull up the
old pre-generated version and send that instead. As you can see, I provide two methods of clearing the cache. The first clears the entire cache, and the second
clears the pre-generated signal for a given command.
Hide Co p y Co de
converted by W eb2PDFConvert.com
/// <summary>
/// Clears the cached signal directory
/// </summary>
public void ClearCache()
{
if(Directory.Exists(this.CacheDirectory))
Directory.Delete(this.CacheDirectory,true);
Directory.CreateDirectory(this.CacheDirectory);
}
/// <summary>
/// Clears the cached signal for the given command
/// </summary>
public void ClearCache(Guid idCommand)
{
string strFilename = CacheDirectory + idCommand.ToString();
if(File.Exists(strFilename))
File.Delete(strFilename);
}
When you send a signal using IRWave, you will see several things going on. First, you will notice that we turn up the volume on the audio port to its
maximum level. This is the equivalent of us saying we want to send the IR signal with maximum power. Remember in the earlier sections, how we discovered
that preamble signal and how it is used to boost the power? Well, if we don't push the audio port's volume to maximum power before we send the signals,
the preamble would be for nothing. So we save the current audio volume level and put it up to 100% power for maximum range. Next, we check the cache to
see if the signal has already been created. If it is in the cache, we use it. Otherwise, we take the hit and generate the WAV file from the IR command. Finally,
we put the volume back to its original level. I figured this was a nice touch, so that when you later plug your headphones in and queue up your Celine Dione
MP3 collection, you won't get popped eardrums. Well, no more than normally at least.
Hide Sh rin k
Co p y Co de
The next step in processing is to examine the WriteIRWAVFile method. This method draws upon the base class (PCMWavGen) to write the necessary
information to create a valid WAV file. WriteHeader and WriteFormat generated sections #1 and #2 of the WAV file format. The 3rd section is generated
by calling the WriteWAVSignal method which (finally) gets to the issue of generating the proper audio WAV data.
Hide Co p y Co de
converted by W eb2PDFConvert.com
The WriteWAVSignal method creates audio data for the given IR code. If you can remember from previous sections, the IR code consists of a series of
ON/OFF burst pairs. The ON time is comprised of many on-off transitions of the signal, the frequency of which is determined by the carrier frequency of the
IR code. The OFF time is, well, simply time where we want to be absolutely quiet and send no signal at all.
Hide Sh rin k
Co p y Co de
converted by W eb2PDFConvert.com
///
///
///
///
///
The last method of note creates the data for a stereo carrier wave. Originally, I created a method that calculated a carrier wave with a given phase-shift and
called it twice to get a stereo wave. Due to speed issues, I rewrote this to calculate both channels at once. (The original method, although unused, is included
in IRWav). Also, I took one more caching step and cached the carrier wave that was generated. The IR codes that come from a single remote generally use the
exact same carrier frequency. So I managed to eek out more speed improvement by caching the last carrier frequency. Then I simply copy enough of these
carrier cycles into the destination signal that will fit in the given duration.
Hide Sh rin k
Co p y Co de
converted by W eb2PDFConvert.com
Sample Application
The sample application is very simple and is meant to be nothing more than an illustration of how to use the underlying IR code. To really take advantage of
the sample application, you need 2 things.
converted by W eb2PDFConvert.com
First, you need to purchase or borrow a $29 Total Remote audio dongle. This is the hardware that fits in the audio port, as shown in the picture at the
top of this article.
Second, you need to locate valid IR code data for the devices you wish to control (television, VCR, DVD, etc...). This second part is the trickiest, but you
should have good luck finding them in the places I mention in this article.
The actual sending of the IR data couldn't be simpler, as illustrated by the following snippet:
Hide Co p y Co de
/// <summary>
/// Private member that allows us to send signals to the TotalRemote
/// </summary>
IRWav _totalRemote = new IRWav();
///
///
///
///
<summary>
Sends an IR command
</summary>
<PARAM name="idCommand">Unique ID of the command (or Guid.Empty)</PARAM>
The sample application reads the config.xml file and dynamically generates buttons for the user interface. (Please note that the config.xml file must reside in
the same directory as the executable.) When you press a button, its associated IR code is then sent through the total remote. Each entry in the config.xml file
consists of an ID (used to uniquely identify the button), a Name (displayed on the button), and the Code (actual Pronto CCF data representing the IR code
you want to send). An example of the config.xml file is as follows:
Hide Sh rin k
Co p y Co de
Wrapping it up
So, there we have it from start to finish. I really must commend Griffin for devising a very clever solution to sending IR signals through the audio port. The
method is ingenious and quite simple. I even toyed with creating a homemade version of the dongle, but just haven't had the time. I think the recipe is as
follows:
1 part stereo mini-jack +
1 part capacitor +
1 part resistor +
2 parts LEDs +
1 part Elfin Magic
= Homemade Total Remote
converted by W eb2PDFConvert.com
The problem is that I am a bit short on the Elfin magic. Maybe someone will take this article as the basis and come up with the home version. But either way,
once you know a bit about how IR signals are created, the process of determining how to convert audio to IR is pretty straightforward.
I do have a couple closing notes:
I cannot stress enough that when using this application to send IR codes to your own devices that the IR code is very important! Not only do you need to
find the proper IR code for your make/model of device, but it has to be a good code. Generally, the codes I found were usable. But a lot of codes were
missing the full code. Hint: If you get an IR code that doesn't seem to work, try sending it twice in rapid succession. If this still doesn't work, then it is probably
a bad code. Also, please do not send me requests for IR codes!!! I don't have a big-book-of-IR-codes. Search the web (or look at the sites I references) and
you will find them.
This method of using the audio port may not work on all PDAs. If the hardware manufacturer skimped on the audio port, it might not be capable of sending
a signal (or at least a strong one). For example, I believe the Dell Axim (at least older models) have a problem with using the audio port in this manner. See
the Griffin Technology site for a complete list of supported models.
References
Boy howdy, I certainly referenced a lot when developing this project. Here are the links of the relevant sources:
Griffin Technology - Total Remote Manufacturer.
Barry Gordon - Excellent write-up of how consumer IR signaling works.
RemoteCentral.com - Wealth of IR codes and general consumer IR information.
Stanford.edu - Explanation of the WAV file format.
SonicSpot - Further WAV file format information.
Parallax Inc - Makers of the USB oscilloscope I used (OPTAScope 81m).
More Reading
Here are some related IR links:
LIRC - LIRC is a LINUX package that allows you to decode and send infra-red signals of many (but not all) commonly used remote controls.
WinLIRC - WinLIRC is the Windows equivalent of LIRC, the Linux Infrared Remote Control program.
Ultramote - a Compact Flash IR extender for the pocket PC.
PDAWin extender schematic - a hardware schematic for building your own pocketpc IR extender.
History
4/18/04 - Article submitted
4/22/04 - Minor editing and fixing of hyperlinks
6/10/04 - Added extra references
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Share
EM AIL
Michael is an avid Windows developer, working on applications ranging from agricultural, military, financial, and workflow to those ranging in scope from
mobile, desktop and client-server systems. He is a co-author of the MFC Bible 4 published by Macmillan. In 2003 he was a team member on the project
converted by W eb2PDFConvert.com
that won the CES 2003 Best of Innovations award for Home Automation. Currently he is working for a start-up developing .Net applications for home
automation on desktop, PocketPC, and Palm platforms. He also runs a software development and consulting business at http://www.digitForge.com
Go
First Prev Next
converted by W eb2PDFConvert.com
converted by W eb2PDFConvert.com
Manipulate IR port
draven2040 13-Sep-04 13:39
Be good to port this to Win32 XP
norm.net 9-Jun-04 4:51
News
1 2 Next
Suggestion
Question
Bug
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalin k | Advertise | Privacy | Terms o f U se | Mo b ile
W eb 03 | 2.8.150723.1 | Last U p dated 11 Ju n 2004
converted by W eb2PDFConvert.com