Shop OBEX P1 Docs P2 Docs Learn Events
using SRF02 sensor w/ BASIC stamp HELP — Parallax Forums

using SRF02 sensor w/ BASIC stamp HELP

trucutrutrucutru Posts: 4
edited 2009-02-09 02:27 in BASIC Stamp
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:

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-02-09 02:27
    You need to write routines to send and receive I2C data to the ranger. The bs2p versions have built in commands to do this but not the other stamps. There probably is an article in the nuts and volts section to do this but I have never looked it up.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.