Code Bank: BS2/Sony Remote Control Interface -------------------------------------------- The following program reads signals from a Sony Corporation entertainment equipment IR remote control, displays them in the DEBUG window and outputs the result as DTMF tones. Parts count is low, consisting of an infrared receiver module, such as the Sharp GP1U58X, a remote control unit and optional speaker output parts (piezo transducer and 10 uF capacitor). See the BASIC Stamp 2 manual for speaker hookup. The infrared receiver module for this project should, ideally, be one that is set for a 40 kHz carrier frequency. However, the more common 38 kHz modules will work also. Some reduction in range may be apparent, but the final result is functional nonetheless. The output pin of the module connects to a Stamp I/O pin and you supply +5 volts and ground to the other pins. The remote control that you use may be either a Sony manufactured unit, or one of the universal remotes that can be configured for Sony entertainment equipment. This is important since we’ll be dealing with, and programming for, a specific signal protocol. With Sony’s SIRCS specification, a start pulse is initially sent to indicate the beginning of a frame of data. This pulse is 2.4 msec in length. Following this are seven bits of data, which represent the instruction being sent. An additional five bits follow, signifying the target device (TV, VCR, etc.). Data bits are sent with the least significant bit first and the most significant bit last. The Category data in this example is ignored. If you do want to make use of it, the listing can be extended to store and decode the last five bits of the frame in the same manner as the first seven bits. '----------- 'IR2DTMF.BS2 ' 'Copyright © 1999 by D.G. Roy ' 'reads IR data from a Sony remote control, using a 40 kHz IR 'module (eg: Sharp GP1U58X) connected to SIGLINE. Displays the 'result in the DEBUG window and outputs as DTMF tones. ' 'pin assignments SIGLINE CON 2 'signal from sensor SPKR CON 8 'audio output line ' 'constants FALLING CON 0 'used by PULSIN cmd ' 'variables DSIG VAR BYTE 'output LOWPART VAR NIB 'used in SAYCODE HIPART VAR NIB 'used in SAYCODE ' 'instruction data ID0 VAR WORD 'result storage from PULSIN ID1 VAR WORD ID2 VAR WORD ID3 VAR WORD ID4 VAR WORD ID5 VAR WORD ID6 VAR WORD ST VAR WORD 'start signal JUNK VAR WORD 'temp storage ' '---------------- 'Main Loop starts '---------------- sigread: DSIG = 0 'initialize result variable 'get start bit PULSIN SIGLINE, FALLING, ST 'get seven data bits (LSB first) PULSIN SIGLINE, FALLING, ID0 PULSIN SIGLINE, FALLING, ID1 PULSIN SIGLINE, FALLING, ID2 PULSIN SIGLINE, FALLING, ID3 PULSIN SIGLINE, FALLING, ID4 PULSIN SIGLINE, FALLING, ID5 PULSIN SIGLINE, FALLING, ID6 'collect six category bits - but we don't do anything with them PULSIN SIGLINE, FALLING, JUNK PULSIN SIGLINE, FALLING, JUNK PULSIN SIGLINE, FALLING, JUNK PULSIN SIGLINE, FALLING, JUNK PULSIN SIGLINE, FALLING, JUNK PULSIN SIGLINE, FALLING, JUNK 'verify a good start bit - should be about 1200 IF ST < 1100 THEN sigread 'no good IF ST > 1300 THEN sigread 'try again 'start bit is OK, so convert data bits - a high (1) should be ' about 600, a low (0) should be about 300 - we split the ' difference and say that < 450 is a low, >= 450 is a high 'convert the instruction data - start with MSB IF ID6 < 450 THEN DD5 DSIG = DSIG + 1 'add binary one DD5: DSIG = DSIG * 2 'shift left IF ID5 < 450 THEN DD4 DSIG = DSIG + 1 'add binary one DD4: DSIG = DSIG * 2 'shift left IF ID4 < 450 THEN DD3 DSIG = DSIG + 1 'add binary one DD3: DSIG = DSIG * 2 'shift left IF ID3 < 450 THEN DD2 DSIG = DSIG + 1 'add binary one DD2: DSIG = DSIG * 2 'shift left IF ID2 < 450 Then DD1 DSIG = DSIG + 1 'add binary one DD1: DSIG = DSIG * 2 'shift left IF ID1 < 450 THEN DD0 DSIG = DSIG + 1 'add binary one DD0: DSIG = DSIG * 2 'shift left IF ID0 < 450 THEN DDDONE DSIG = DSIG + 1 'add binary one DDDONE: 'display the result DEBUG ?DSIG GOSUB SAYCODE 'output as DTMF 'and start over PAUSE 45 'to debounce signal GOTO sigread '----------- 'subroutines '----------- SAYCODE: 'break up the code and output as DTMF tones 'works for 2 digit codes LOWPART = DSIG // 10 'modulus HIPART = DSIG / 10 DTMFOUT SPKR,[HIPART] DTMFOUT SPKR,[LOWPART] RETURN '------------- If you're not going to use the speaker output, just delete the GOSUB SAYCODE instruction and the SAYCODE subroutine. With this program, you can determine the numeric codes associated with each button on the remote. From there, its a simple matter to jump to individual subroutines for specific robot actions.