PDA

View Full Version : Sharp GP2D02



Alby
- 7th January 2005, 21:33
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

mister_e
- 7th January 2005, 21:57
as a start http://www.mcselec.com/download/appnotes/gp2d02.pdf

based on BasicStamp... easy to translate now.

Alby
- 12th January 2005, 00:30
Thanks for the note Steve, Will check it out
Cheers
Alby

sundaecone
- 11th July 2005, 12:20
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.. :)

Martin....
- 6th November 2008, 19:18
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


@ 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

DanPBP
- 8th March 2009, 09:09
I know this thread is old, but I just wanted to reply with a working code:



sensor_value var byte

high sensor_clock
pause 3
low sensor_clock
pause 70
shiftin sensor_data,sensor_clock,2,[sensor_value\8]