Sharp GP2D02


Closed Thread
Results 1 to 6 of 6

Thread: Sharp GP2D02

  1. #1
    Alby's Avatar
    Alby Guest

    Default Sharp GP2D02

    I am trying to use the sharp sensor with a sumo robot and I cannot seem to read the information from it. I am programming in pic basic and It seems I need to read the 8 bit serial data from the sensor, store it and then read it to interpret it. For now I 'd be happy to show it on an lcd screen.
    Can anyone point me to some more info on the serin commmand and how to figure this out
    Thanks
    Alby

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    as a start http://www.mcselec.com/download/appnotes/gp2d02.pdf

    based on BasicStamp... easy to translate now.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Alby's Avatar
    Alby Guest


    Did you find this post helpful? Yes | No

    Default Sharp GP2D02

    Thanks for the note Steve, Will check it out
    Cheers
    Alby

  4. #4
    sundaecone's Avatar
    sundaecone Guest


    Did you find this post helpful? Yes | No

    Default

    uhm.. if it's not too much.. could somebody please help me with the programming? i'm using assembly..

    i'll be happy just to be able to output the measurement in PORTB.. i made a code but apparently, it doesn't work.. i already searched other forums and so far this is the only one with a hit..

    thanks in advance..

  5. #5
    Join Date
    Jun 2006
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Translation

    Hi

    I translated the code.
    The Sensor IR works but I canīt read the Result.
    Has anybody ever tested this Code ?
    I see the result by the blinking of a LED.
    Even with the oscilloscope I got no Result.

    Martin


    Here is what I translated
    Code:
    @ DEVICE INTRC_OSC_NOCLKOUT, MCLR_OFF
    DEFINE OSC 4
    
    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA	90h
    
    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA	20h
    
    ' Set baud rate
    DEFINE HSER_BAUD	9600
    
    ' Set SPBRG directly (normally set by HSER_BAUD)
    DEFINE HSER_SPBRG	25
    
    
    
      
    Vo 		VAR     PORTB.6		' ---->sensor Input
    Vin 	VAR     PORTB.7		' <----sensor Output
    SERVO	VAR		PORTB.5		' Servo Motor
    LED		VAR		PORTB.0		' LED control
    i		VAR		BYTE		' loop variable
    Dist	VAR		BYTE		' result of measurement		
    
    ' -----[ Initialization ]---------------------------------------------
    '
    init: 
    TRISB  	= %10000001			' designate portb as output
    PORTB  	= 0        			' clear portb 
    Dist   	= 0
    Input Vin
    High LED
            
    ' -----[ Main Loop ]--------------------------------------------------
    '
    start:
    GoSub sensor_control
    GoSub LED_Distance
    GoTo start
    ' -----[ Subroutines ]------------------------------------------------
    '
    sensor_control:
    Dist = 0
    Low Vo
    Pause 72
    For i = 0 TO 7
    	PulsOut Vo,15
    	Dist = Dist * 2 + Vin
    	'HSerout [DEC Dist]
    	Next i
    High Vo
    Pause 3
    Low Vo
    Return        
           
           
    LED_Distance:
    
    IF 			   (Dist > 147) Then PWM LED, 13,2 >10	    5%
    IF (Dist < 147) AND (Dist > 119) Then PWM LED, 26,2	'10-15	10%
    IF (Dist < 118) AND (Dist >  91) Then PWM LED, 38,2	'15-20	15%
    IF (Dist <  90) AND (Dist >  81) Then PWM LED, 51,2	'20-25	20%
    IF (Dist <  80) AND (Dist >  71) Then PWM LED, 64,2	'25-30	25%
    IF (Dist <  70) AND (Dist >  65) Then PWM LED, 77,2	'30-35	30%
    IF (Dist <  64) AND (Dist >  55) Then PWM LED, 89,2	'35-40	35%
    IF (Dist <  54) AND (Dist >  50) Then PWM LED,102,2	'40-45	40%
    IF (Dist <  49) AND (Dist >  47) Then PWM LED,115,2	'45-50	45%
    
    IF (Dist <  46) AND (Dist >  44) Then PWM LED,140,2	'50-60	55%
    IF (Dist <  43) AND (Dist >  42) Then PWM LED,166,2	'60-70	65%
    IF (Dist <  41) AND (Dist >  40) Then PWM LED,191,2	'70-80	75%
    IF (Dist <  40) 				 Then PWM LED,217,2	'>80	85%
    Return

  6. #6


    Did you find this post helpful? Yes | No

    Default

    I know this thread is old, but I just wanted to reply with a working code:

    Code:
    sensor_value var byte
    
    high sensor_clock
    pause 3
    low sensor_clock
    pause 70
    shiftin sensor_data,sensor_clock,2,[sensor_value\8]

Similar Threads

  1. Sharp ir distance sensor
    By hasnannordin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th October 2009, 21:48
  2. Sharp GP2D12 Range Finder???
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th December 2007, 09:21
  3. need help on GP2D02...newbie
    By capix in forum mel PIC BASIC
    Replies: 1
    Last Post: - 4th March 2006, 09:57
  4. Need help GP2D02
    By capix in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th December 2005, 10:41
  5. GP2D15 sharp
    By chip_1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th May 2005, 07:45

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