Shop OBEX P1 Docs P2 Docs Learn Events
Is it possible to use a sharp IR ranger with BS2 without an AD converter — Parallax Forums

Is it possible to use a sharp IR ranger with BS2 without an AD converter

vla7vla7 Posts: 79
edited 2008-03-10 20:17 in BASIC Stamp
I bought a Sharp GP2D120 IR Ranger and want to connect to my BOE BOT to allow it to follow a wall in order to navigate through a maze.· I have no idea how to connect or program this thing.· I came across some literature by "Nuts and Volts" where they connect it to an analog-to-digital converter first (the ADC0831).· I dont have this converter and was wondering·if I really need one or is there a way to accomplish my task without an AD converter.· I would appreciate any advice someone can give on how to go about this task.

Thanks.

Comments

  • UghaUgha Posts: 543
    edited 2008-02-14 02:16
    I'm not sure... Have you considered using normal IR LEDs and receivers?

    And if you do want the part, I found something very much like it for sell rather cheap:
    ADC0831CCN

    http://www.futurlec.com/ICADC.shtml
  • vla7vla7 Posts: 79
    edited 2008-02-14 12:56
    I have tried using normal IR LEDs and receivers but the closest reading I can get is about 4 inches away from a wall.· I would like something a little more sensitive that can distinguish between the 1 and 4 inch distance.· If anyone knows how to accomplish this with regular IR LEDs please let me know.
  • quickster47quickster47 Posts: 35
    edited 2008-02-14 12:57
    Take a look at HVW Technologies. They have some modified Sharp IR rangers that work really great.

    http://www.hvwtech.com/products_list.asp?CatID=114&SubCatID=148&SubSubCatID=0

    Carl
  • ZootZoot Posts: 2,227
    edited 2008-02-14 13:29
    Since the Sharp puts out ~3v at it's peak, you could set up an RCTIME circuit to measure the voltage. Here's a brief snapshot (and see the Pbasic manual under RCTIME) and follow the link to Tracy Allen's site which has good info on using RCTIME to measure analog voltages.

    Remember you will still have to "linearize" the readings (whether you use RCTIME or an ADC) -- the Sharps output a curve with respect to distance.

    http://forums.parallax.com/showthread.php?p=698218

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • vla7vla7 Posts: 79
    edited 2008-02-14 14:45
    I noticed from the Acroname website that there is also a Sharp GP2D15 which is a digital version of the the IR Detectors. If I would have bought the digital version would I not need to have an AD converter? If so, what is the advantage of buying an analog IR Detector when you can just get a digital one?
  • ZootZoot Posts: 2,227
    edited 2008-02-14 14:48
    "Digital" means Yes/No at a preset distance threshold.

    Analog IR rangers let you get a very precise distances, at resolutions of less than a centimeter.


    Somebody said...
    This sensor takes a continuous distance reading and returns a logic value corresponding to object detection with a pre-set range of 24 cm (10").

    So you get a "yes/no" answer to the question: "is the obstacle closer than 10" or not?"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • vla7vla7 Posts: 79
    edited 2008-02-14 16:33
    so do I really need an AD converter to be able to use my Analog IR ranger with my basic stamp to tell how close I am to an obstacle?
  • alecalec Posts: 2
    edited 2008-02-14 16:51
    Yes, you need an ADC to use the analog version. Sharp also has one with a digital output that sends an encoded serial stream that you can read with Serin to get precise position. John Williams had a great Nuts and Volts Stasmp Application column that dealt with the analog sensor and an ADC- column #114 and you can download it from the Parallax website.
    Have fun - Alec
  • ZootZoot Posts: 2,227
    edited 2008-02-14 17:10
    You do not *have* to use an ADC -- you can use RCTIME. May not be as stable nor as fast to take a measurement, though, and you'll need to experiment with your R and C values to get the best balance between speed of the reading and accuracy/stability. One- and two-channel ADCs are cheap and common, though, and it never hurts to have a few lying around (they are useful for many, many things besides IR rangers).

    The Sharp rangers that provide a SPI (using SHIFTIN) serial interface are a bit pricier (basically these rangers include an on-board ADC), and, in my humble opinion, have one serious weakness -- the time from initiating a reading to getting one back can be in the 50ms-70ms range -- in other words your Stamp will be waiting on the reading that whole time. Those rangers do have one big plus, though -- they use much much less current as they are only "on" when a reading has been initiated.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • vla7vla7 Posts: 79
    edited 2008-02-14 19:27
    thanks
  • NoiseMantraNoiseMantra Posts: 4
    edited 2008-03-07 18:41
    The trick to interfacing the Sharp sensor (or any voltage-output analog sensor) with the BS2,
    without using an A/D converter, is to make the sensor look like a resistive sensor.
    Here's a simple way to do this:

    www.noisemantra.com/BASICStampAnalogInput.htm

    With the circuit shown on this webpage, you can use the RCTIME
    command to read data from the Sharp distance sensor.

    - Chris
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-03-07 19:18
    Chris,

    Your circuit should work, and your inclusion of that diode to cover the lower 0.6V of the output range is clever (assuming the sensor remains accurate with a 4.4V supply). But, as you point out in the linked-to page, the circuit is highly dependent on the transistor's gain, which can vary from device to device and with temperature. From my point of view, it's hard to understand any reluctance to incorporate an A/D converter for these kinds of apps. It's not like they're expensive or take up a lot of room (probably less room than the five discrete components in your schematic). Plus, you get something that's designed from the ground up to be accurate and stable.

    -Phil
  • NoiseMantraNoiseMantra Posts: 4
    edited 2008-03-08 15:24
    Actually now that I think about it, adding the diode to the ground lead of the sensor
    increases the temperature stability of the circuit (as long as the diode and transistor
    are kept at the same ambient temperature).

    Also I came up with a variation on the original circuit which will be
    much less sensitive to component (and temperature) variations.
    It is shown at the bottom of the same web page:

    www.noisemantra.com/BASICStampAnalogInput.htm

    Using an A/D converter may give you a lower part count, but probably not pin count,
    and the code required to support one is significantly more complex.
    If absolute accuracy is not needed, I still present this as a viable and easy solution.

    - Chris
  • BeanBean Posts: 8,129
    edited 2008-03-08 15:51
    Chris,
    In the first circuit, couldn't the 100K resistor value be changed to account for differences in transistor gain ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-03-08 15:58
    NoiseMantra,

    I presented·this/that circuit a year or two ago in a similar context.

    ADC_lite.jpg

    The member asked if an ADC was essential and obviously it's not.

    Post Edit -- I could point to a "circuit", on the Forum, where the guy is using an ADC to "read" the output of a comparator.


    Post Edited (PJ Allen) : 3/8/2008 4:05:14 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-03-08 17:35
    NoiseMantra,

    Have you tried your second circuit on the bench? I think it could run into trouble at high sensor outputs, in that the capacitor may not discharge fully enough to register as a low to the Stamp. PJ's selection of resistor values seems more dependable in that regard, though it is slightly more gain-sensitive.

    Another way to reduce the gain sensitivity is to use a matched pair of transistors and bias one with a constant voltage. Then compare readings from both. But that's another Stamp pin and more parts...

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-03-08 20:44
    A less temperature- and gain-dependent method would be to incorporate a comparator and do your own successive approximation (SAR) ADC in software:

    attachment.php?attachmentid=52627

    Total hardware cost for this circuit can be as low as fifty cents in quantity, possibly less. With an SOT23-5 comparator, the PCB footprint is minimal.

    The Stamp sends various duty cycles to the pout pin, using PWM, until (by reading the cin pin) it's able to tell where the comparator inputs are nearly equal. From there, it can calculate an input voltage with eight-bit precision.

    Here's a program that does this, using both a binary search and a linear search. The binary search is quicker, but the measured voltage must be constant during the entire measurement interval. The linear search is not so quick, especially with high sensor voltages, but it's more forgiving when that voltage varies slightly during the measurement interval.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    pout  PIN 10
    cin   PIN 11
    
    volts VAR Word
    pos   VAR Nib
    delta VAR Byte
    
    DO
      GOSUB Binary
      GOSUB Print
      GOSUB Linear
      GOSUB Print
      DEBUG CR
    LOOP
    
    Binary:
    
      volts = 0
      FOR pos = 7 TO 0
        delta = 1 << pos
        volts = volts + delta
        PWM pout, volts, 40
        IF (cin = 0) THEN volts = volts - delta
      NEXT
      RETURN
    
    Linear:
    
      FOR volts = 0 TO 255
        PWM pout, volts, 3
        IF (cin = 0) THEN EXIT
      NEXT
      RETURN
    
    Print:
    
      volts = volts * 100 / 51
      DEBUG DEC volts / 100, ".", DEC2 volts // 100, " "
      RETURN
    
    
    


    I tried this code using a 500-ohm trimpot to produce the "sensor" voltage. The comparator was an LM393. I had to power it from Vin, since its input common mode range only goes up to the supply voltage - 1.5V. The results agreed rather well with the voltage measured via a voltmeter.

    A true SAR ADC would include sample-and-hold circuitry for the voltage input, which one could easily do with an analog switch and another capacitor. But if you're going to go to all that trouble, you might as well use an integrated ADC.

    -Phil
    447 x 233 - 2K
  • DgswanerDgswaner Posts: 795
    edited 2008-03-10 04:15
    Can I steer this thread in a different but related direction? I also just purchased some Sharp IR sensors, and want to get them working, it looks like the RCtime Method has been covered pretty well, but I have never used an ADC, I have no idea which one to use or even what to look at when deciding on which ADC to use. I was hoping to find a sample circuit from sharp but I haven't found one yet. can some one provide information on connecting them using an ADC?

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

    DGSwaner
  • NoiseMantraNoiseMantra Posts: 4
    edited 2008-03-10 16:03
    Phil,
    I did test both circuits on the bench and they worked for me; but you are right about the potential for problems at higher input voltages. Originally I left out the base resistor on the second circuit and, as you anticipate, at input voltages above about 2.3V the B-C junction becomes forward biased and the capacitor will never discharge to the required 1.3V. Your SAR circuit is a nice approach as well.

    PJ,
    I’m always happy to reinvent the wheel! idea.gif
    Was that circuit posted on a Parallax forum?

    Dgswaner,
    I’ve posted instructions on interfacing the BS2 to a PCF8591 I2C A/D D/A converter here:
    astro.temple.edu/%7Ecvecchio/PCF8591%20I2C%20example.htm
    But if anyone has examples or recommendations for interfacing with other A/D converters, I love to hear them.
    I suspect that if I had used an SPI rather than an I2C A/D converter, it might have made the software end of things simpler.

    - Chris
  • MSDTechMSDTech Posts: 342
    edited 2008-03-10 20:17
    Parallax sells the LTC1298, and has provided documents, wiring diagrams and code:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/appkit/ltc1298.pdf

    I'm currently running several analog sensors in the Weather Station I'm building and have used 3 different ADC's in the process. The are fairly easy and cheap, also easy to calibrate.
Sign In or Register to comment.