using SRF02 sensor w/ BASIC stamp HELP
trucutru
Posts: 4
Hey there, I am trying to use the ultrasonic sensor SRF02 from DEVANTECH, http://www.robot-electronics.co.uk/htm/srf02techI2C.htm , this device can work with the i2c bus in the basic stamp 2. I wrote some code but I am at a lost about how to command the microcontroller to tell the slave srf02 (which its address is set to the default address ) to start ranging in inches. Also how would I write the code for assigning a different address to a second SRF02. I am just looking for some guidance, I'll keep trying to fix my code,
thanks,
Tru
' {$STAMP BS2}
' {$PBASIC 2.5}
'Author: Antonio Corzo
'Group: Pinkesh Patel, Gil Hernandez, and Pinkesh Patel
'Subject: ECET 402 Senior Proj. 2 - Electronic cane
'Objective: Interface sensors
'I/O definitions
SDA PIN 15
SCL PIN 14
'Constants
RangInch CON 80
RangCm CON 81
ACK CON 0
NOACK CON 1
'Variable
i2cDATA VAR Byte
i2cACK VAR Bit
i2cDATaddr VAR Byte
INITIALIZE:
i2cDATA=%11111111
DEBUG CLS,"PC says:..."
IF (i2cAck = ACK) THEN Main
DEBUG "ERROR: NO DEVICE FOUND"
Main: 'Main program
DO
PAUSE 1000
GOSUB startI2C
i2cDATaddr=224
RangInch 'I get an error over here which says "expected label variable or instruction"
READ 0x02, i2cDATA 'I suppose I have to write this in decimal or binary
LOOP
startI2C: 'Starting I2C SDA hi-lo while SCL hi
HIGH SDA
HIGH SCL
LOW SDA
LOW SCL
RETURN
stopI2C: 'Stopping I2C SDA lo-hi while SCL hi
LOW SDA
HIGH SCL
HIGH SDA
RETURN
ACK_NOACK:
thanks,
Tru
' {$STAMP BS2}
' {$PBASIC 2.5}
'Author: Antonio Corzo
'Group: Pinkesh Patel, Gil Hernandez, and Pinkesh Patel
'Subject: ECET 402 Senior Proj. 2 - Electronic cane
'Objective: Interface sensors
'I/O definitions
SDA PIN 15
SCL PIN 14
'Constants
RangInch CON 80
RangCm CON 81
ACK CON 0
NOACK CON 1
'Variable
i2cDATA VAR Byte
i2cACK VAR Bit
i2cDATaddr VAR Byte
INITIALIZE:
i2cDATA=%11111111
DEBUG CLS,"PC says:..."
IF (i2cAck = ACK) THEN Main
DEBUG "ERROR: NO DEVICE FOUND"
Main: 'Main program
DO
PAUSE 1000
GOSUB startI2C
i2cDATaddr=224
RangInch 'I get an error over here which says "expected label variable or instruction"
READ 0x02, i2cDATA 'I suppose I have to write this in decimal or binary
LOOP
startI2C: 'Starting I2C SDA hi-lo while SCL hi
HIGH SDA
HIGH SCL
LOW SDA
LOW SCL
RETURN
stopI2C: 'Stopping I2C SDA lo-hi while SCL hi
LOW SDA
HIGH SCL
HIGH SDA
RETURN
ACK_NOACK:
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen