All About IR Signals
What makes Brainlink unique among robot controllers is it's built-in ability to capture and re-transmit just about any infrared signal. Though already decoded device files for a number of popular robots are included with the Brainlink software download, we think a large part of the fun of Brainlink is getting it to work with new and obscure IR-controlled devices you may own. Though we've tried to make this process easy by creating supporting firmware and software utilities, the world of infrared protocols is completely un-standardized, with each manufacturer mostly doing their own thing. This tutorial will describe the theory behind data transmission via infrared signals, and discuss at a high level how Brainlink transmits and captures IR signals.
Infrared Signals: A Quick Primer
Though implemented using a wide variety of different protocols, infrared signals all share one commonality: They are sending digital (binary) data using infrared light. The variety of ways this is accomplished is discussed in this section.
How data is encoded. Take a look at the IR signal below; each time our receiver detected IR light the signal is shown with a value of 1, and whenever no light is detected the signal value is 0. The signal below is encoded using something referred to in Brainlink documentation as "downtime" encoding, which means that a logical 0 is shown as a short amount of time between pulses, while a logical 1 is a long period of time between pulses. Downtime encoding is the most common way data is encoded. The others we have identified are:
- Alternating. In this case a logical 1 is a long period of time of either signal value high or low, and a logical 0 is a short time of signal high or low.
- Uptime. This is the second most common type of encoding - in this case, the signal stays high for a variable amount of time (with 0 being a short time and 1 a long time), while the time between pulses is simply used to mark the end of one bit and the start of another.
- iRobot. We named this type of encoding scheme after encountering it on the Roomba remote. In this case, each bit takes up a fixed amount of time (on the Roomba, it is 4 ms). If the signal is high for 3 of those milliseconds, followed by going low for 1 ms, this is considered a logical 1. If it is high for 1 ms and low for 3 ms, this is a logical 0.
There may be other data encoding strategies out there; if so, Brainlink doesn't currently support them (but likely could with a firmware update).
Figure 1: The IR signal from the Prime-8 "Shoot" button
Start Pulses. IR remotes typically (though not always) start their signal with a long pulse, or occasionally, a sequence of pulses which do not contain data. The purpose of these pulses is to notify the device that information is coming.
Carrier Frequency. The image to the right shows a magnified view of the first three pulses of figure 1. Notice that even when the signal is on, it is actually pulsing at a 50% duty cycle. The frequency with which it does this is called the carrier frequency, which is 38 KHz on most remotes. The carrier is one way IR receivers can filter out sources of infrared light (the Sun, artificial lights, etc).
The Brainlink's receiver is tuned to receive signals near the 38 KHz frequency; so if Brainlink can capture it, you can assume the carrier is roughly 38 KHz. It is possible to come across a device with carriers at 56 KHz. Signals at this carrier can't be captured by Brainlink, but they can be transmitted by Brainlink if you can capture the data in some other way.
Number of Bits. The number of bits encoded varies substantially by device - 8, 12, 16, 20, 24, and 32 are all common. Brainlink can support capture of signals with up to 46 bits. Some devices which send 24 or 32 bits of data actually only use 8 bits for information, and use the additional bits for error checking and correction.
Signal Repetition. Some IR remotes resend their signal every 20-100 milliseconds as long as a button is held down. This is uncommon with consumer devices but fairly common among robot remote controls. Unfortunately, Brainlink can't currently auto-detect if a signal is repeating; however, a major clue is if a device does something (like move forward) only when the button is held down.
IR Capture and Transmit
Brainlink contains an IR receiver to capture signals from remote controls, and an IR LED to transmit signals to devices. The following description makes reference to Brainlink's bluetooth protocol, which is fully specified here.
IR Capture. Brainlink's IR Receiver is a Sharp GP1U module with a peak sensitivity to signals with a 38 KHz carrier frequency. You would find this type of module in any device that is controlled by IR remote. In Brainlink, the output signal of the receiver module is connected to a input capture pin on the Brainlink's microcontroller. The output signal goes high whenever it sees infrared light at the carrier, and otherwise stays low.
When a capture command is sent to the Brainlink over its bluetooth connection Brainlink's default firmware begins listening for the signal from the receiver module to go high. If it does so within 4 seconds, Brainlink begins recording the time between the receiver signal's rising and falling edges. The firmware does some analysis on these signals, rejecting as noise those with 4 or fewer state changes or those where the signal is high for less than 200 us. If a signal is seen as valid, Brainlink then transmits the time data over Bluetooth to the host, and it stores the data in a temporary buffer (only the most recent captured signal is stored). A command from the host can also store this data into Brainlink's EEPROM, where it can later be retrieved for analysis or transmission.
IR Transmission. Brainlink's IR LED can be configured to transmit signals that mimic those of just about any remote control. In order to do so, Brainlink's firmware must be told how to configure the IR signal. Specifically, it needs the following signal characteristics:
- Carrier Frequency
- Start Pulse Sequence
- Number of bits in a signal
- Type of encoding
- Time representing a logical one
- Time representing a logical zero
- If applicable, time between bits
These characteristics are described in detail in the first section of this tutorial. We have created several utilities that can help you analyze a signal and determine these values - see "How to Decode an Infrared Remote".
Once configured, a host can transmit a signal to Brainlink containing the data in encoded form as well as how frequently the signal should repeat. The IR transmitter can be dynamically re-configured with different characteristics; so you can switch which remote control Brainlink is mimicking at any time.
Raw Format. It is not always possible to discover the IR signal's characteristics. In these situations, a raw format may be used which is simply the un-encoded time data produced by capturing a signal. There are two sources for this data:
- EEPROM. As mentioned in the IR Capture section, it is possible to store the time data from the most recently captured signal in EEPROM. With this method, one can store up to five signals on a given Brainlink, and the data will persist through power-cycling. To transmit a signal in EEPROM, the host need merely specify the signal position (0-4) and if the signal should auto-repreat.
- Host. Alternatively, the host can transmit the signal data to Brainlink in raw form. This is bandwidth intensive and thus relatively slow, but it has the advantage of allowing nearly infinite signal storage and the data need not be re-captured on different Brainlinks.