|
||||||||
|
||||||||
|
DAN102 Interfacing to an IR Module By Michael Simpson Ever wanted to control one of your projects remotely. How about data entry with out a keypad hookup? With a simple IR module and a bit of programming you can start collecting keystrokes with the best of them. I wont go into the theory behind infrared diodes or transistors nor will I get into distance detection. I will be concentrating on two particular modules. The Sharp GP1U58X and the Vishay TSOP1840. Both these modules operate at 40kHz and are well suited to our applications. There are a great number of remotes, and protocols to match but I will be writing about one in particular. The Sony protocol.
The Protocol Lets start by diving into the protocol. The IR module will output a pulse stream of bits with varying widths. The widths are defined as follows.
The world is not perfect and to compensate for various manufactures we have expanded the specification a bit as follows.
The actual protocol consist of a starting bit followed by 12 data bits. The data bits can be further broken down into command and device bits as shown.
These bits come with the least significant first and will be represented as the command byte and the device byte. We will get into this further when we look at the code. The Modules Lets look a little closer at the modules before we wire them up. The Vishay and sharp modules are interchangeable except for the pin out as shown here.
Kronos Robotics carries both module just click on one of the following links purchase one.
The Circuit Wire up the circuit as shown. You can use the Sharp or the Vishay module. I used a Dios Ultra 32 Pin module here but any Dios Ultra chip or board will work.
Schematic 1
You don't have to hook up the LED for this first program. We are just going to read several bits from the module and display them. Something to keep in mind is that the Dios pulsin command returns a value in .1us units. So a value of 24000 will be 2400us. or 2.4ms. Test Program 1 download it here
Program listing 1 is just a simple program to demonstrate the raw pulse widths of the various bits. The output should look something like this.
Figure 1
I have indicated a start bit in the Figure 1. Generally anything over 2000 I will conceder a start bit. Anything under 1000 will be considered a 0 and the rest a 1. With this in mind the displayed readings above would be 000010010000 or a IR command of 16 and a device of 1. Next Wire up the LED as shown in Schematic 1. Note that LED1 has a integrated resistor. If you dont have this type of LED make sure you use a 100-390 ohm resistor in series with the LED. Test Program 2 download it here
The Dios software comes with a library that reads the IR code for you. In Program #2 we use this library to read the commands. One thing the library does is to add 1 to the command code. This is done so that the library can return a 0 if a timeout occurs. It also lets the number keys return the actual value of the number key that is pressed. Be sure to check out the Dio IR library help file for more information and functions. Parts List
|
Copyright © 2001 - 2007 Kronos Robotics