I'd Rather Be Building Robots

May 21, 2009

Control the world with the HiTechnic IR Link

Filed under: Sensors, Tutorials — Xander @ 20:53

IRLink Sensor The HiTechnic IR Link is capable of many things including controlling your Power Function devices.  The one thing you couldn’t do was transmit regular data.  That is, until now. 

The IR Link has several transmission modes, 0×02 for example is used for the PF functionality.  There is another mode 0×00, UART-mode, which can be used to transmit 8 bytes at a time at 2400 baud using a 38KHz carrier frequency.  It is also the mode that can be used for communicating with the RCX.

There are two ways you can use the IR Link to transmit your data.  The first method which can be used to send the same 8 bytes over and over again works by preloading the transmit buffer at 0×45 with the 8 bytes you wish to send, followed by the total message length (0×08) and the transmission mode to be used (0×00).  You can then trigger the IR Link to start transmitting by setting register 0×4F to 1 with another I2C message.  Care must be taken not to trigger a retransmission before the previous one is done or you’ll garble the currently transmitting message as it will immediately start transmitting from the first byte again.

If you don’t want to send just 8 bytes over and over again, you can also load up the transmit register at 0×45, followed by the message length (0×08), transmission mode (0×00) and the trigger (0×01). 

Due to the nature of UART-mode, the bytes are transmitted UART-style with odd parity.  That means that when you tell the sensor to transmit 0xAB (b10101011), the following is transmitted via IR:

Start B0 B1 B2 B3 B4 B5 B6 B7 Par Stop
1 0 0 1 0 1 0 1 0 0 0

Each data byte is preceded by a start bit which is always set to 1, then follows bits 0 through 7 of your data (least significant bit first), inverted (0 becomes 1, 1 becomes 0), the odd parity value and then a stop bit which is always 0.  Sounds complicated?  I agree, it took several edits of this blog entry to get this right!

For each bit set to 1, the IR Link’s transmitter goes high for 1/2400th of a second or about 0.42ms, that means that 2 consecutive bits set to 1 will mean an IR burst of a little more than 0.83ms. 

There is a gotcha with the IR Link’s transmission buffer;  its start register is counted backwards from 0×4D. That means that if you have an 8 byte message to send, the first data byte starts at 0×4D-0×08 = 0×45. So if you want to transmit the above sequence, you’ll have setup the IR Link’s buffer such that it looks like this:

Reg 0×45 0×46 0×47 0×48 0×49 0×4A 0×4B 0×4C 0×4D 0×4E 0×4F
Data 0xCC 0×76 0×66 0xFF 0xCC 0×00 0xAB 0xAA 0×08 0×00 0×01

Where:
0×4D is the number of bytes to be transmitted
0×4E is the transmission mode
0X4F is the transmission trigger
You will nee to skip the transmission trigger (0×4F) if all you want to do is preload the transmission buffers. 

Please note that there is no way for the IR Link to know if transmission was successful.  An easy way to check if your IR Link is sending *any* IR signals is to point it at a digital camera and look through the viewfinder.  The IR light should appear as a dot the small screen on the front of the sensor.  Most digital cameras are extremely sensitive to IR light.  This is also a good way to check if your TV remote is still working!

I’ve included two NXC programs, one which transmits the same message over and over again as fast as possible, the other sends a single message every 50ms.

IR Beacon: [LINK] Generates 1200Hz IR signal, can be used with IR Seeker V2
IR Messenger: [LINK]

The functionality to send messages via IR will be included in the next release of the 3rd Party RobotC Driver Suite, so I didn’t include any here.

5 Comments »

  1. Yay! NXT-RCX communication outside of NXT-G. (There are probably drivers for NXC that I didn’t see, but this should work…) Now to figure out how to send IR messages from the RCX to the NXT. (Technicaly, for RCX to NXT one-way communication, we could use the light sensor, just like with the camera.)

    Comment by NickNackGus — May 22, 2009 @ 13:10 | Reply

  2. Oh yeah… frequency of transmission is greater than 1 kHz…nevermind on the light-sensor idea…it can still be used like the ultrasonic sensor to determine distances…if you haven’t already, could you try to get the IRlink to work for recieving messages from the RCX? (The way the default firmware permits? With values between 0 and 255)

    Comment by NickNackGus — May 31, 2009 @ 14:46 | Reply

  3. At the moment I am working on other projects so this will have to wait, unfortunately. When I get some time again, I’ll add this stuff to the driver suite.

    Regards,
    Xander

    Comment by Xander — May 31, 2009 @ 14:48 | Reply

  4. hmm.. interesting. Coincidentally UART and I2C are covered in the last few lectures for my embedded systems class. haha. Though this is a much more interesting way of learning.

    Comment by Steve Tan — June 6, 2009 @ 13:41 | Reply

  5. [...] how does it work? Well, remember I mentioned a few articles back how you could turn an IR Link into a beacon by pulsing it at 1200Hz? Well, [...]

    Pingback by HiTechnic Sensor Hack « I’d Rather Be Building Robots — June 30, 2009 @ 08:58 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.