Questions on ultrasonic distance finder


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jellis00 View Post
    The one I have had a lot of success with is the SRF02. . . . If you decide to use this product, let me know and I can share some PBP code with you that has been pre-tested to work with the SRF02.
    I'm going to be working with the SRF02. I'd be interested in knowing what you developed. I assume it was I2C and not serial?
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default A SRF02 routine

    Quote Originally Posted by RussMartin View Post
    I'm going to be working with the SRF02. I'd be interested in knowing what you developed. I assume it was I2C and not serial?
    I am attaching a routine I use as an Interrupt Service handler with Darrel Taylor's DT_INTS-18.bas. Whenever the interrupt is received it executes this routine to take an ultrasonic range measurement, display it to LCD, and log it to EEPROM.

    Note that I am using an I/O pin from the MCU to turn on and off power to the SRF02. Whenever the SRF02 is turned off but still connected to the I2C bus it will distort the bus and prevent use of any other devices that are connected to I2C. Therefore, just before and after you want to use the I2C bus for any device, you will have to turn on or off the SRF02. I did this to save battery power so I didn't have to keep the SRF02 continuously powered up.
    Hope this works for you.
    Code:
    Range:
        HIGH ext_pwr ' Temporarily turn on power to SRF02 for I2C bus use
        PAUSE 500    ' Delay to let I2C bus stabilize after SRF02 turn on 
        'DEFINE WRITE_USED 1 'Required if only writing WORD variables in v2.6
        ' Update day counter and address offset for day's measurements
            READ 9,day_cnt        ' Test if EEPROM data has been captured
                                  ' & cleared by PC & new monthly epoch
                                  ' started.
            day_cnt = day_cnt + 1  ' Increment day counter
            Write 9,day_cnt 'Update contents of day_count memory address
            Pause 10
            If J >= 240 Then
               J = 0    ' If allocated EEPROM already used, start over
            ENDIF
        ' Make SRF02 Range Measurement           
            I2CWRITE SDA,SCL,$E0,0,[80]  ' Request start of ranging in inches
            pause 100                    ' Wait for ranging to finish
            I2CREAD SDA,SCL,$E0,2,[rng1,rng0] ' Get ranging results                         
            'WRITE 253,rng1               
            'Write 254,rng0
            WRITE 240,Word w0            ' Write range to EEPROM       
        ' Display time & range measurement on LCD display in inches  
            LCDOut $FE,1:FLAGS=0:Pause 250 ' Clear Display
            I2CREAD SDA, SCL, RTCdevice, SecReg,[sec,MINs,hr,day,date,mon,yr]       
            LCDOUT $fe,1
            LCDOUT $fe,Line1,Hex2 mon,"/",hex2 date,"/",hex2 yr
            LCDOUT $fe,Line2,hex2 hr,":",hex2 MINs,":",hex2 sec
            Pause 2000                   ' Allow Time for user to view
            LCDOUT $FE,1
            LCDOut $FE,Line1,"Range:"    ' Display on 1st line
            LCDOut $FE,Line2,#w0," in."  ' Display on 2nd line
            PAUSE 5000                   ' Allow Time for user to view
        ' Clear STATUS register & Alarm flags..ready for next interrupt             
            I2CWrite SDA, SCL, rtcdevice, StatusReg,[$00]           
        LOW ext_pwr  ' Turn off power to the SRF02 at end of display.
                     ' This statement will distort the I2C bus and ext_pwr
                     ' must be set HIGH again before any attempts are made to
                     ' use the I2C bus.
        ' Store range as date-stamped value in EEPROM
            WRITE 17+J,WORD w0          'Store day's range in EEPROM
            PAUSE 10
            Write 16+J,date             ' with day of month date-stamp
            PAUSE 10
        ' Step pointer to next logging address in EEPROM
            J = J + 3
            WRITE 10,J   'Update contents of J index EEPROM memory address
            Pause 10                             
        PAUSE 470        ' Delay to permit I2C bus to stabilize after SRF02 off   
        ' Resume Main Program 
    @ INT_RETURN

Similar Threads

  1. Ultrasonic distance sensor with PIC16F84A
    By MrRoboto in forum mel PIC BASIC
    Replies: 3
    Last Post: - 29th June 2009, 09:01
  2. Sharp GP2D12 Range Finder???
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th December 2007, 09:21
  3. sensor ultrasonic 8051&PIC
    By hd_uni_pro in forum Schematics
    Replies: 1
    Last Post: - 13th September 2006, 12:58
  4. ultrasonic sensor
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th May 2006, 20:26
  5. SRF04 Range Finder 16F628 R18iXL Board
    By Spindle in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 02:08

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts