SRF08 Ultrasonic Rangefinder


Closed Thread
Results 1 to 5 of 5
  1. #1
    rad's Avatar
    rad Guest

    Default SRF08 Ultrasonic Rangefinder

    Hello,

    Have any of you written a program using the new-ish commands,
    I2CREAD and I2CWRITE ?

    I cannot get them to work properly, so far. I have a working Nuts and Volts Stamp program that works perfectly. If any of you want to help translate, please respond. Thanks.

    When I view the stamp output on an oscilloscope, it is rock steady, as far as the signal goes, and it seems to put out one set of needed pulses.

    However, when I try to look at the output train of pulses from the I2CWRITE picBasic command, I seems to get two sets of pulses from this one command. And the signal is jagged and weakish compared to the stamp out put.

    So, first, what's up with what the picBasic command? What is it trying to do and what about the signal, do I need to filter it somehow to get a cleaner output?

    Thanks.

    I'm just measuring the output from

    I2CWRITE dat,clk,0,0,[$50]


    thanks

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I don't know what you're trying to do with I2CREAD and ICCWRITE, but it looks to me that you're using these commands in the wrong context or application.

    PBP's I2CRead/Write are used to interface to other I2C bus compatible devices such as Serial EEPROM (eg 24LC16, 24LC32 etc), Real Time Clocks - RTC's (eg DS1307) and anything else that you can find that's I2C compatible.

    Two Sets of pulses are provided because one is the Clock against which the other (the Data) is synchronised.

    As long as you remember the recommended pull-up resistors, I2CRead/Write work as advertised and have no known issues.

    Now, I don't have the Nut's n Volts article but I'm sure you're using these commands for the wrong purpose. What exactly are you trying to do/achieve? Come back and tell us what you're doing with the Stamp and perhaps we'd be able to recommend a more suitable command to use.

    Melanie

  3. #3
    rad's Avatar
    rad Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Melanie for the reply.

    I should have been more descriptive.

    This SRF08 device is a 'new and improved' version of the familiar rangefinder and it is accessed thru the I2C bus.

    For some reason, I haven't been able to find the right values to use with the I2CWRITE command to match up with what my Stamp program produces, using a more bit banging approach.

    I have translated this into picbasic, basic, and it works fine. And it looks the same on the scope, or is close to what the stamp does.

    The thing works now, so it's no big emergency. But I would like to reduce my program to two lines using the handy features of I2CWRITE AND READ.

    I was first using an 18F452 and have now switched to a 16F877 which works much better. The 18F452 was very noisy for some reason. I was using 1K pull up resistors. Which worked fine for the Stamp and the 16F877


    http://www.acroname.com/robotics/parts/R145-SRF08.html
    http://www.nutsvolts.com/toc_Pages/jul03toc.htm
    (Stamp Application)

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The only thing those links didn't give you was the I2C accessible Address and Register Map for the SRF08 which is what you need to play with PBP's I2C commands. A quick dogpile search found something more useable here...

    http://www.robot-electronics.co.uk/htm/srf08tech.shtml

    From that you can see the default address is $E0 and you've got 36 registers to play with and access...

    So use your I2C command like this...

    SRFAddress var byte
    MyByte var byte
    SRFAddress=$E0
    .. ..
    I2CRead Datapin,Clockpin,SRFAddress,$00,MyByte

    This should read the Software Revision (Register Address $00) into the variable MyByte. From that you can work out how to send the appropriate I2CWRITE command to the SRF08 to initiate a ranging, wait 65mS, and the read back the results with an appropriate I2CREAD.

    Melanie

  5. #5
    rad's Avatar
    rad Guest


    Did you find this post helpful? Yes | No

    Default

    DEFINE LOADER_USED 1
    DEFINE OSC 20
    DEFINE I2C_HOLD

    cmdInch CON $50

    clk VAR PORTB.0
    dat VAR PORTB.1
    devAddr VAR BYTE
    regAddr VAR BYTE
    d VAR WORD

    TRISB = 1

    devAddr = $E0 ' device address, default
    regAddr = $00 ' command register 0

    loop:
    regAddr = $00 ' command register 0
    I2CWRITE dat,clk,devAddr,regAddr,[cmdInch]
    pause 70
    regAddr = $02 ' $02 high byte of echo 1, $03 low byte
    I2CREAD dat,clk,devAddr,regAddr,[d] ' read echo 1 result into word var d

    serout2 portc.6, 16468, [dec d.lowbyte,13,10] ' display address $03 low byte of echo 1
    goto loop
    END

    Melanie,
    OK this works. I'm not sure about the I2C_HOLD command, it doesn't work without this. But everything else was only a problem of getting at the low or high byte and/or figuring out what the WRITE and READ command needed.

    The manual calls my 'devAddr' the 'control' byte. That confused me, but of course I haven't read anything about I2C in general. So maybe that's the problem.

    Thanks Melanie, -- Happy Regards.

Similar Threads

  1. Replies: 23
    Last Post: - 23rd September 2008, 18:20
  2. the ultrasonic SRF04 with pic16f88
    By tur_bot in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 20th March 2008, 17:24
  3. Water Level Detection using Ultrasonic Sensor
    By Balachandar in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th November 2007, 04:59
  4. sensor ultrasonic 8051&PIC
    By hd_uni_pro in forum Schematics
    Replies: 1
    Last Post: - 13th September 2006, 12:58
  5. ultrasonic sensor
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th May 2006, 20:26

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