Connecting the SRF08/10/235 Sonar Modules to the BS2p  

The SRF08, SRF10 and SRF235 modules use the I2C bus for communication and have the same connector pin-out. This example shows how to connect these modules to the BS2p. The SDA (data) and SCL (clock) lines are connected to pins P8 and P9 on the BS2p. These are the pins used by the BS2p for the I2CIN and I2COUT commands. 

Note - For the BS2, BS2e and BS2sx - this example cannot be used. Use the BS2 Example instead. 
If you have the BS2p - read on.

This example uses the I2CIN and I2COUT  commands. It has been tested with the BS2p Rev C firmware.
The BS2p internal 5v regulator is not suitable for powering much external circuitry. I therefore recommend you use a separate 5v regulator.

Circuit Schematic for connecting a SRF08/10/235 Sonar Module to the Basic Stamp BS2p

The schematic above shows 4k7 pull-up resistors on the SCL and SDA lines to Vdd, as recommended by Parallax. 
For greater noise immunity, I recommend pulling up to the SRF08's 5v supply instead (so as not to place any more load on the BS2) and using 1k8 resistors.

Displaying Firmware Revision, Light Sensor and Range readings in a PC Debug window
The following sample code will display the firmware revision, light sensor reading (SRF08 only) and the range reading, in a Debug window on the PC .
The sample code below can be downloaded here.

'{$STAMP BS2p}
'**                                                       **
'**       I2C Routines for the Basic Stamp BS2p           **
'**  with the SRF08, SRF10 and SRF235 Ultrasonic Rangers  **
'**                                                       **
'**             Copyright 2005 - Devantech Ltd            **
'**     Commercial use of this software is prohibited     **
'**     Private and educational use only is permitted     **
'**                                                       **
'**        Written by Gerald Coe - February 2005          **
'**                                                       **
'   Connect P8 (pin13) of the BS2p to the SRFxx SDA
'   Connect P9 (pin14) of the BS2p to the SRFxx SCL
'   Use 4k7 pull-up resistors from SCL and SDA to 5v supply
SDA     CON 8           ' SDA on pin13, SCL on pin14
Ver     VAR Byte
Light   VAR Byte
Range   VAR Word        ' range
  I2COUT SDA, $e0, 0, [81]    ' Rangeing command - 80 for inches, 81 for cm, 82 for uS
  PAUSE  100
  I2CIN  SDA, $e1, 0, [Ver, Light, Range.HIGHBYTE, Range.LOWBYTE]
  DEBUG  2,0,1, "BS2p to SRF08, SRF10 or SRF235 "
  DEBUG  2,0,3, "Firmware Version ", DEC Ver, "    "
  DEBUG  2,0,4, "Light Sensor ", DEC Light, " (SRF08 only, Reads 128 on the others)   "
  DEBUG  2,0,5, "Range ", DEC Range," cm      "
  GOTO   Loop