Shop OBEX P1 Docs P2 Docs Learn Events
UltraSonic range finder — Parallax Forums

UltraSonic range finder

Armored CarsArmored Cars Posts: 172
edited 2004-10-20 19:20 in BASIC Stamp
Does any one know how to communicate with the SRF08 or SRF04?

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-19 14:05
    Yes.· Which one?· The SRF-04 uses a PULSIN interface; the SRF-08 (my preference) uses I2C.· I've attached simple BS2 demos for each.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • MatthewMatthew Posts: 200
    edited 2004-10-19 15:44
    How about the Polaroid one?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-19 16:05
    I've never used the Polaroid sensor; but you can find a lot of information on it on the Internet. Google is your friend.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Armored CarsArmored Cars Posts: 172
    edited 2004-10-19 17:59
    I think Ill stick with the 04, it looks alot simpler to program.· Thanks for the programs.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-19 18:25
    Trust me, that sensor is a pain in the backside... Go with the -08 if cost is not a problem. It does the distance calculations for you, and lets you connect more than one unit to the same set of wires.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Armored CarsArmored Cars Posts: 172
    edited 2004-10-19 19:14
    Im having trouble understanding the code for the 08, wich brings up a few other questions I had.

    What is the PIN command? (Ive never heard of it)

    The basic stamp is divided up into 5 sections, in know pins 1-16 are divided into A-D. In a program I saw it was reading pins 12 and 13 and used the command

    SPEED= (IND & %0011)

    to get 0, 1, 2, or 3 out of any combination if pins 13 and 14. I get what the result is, but Im not sure what the & actually does with the %0011.

    Same question goes for

    MODE= (IND >> 2)

    wich reads pins 14 and 15 and also converts to a number 0-3. There is no explination of what >> does.

    Ill study the 08 program tonight and see what I can figure out.
  • Shawn LoweShawn Lowe Posts: 635
    edited 2004-10-19 21:29
    The explaination of the >> operator is in the help file, you can look under the index or look in the mathimatical operators section
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-19 22:07
    PIN (new in PBASIC 2.5) is not a command, it's a type: it allows you to define an IO pin. Why is this important? Because some elements of the language want a pure numeric value for the pin (e.g, 1 for P1), others want the input register bit (e.g., IN1 for P1), and finally, some elements of the language want the output bit (e.g., OUT1 for P1). Before the PIN definition some programs required redundant definitions for the same physical IO pin.

    %0011 is a 4-bit binary notation for the value 3. In the case you cited, it is being used as a mask value so that only bits 0 and 1 (pins 12 and 13) of that port IND (pins 12, 13, 14, and 15) are evaluated. The other bits, being ANDED with 0, get ignored.

    >> is the right shift operator (see chapter 4 of the manual, or the operator section of the help file). It shifts a value n number of bits. For example, %1100 >> 2 = %0011.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • cabojoecabojoe Posts: 72
    edited 2004-10-20 11:08
    Another cool feature of the 08 is that you can set a register that controls how long the reciever will wait for the ping...so instead of ranging out to 6 meters·or so, you can set it to only range say 1 meter, which is perfect for obstacle avoidance. Doing so takes way less time to do, so you can make alot more measurements in the same amount of time. The 08 also has 2 light sensors onboard.
  • Armored CarsArmored Cars Posts: 172
    edited 2004-10-20 18:56
    I dont think I can program it. I can follow the flow of the program, but I dont know what anything is doing. It looks too long also, the program needs to run faster for what I need.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-10-20 19:20
    You might want to consider the BS2p then, as it has I2C functions built-in and is our fastest BASIC Stamp (3x speed of a stock BS2).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.