The Infrared remote interface is not difficult to build ... getting the codes is the most important part.

It is not so difficult once you get the BIG PICTURE !!


Chuck Heller's data aquisition program LEARN.EXE helps to some extent. It presents a repeatable code sequence. You will still need to discover the applicable code sequence contained within each button's bit stream, and then copy them to Chuck Heller's KEYS.TXT.

KEY.TXT cannot be used with TNT.

Use IRREMOTE.BAS to change IRCODES.TXT for use with TNT. .. or you can manually edit them (tedious).

The TNT IRREMOTE.BAS program has some useful features. It searches for the token you have defined and displays it next to the bit stream. You can see where your token can be added to or changed to improve your chances of obtaining a unique 'HIT'. Using TNT's IRREMOTE.BAS allows you to edit the codes by exiting to BASIC ... editing the codes in the listing .. re-running the program and testing the IR codes.

The codes obtained can then be saved from the IRREMOTE.BAS listing to the IRCODES.TXT data file by using the [S]ave key while IRREMOTE.BAS is running. IRCODES.TXT is written and can then be used by TNT.BAS and TNT.EXE to assign TV remote key codes to operations.

The TNT IRREMOTE.BAS program is written in QUICK BASIC 4.5 and uses a slightly different method to collect the codes. The COM1: port is opened at 9600,n,7,1. The data is collected from the COM1: port using:

DATA$ = INPUT$((LOC(1),#1)

This inputs the entire buffer as a series of ASCII characters which don't make much sense. iT lookS like Greek .. BUT ... after looking at the set of ASCII characters, and refering to an ASCII value chart, it was noticed that some were 128 (10000000) and the rest varying values higher than 128 (1XXx0000)... so ... a software filter using the ASC(XX$) function was applied to turn all 128's into 1's and the rest into 0's. This made a token that was very similar to Chuck's. TNT derived tokens are NOT identicle to Chuck Heller's .

Next, trial and error was used to find the correct sequence for each button. The code sequences are quite recognisable. When I ran Chuck's Learn program and printed out the data. I saw that his data collection was nearly flawless. I believe Chuck uses a C language serial port Interrupt Service Routine (ISR_Serial)) that accesses the port through the Interrupt table. His program uses the input as an interrupt and services it immediately.

I tried this and got many stack overflows, errors, and trouble ... so I just opened the port ... let data come into the buffer... and read it in the main screen display loop. I found that I had better data reception using 7 data bit words, rather than using Chuck Heller's 8 bit words. This is probably a characteristic of BASIC's manner of data aquisition. In TNT, any data less than three ASCII characters long is considered to be noise. The buffer is purged after each data aquisition, and anytime there is noise in the buffer less than three characters long, with the

NOISE$ = INPUT$((LOC)1,#1) ... loop.

I could readily see the similarities of the output at this point.

The trick in getting a good set of tokens is to try to ignore those that are random, and select those that are repeated and unique in each buttons data stream. Sometimes portions of the data stream will be similar between two keys. When this happens you need to extend one or the other to make it unique and distinct. This is not so easy. I began by hitting the VOL UP button and writing down the bits. I did this several times until I could recognize the general pattern. Then I selected an eight to ten bit sequence to serve as the token. Then tested it. I put the list into IRREMOTE.BAS so I could edit it quickly from QBASIC 4.5. You will need a long enough TOKEN so it is unique, and so that it will not be generated randomly. When you first begin it can look hopeless. Wrong keys keep coming up or keys not found are reported. Then, when the data set becomes more accurate and complete, your results begins to improve. Finally, you will have a data set that performs very well.

It should be noted that the IR sensor is sensitive to incandescent lighting, sunlight, matches and cigarrette lighters, space heaters, or any source of Infrared (heat) noise. Most of these can be filtered out as noise, but it is best to avoid them as they conflict with valid data aquisition. My railroad is in the basement, and I use flourescent lighting, so I'm good to go.
But ... bare in mind that light bulbs, flood lights, and heaters can interfere. These will all add to your troubles when trying to construct a valid data set.

I use an RCA SYSTEM LINK 4 whch I bought for about 10 bucks. This is a neat unit ... compact, easy to hold, concise, and quite relevant to our application. I use it similarily to Chuck, although I have implemented some differences which I find useful for operating within TNT.

This is what is so powerful about having your own SYSTEM, you can write code to adapt to any manufacturer's CV conventions, any RC remote, and customize your sceen display.



Here are the codes I'm using with the RCA SYSTEM LINK 4 set to TV code select 000. This is as it comes ... take out the batteries, press the buttons until the light stops working ... then replace the batteries .... or ... press Code Search ... then TV .. and then enter 000.

SPEED UP (volume up)
"110100001111110010111"

SPEED DOWN (volume down)
"1101000111111110010111"

HIGHER THROTTLE (channel up)
"111100101101000011010010"

LOWER THROTTLE (channel down)
"11111111001011000"

0
"1100111111111111001100"

1
"11110011000100001100110"

2
"11110011001000001100110"

3
"111100110011000011001100"

4
"11110011010000001100101"

5
"111100110101000011001010"

6
"11110011011000001100100"

7
"111100110111000011001000"

8
"1100011111111100111"

9
"10000001100011001100"

F0 (play)
"1111010111101"

F1 (enter)
"111101010011000010101100"

F2 (mute)
"11111100111111"

F3 (tv/vcr)
"101000010101"

F4 (record - need to press twice!!)
"1111110111101"

PAUSE (pause)
"10011111010000"

STOP (stop)
"0101111111111"

REVERSE (rew)
"101000010000"

FORWARD (fast forward)
"101000110000"

ALL STOP (off/on)
"11100111011000011000100"

PREVLOCO (prev ch)
"111110010011100001101100"

TURNOUT SELECT (TV)
"1111100111010000011"