Infrared Remote Control Decoding
You can easily add a remote control to your project using the IR command. When enabled this function will run in the background and interrupt the running program whenever a key is pressed on the IR remote control. It will work with any Sony compatible remote control including ones that generate 12, 15 or 20 bit messages.
Most cheap programmable remote controls will generate these commands and using one of these you can add a sophisticated flair to your project.
MMBasic 5.0 on the CGMICROMITE2 (and CGMICROKIT) and CGMICROBOARD support the NEC protocol, too. The NEC protocol is also used by many other manufacturers including
Apple, Pioneer, Sanyo, Akai and Toshiba so their name brand remotes can be used. NEC remotes use a 38KHz frequency and suitable receivers tuned to that frequency include the Vishay TSOP4838, Jaycar ZD1952 and Altronics Z1611A .
To detect the IR signal you need an IR receiver connected to the IR pin.
IR Pin for CGCOLORMAX is pin 12.
IR Pin for CGMMSTICK is pin 14.
IR Pin for CGMICROMITE2 is pin 16. On the CGMICROKIT connector this is the uM16 connection.
IR Pin for CGMICROBOARD is uM46, a couple of pins from RESET.
This is illustrated in the diagram above. The IR receiver will sense the IR light, demodulate the signal and present it as a TTL voltage level signal to this pin. Setup of the I/O pin is automatically done by the IR command.
Sony remotes use a 40KHz modulation frequency but receivers for that frequency can be hard to find. Generally 38KHz receivers will work fine but maximum sensitivity will be achieved with a 40KHz device such as the Vishay TSOP4840. Examples of 38KHz receivers that work include the Vishay TSOP4838, Jaycar ZD1952 and Altronics Z1611A.
To setup the decoder you use the command:
IR dev, key, interrupt
Where dev is a variable that will be updated with the device code and key is the variable to be updated with the key code. Interrupt is the interrupt label to call when a new key press has been detected. The IR decoding is done in the background and the program will continue after this command without interruption.
This is an example of using the IR decoder:
IR DevCode, KeyCode, IR_Int ' start the IR decoder
< body of the program >
IR_Int: ' a key press has been detected
PRINT "Received device = " DevCode " key = " KeyCode
IR remote controls can address many different devices (VCR, TV, etc) so the program would normally examine the device code first to determine if the signal was intended for the program and, if it was, then take action based on the key pressed. There are many different devices and key codes so the best method of determining what codes your remote generates is to use the above program to discover the codes.
The IR function uses the same I/O pin as the wake up signal for the CPU SLEEP command and it is possible to combine them so that an incoming IR signal will wake the controller which will then decode the IR signal. In this way you can have a microprocessor running on battery power that will wake up on an IR signal, do something based on the signal, then go back to sleep.
The following is an example:
' start the IR decoder
IR DevCode, KeyCode, IR_Int
CPU SLEEP ' now sleep until a signal
' a key press has been detected
< do some work based on the key press >
END SUB ' return to sleep again
Infrared Remote Control Transmission
Using the IR SEND command you can transmit a 12 bit Sony infrared remote control signal. This is intended for Maximite or Micromite† communications but it will also work with Sony equipment that uses 12 bit codes. Note that all Sony products require that the message be sent three times with a 26mS delay between each message.
The circuit above illustrates what is required. The transistor is used to drive the infrared LED because the output of the Maximite is limited to about 14mA. This circuit provides about 50mA to the LED.
To send a signal you use the command:
IR SEND pin, dev, cmd
Where pin is the I/O pin used, dev is the device code to send and key is the key code. Any I/O pin on the Maximite can be used and you do not have to set it up beforehand (the IR SEND command will automatically do that).
Note that the modulation frequency used is 38KHz and this matches the common IR receivers (described in the previous page) for maximum sensitivity when communicating with another Maximite or Micromite.