Basic Stamp Programming Examples

This section covers some example programming code for all the Infrared Control Freak command codes. The code is written for a Basic Stamo (BS2)

Output results are in  decimal formats. However if you replace the 03x with a 04x, the outputs will be in ASCII format (i.e. for direct connect to Terminal screen)

Command

Code

Mode Name

Description

     

020

ZAP_MESSAGE

Transmit IR Device and Button Codes to other robots

030

IR REMOTE CONTROL

Receive Sony (SIRC) IR commands and output results to serial port as two-bytes in Decimal format

031 N/A

032

ONE-SHOT IRPD

One shot proximity sensing. 6 bytes of serial data are transmitted with proximity information.

033

N/A

 

034

FREEWHEELER

6 bytes of serial data are transmitted with proximity information in a Send a continuous stream of data. This is used for debugging or for .

035

AUTOPILOT

Fuzzy logic results are sent as two bytes of data to serial port. These depict the direction of the nearest obstacle and distance.

036

BEACON

This command searches for Sony (SIRC) infrared transmission on all 3 sensors and returns with which sensor received the highest number of IR 'hits'. 

037 LIGHT SENSOR Used with Infrared Control Freak 'Light' version that has built-in Light sensors. Command return with Left & Right readings on 
038 SWEEP

(not implemented yet)

This command sweeps up and down various IR modulation frequencies to obtain a 'zone' in which the obstacles are located. 
     
 

 

 

 

 

 

 

 

 

 

 

 

COMMAND 032 ONE-SHOT IPRD

The Basic Stamp program below will trigger the Infrared Control Freak (IR-CF) into the ONE-SHOT IRPD. In this command IR-CF will send 100 pulses on the left and right  IR LED's. IR-CF will then check on each sensor for reading of obstacles. 

 The measured results are sent  as  6 bytes of data. The values will be in the range 0-100. The value 0 = the sensor has not detected any obstacle.  On the other extreme, a value of 100 = that the obstacle is almost about to collide with the IR-CF.    

 The first two bytes are the results from the right sensor. The first byte is the measured hits from the Right LED and the second byte is the number of hits from the LEFT LED. Unless the obstacle is extremely close,  the right sensor should not actually 'sense' any 'hits' from the LEFT LED. As depicted in diagram below the obstacle will be sensed only on the left and middle sensors.

 

The sequence of Bytes returned to the Basic stamp are:

RIGHT SENSORS

MIDDLE SENSOR

LEFT SENSOR

RHITS_R

RHITS_L

MHITS_R

MHITS_L

LHITS_R

LHITS_R

The most important bytes to measure are 1, 3,4 & 5.

Simple Programming

See below how simple it is to interface to the IR-CF using the Basic Stamp. Just a few lines of code and you'll be up and running:

_________________

'{$STAMP BS2}

'Test Command 032 - Single Shot

 

RX VAR BYTE(5)

DATA_ARRAY VAR BYTE

'***************************

'* MAIN PROGRAM *

'***************************

MAIN:

GOSUB COMMAND_032

GOTO MAIN

'***************************

'* SUBROUTINES *

'***************************

COMMAND_032:

SEROUT 2, 16468, [32]

FOR DATA_ARRAY=1 to 13

SERIN 4, 16468,1000,time_out, [RX(DATA_ARRAY)]

NEXT

 

FOR DATA_ARRAY = 1 to 13

DEBUG dec RX(DATA_ARRAY), " "

NEXT

DEBUG CR

debug "____________________________",cr

RETURN

 

TIME_OUT:

DEBUG "TIMED OUT", CR

RETURN

________________________________

Download Basic Stamp Code

 

COMMAND 035 AUTOPILOT

Download Basic Stamp Code

Hit Counter