Sharp GP2D02 and servos
haunteddansion
Posts: 68
I was looking at the posted code (at the bottem) and I was wondering how I would go out interfacing the distance mesured with the motion of a servo? Thanks for the help!
' {$STAMP BS2}
'
' variable declarations
val05· VAR· Byte· ' value where reading is stored
i· VAR· Byte· ' count variable for loop
'
' constant declarations
cl· CON· 14· ' pin 14 is output (clock)
dt· CON· 15· ' pin 15 is the input (data)
'
' I/O pin setup for detector
INPUT dt··· ' make pin 15 the input
HIGH cl····· ' make pin 14 output and high
DEBUG "Start", CR· ' indicate beginning
FOR i = 1 TO 40
· GOSUB read05··· ' take reading
· DEBUG DEC val05, CR· ' display result
· PAUSE 100··· ' stall so display readable
NEXT
DEBUG "Finish", CR· ' indicate end
END····· ' stop Stamp when done
'
' subroutine read05
'
' This subroutine takes a reading from the connected
' GP2D05 detector and stores the value in "val05".
' Any two pins can be used.· Set "dt" to the data line
' of the GP2D05 (pin 3 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D05 (pin 1 on the
' JST connector, green wire).· Also, the IN15 needs
' to be set to the correct variable for the data pin
' (data line).
read05:
· LOW cl··· ' turn on detector for reading
· PAUSE 56··· ' wait 56ms for detector to read
· val05 = IN15··· ' obtain reading from detector
· HIGH cl··· ' turn off detector
· PAUSE 2··· ' wait for reset
RETURN
' {$STAMP BS2}
'
' variable declarations
val05· VAR· Byte· ' value where reading is stored
i· VAR· Byte· ' count variable for loop
'
' constant declarations
cl· CON· 14· ' pin 14 is output (clock)
dt· CON· 15· ' pin 15 is the input (data)
'
' I/O pin setup for detector
INPUT dt··· ' make pin 15 the input
HIGH cl····· ' make pin 14 output and high
DEBUG "Start", CR· ' indicate beginning
FOR i = 1 TO 40
· GOSUB read05··· ' take reading
· DEBUG DEC val05, CR· ' display result
· PAUSE 100··· ' stall so display readable
NEXT
DEBUG "Finish", CR· ' indicate end
END····· ' stop Stamp when done
'
' subroutine read05
'
' This subroutine takes a reading from the connected
' GP2D05 detector and stores the value in "val05".
' Any two pins can be used.· Set "dt" to the data line
' of the GP2D05 (pin 3 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D05 (pin 1 on the
' JST connector, green wire).· Also, the IN15 needs
' to be set to the correct variable for the data pin
' (data line).
read05:
· LOW cl··· ' turn on detector for reading
· PAUSE 56··· ' wait 56ms for detector to read
· val05 = IN15··· ' obtain reading from detector
· HIGH cl··· ' turn off detector
· PAUSE 2··· ' wait for reset
RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
take the val05 ... that is the value you will get from the sharp sensor.. then take some servo code
like this
remember to set x as a variable
I think the servo value can be a variable..??
remember the GP2D02 does not give you a cm or inch value.
INPUT dt ' make pin 15 the input
HIGH cl ' make pin 14 output and high
DEBUG "Start", CR ' indicate beginning
FOR i = 1 TO 40
GOSUB read05 ' take reading
DEBUG DEC val05, CR ' display result
PAUSE 100 ' stall so display readable
NEXT
FOR i= 1 TO 24
PULSOUT 13, val05 'servo plugged into pin 13
PAUSE 20
NEXT
PAUSE 200
DEBUG "Finish", CR ' indicate end
END ' stop Stamp when done
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
·if you have a boe bot with the regular ir u should be able to modify the" following boebot" code, but first things first you gonna have to get your ir sensor working ,,try this
·· then u could look at modifiying this code
hope this helps
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Problems are the "roads" of life,
solutions are only "onramps" to the next problem
············································· "Brad Smith"