background image

Parallax, Inc.  •  IR Buddy Demo Kit (#28016)  •  11/2002

 

Page 3

 

In a typical application, the command to receive RC-5 codes would be  immediately followed with a 

SERIN

 function to accept the data. 

 
Example: 

 

  SEROUT pin, baud, [$72, 10] 
  SERIN  pin, baud, [STR buffer\8\255] 

 
The first line above sends the RC-5 receive command and specifies a 10 millisecond holdoff period.  The 

second line will accept the data into an eight-byte array called buffer.  The \8 parameter tells 

SERIN

 to 

accept eight bytes of data.  The trailing  \255 parameter tells 

SERIN

 to terminate if the value 255 is 

encountered in the input stream. 

 
This syntax allows the BASIC Stamp to retrieve all the available key codes from the IR Buddy, regardless 

of the actual number buffered (up to four codes; two bytes per code).  The IR Buddy uses the value 255 
to identify an unused position in the buffer.  The end of the buffered data is signified with the value 254.  
For example, if the IR Buddy buffered key codes for numbers "1" and "2" from a typical television 

remote, the IR Buddy buffer would contain the following data: 
 

  0    1    0    2  254  255  255  255 

 

The first two bytes are the system and command codes for "1," the second two bytes are the system and 
command codes for "2."  The fifth byte, 254, signifies the end of data in the buffer.  The rest of the 

buffer is padded with the value 255.  Note that (with the syntax specified above) 

SERIN

 will terminate 

upon reading the first 255. 
 

The IR Buddy uses one additional special value: 253.  This value tells the BASIC Stamp that the last key 
code has been repeated without an intermediate release.  The value 253 will appear in the buffer when a 

remote key is pressed and held. 
 
 

$74  Transmit RC-5 Key Code 

 
Use:  

SEROUT 

pin

baud

, [$74, 

repeats, modulation, system, command

]

 

 

pin 

variable or constant value: 0 to 15 

baud 

variable or constant value for 2400, 4800 or 9600 baud; open-mode 

repeats 

variable or constant value: 0 to 255; number of repeats of this key code 

modulation  variable or constant value: 30, 38 or 56; IR modulation frequency in kilohertz 
system 

variable or constant value: 0 to 31; system code 

command 

variable or constant value: 0 to 63; command value 

 

This command directs the IR Buddy to transmit any one of the 2048 unique key codes using the Philips 
RC-5 protocol.  Each key code consists of a five-bit system code and a six-bit command.  This function 
will always send the key code once at the specified modulation frequency (30, 38 or 56 kHz), followed by 

the specified number of repeats.   
 

Once the IR Buddy begins transmitting the key code, it will pull the serial line low to indicate its busy 
state.  This line can be monitored by the BASIC Stamp to prevent resetting the IR Buddy or otherwise 
disrupting a transmission in progress.   

Summary of Contents for 28016

Page 1: ...tamp Device controller using a standard television VCR remote control Fool proof beam interrupt detection for alarm systems Wireless data exchange between BASIC Stamps and IR master slave control Pack...

Page 2: ...y robust The IR Buddy capitalizes on the strength of this protocol and with specialized internal software uses a similar technique to allow the BASIC Stamp to transmit and receive eight byte data pack...

Page 3: ...the buffer The rest of the buffer is padded with the value 255 Note that with the syntax specified above SERIN will terminate upon reading the first 255 The IR Buddy uses one additional special value...

Page 4: ...bytes variable or constant values 0 to 255 8 byte packet This command directs the IR Buddy to transmit an eight byte data packet to a companion IR Buddy using the specified modulation frequency Note...

Page 5: ...It is particularly useful when the connection is over a long wire run especially in an electrically noisy environment The Loopback test can be used to establish the highest error free baud rate betwe...

Page 6: ...imulates normal program activity and will demonstrate the IR Buddy s ability to buffer multiple key code data Connect the IR Buddy to the BASIC Stamp as shown if Figure 1 Title IRB RC 5 Monitor BS2 ST...

Page 7: ...OL clear old message NEXT GOTO Loop_Pad End_Of_Buffer DEBUG End of Buffer GOTO Clear_Old_Data Repeated_Key DEBUG Repeated Key Clear_Old_Data idx idx 1 point to next line IF idx 7 THEN Loop_Pad done DE...

Page 8: ...utputs using numeric buttons 1 though 4 on the remote The Mute button is used to turn all outputs off The system code for the program has been set to zero the typical value used for television control...

Page 9: ...x extract system code IF sysCode BufEnd THEN Loop_Pad reached end of buffer IF sysCode System THEN Skip_Key check for valid system code cmdCode buffer idx 1 extract command Check_All_Off IF cmdCode Al...

Page 10: ...R Buddies from extraneous IR sources The use of the error accumulator allows the system to work in and be fine tuned for IR noisy environments The use of random coded message prevents defeat even from...

Page 11: ...tract system value cmdOut randVal LowByte 00111111 extract command value TX_Code SEROUT IRbTX IRbBaud IRbRc5Tx 0 IRbMod sysOut cmdOut PAUSE 5 let IRB grab SIO line TX_Wait IF Ins LowBit IRbTX Busy THE...

Page 12: ...ic do not change IR_Buddy_Reset LOW IRbTX signal reset LOW IRbRX PAUSE 5 INPUT IRbTX release reset signal INPUT IRbRX PAUSE 50 allow time for reset actions RETURN Note The transmit pattern from the IR...

Page 13: ...error occurs the program will halt and display an appropriate message Title IRB Loopback BS2 STAMP BS2 I O Definitions IRbSIO CON 15 IR Buddy serial I O Constants IRbLoopback CON 4C loopback test IRb...

Page 14: ...idx 5 DEBUG DEC buffer idx ClrEOL CR NEXT IF buffer 0 testVal THEN Packet_Error IF buffer 1 testVal THEN Packet_Error IF buffer 2 254 THEN Packet_Error IF buffer 3 255 THEN Packet_Error NEXT testVal N...

Page 15: ...et In this application the 8 byte packet is structured accordingly 0 Header 1 Command i e Light LEDs on slave 2 Data byte 1 i e LED pattern for slave LEDs 3 Data byte 2 4 Data byte 3 5 Data byte 4 6 D...

Page 16: ...buffer 8 bytes cmd VAR Byte data1 VAR Byte data2 VAR Byte data3 VAR Byte data4 VAR Byte data5 VAR Byte chkSum VAR Byte header VAR buffer tx header ackByte VAR buffer rx status lastCmd VAR Byte last c...

Page 17: ...acket_Error rxChkSum chkSum save rx checksum GOSUB Make_CheckSum calc checksum of rx packet IF rxChkSum chkSum THEN Packet_Error compare checksum values Good_Packet DEBUG Good Packet ClrEOL counter co...

Page 18: ...ClrEOL clear last TX message GOTO Show_Packet_Data Show_RX_Packet DEBUG CrsrXY 4 4 ClrEOL clear last RX message Show_Packet_Data display packet bytes FOR idx 0 TO 7 DEBUG HEX2 buffer idx NEXT RETURN N...

Page 19: ...e assumes the packet is good and will continue with the command If the header or checksums are not valid the slave responds by placing a NAK byte in the header and sending the packet back to the maste...

Page 20: ...VAR buffer rx packet ackByte VAR buffer ack nak byte rxChkSum VAR Byte comparison checksum idx VAR Nib loop counter Initialization Setup LEDs 0000 LEDs off DirA 1111 make LED pins outputs Program Code...

Page 21: ...ming specific do not change IR_Buddy_Reset LOW IRbSIO signal reset PAUSE 5 INPUT IRbSIO release reset signal PAUSE 50 allow time for reset actions RETURN Make_CheckSum checksum of bytes 0 to 6 chkSum...

Reviews: