Shop OBEX P1 Docs P2 Docs Learn Events
How to interface PING sensor to AVR (ATmega168)? — Parallax Forums

How to interface PING sensor to AVR (ATmega168)?

XNORXNOR Posts: 74
edited 2008-07-02 18:57 in Robotics
Hi,

How do I use the Parallax PING sensor with an AVR? confused.gif
Specifically, the ATmega 168 using WinAVR (a gcc C-compiler and library).

The Parallax code uses the Serial commands of the Basic Stamp,
but I don't know how to implement this for the ATmega168.

I'm guessing this has been done before, but I couldn't find
a link that was simple enough for me to understand.
(It seems that many people did "bit-banging" using assembly language.)

Thanks for any help!
smile.gif

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-07-01 19:41
    You send a PING sensor a pulse on the data pin, from 2 uSec to 5 uSec wide. You then 'listen' to the data pin (turn that pin to an input) and measure the size of the pulse that is returned on that pin. There's a 750 uSec delay from the end of the 5 uSec pulse to give your program time to 'set up' for the "size indication" pulse.

    I assume the AVR has library code to generate a fixed size pulse, and another library call to measure a pulse-width on an input pin.
  • XNORXNOR Posts: 74
    edited 2008-07-02 16:06
    Hi,··

    Thanks for the reply, but I made a stupid mistake.··blush.gif··

    I meant to ask about the Sharp IR distance sensor:··

    http://www.parallax.com/dl/docs/prod/acc/SharpGP2D12Snrs.pdf

    The code I'm having trouble with is the SHIFTIN command below:··
    Read_GP2D12: 
       volts = 0                  'Reset Sensor Value 
       FOR index = 0 TO 2         'Read 3 Times 
          LOW Adc0831             'Enable ADC0831 
          [b][u]SHIFTIN[/u][/b] AdcData,AdcClock,MSBPOST,[noparse][[/noparse]result\9]  'Read The Voltage 
          HIGH Adc0831            'Disable ADC0831 
          volts = volts+result    'Add The Values 
          PAUSE 30 
       NEXT 
       volts = volts/3            'Average The Readings 
       RETURN 
     
    

    How do I convert the SHIFTIN into C?·· confused.gif··

    Thanks again for any help!· blush.gif··

    ··
  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-02 16:30
    That's a more complicated problem and one that doesn't involve any Parallax products, so it's really inappropriate for these support forums.

    The ADC involved uses a protocol called SPI which is very common. Check the ADC manufacturer's website for datasheets and application notes. You may find a ready-to-go driver in C. Also check Atmel's website and support documents and you will probably find drivers in C for the ATmega168. The ADC datasheets usually include a detailed description of the signals necessary for doing an analog to digital conversion including diagrams of the signals involved.

    Post Edited (Mike Green) : 7/2/2008 4:35:45 PM GMT
  • FranklinFranklin Posts: 4,747
    edited 2008-07-02 18:57
    Go here to start. The Arduino uses a atHega168 www.arduino.cc/playground/Main/ReadGp2d12Range

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