Shop OBEX P1 Docs P2 Docs Learn Events
GP2D02 Newbie — Parallax Forums

GP2D02 Newbie

gordianknotgordianknot Posts: 12
edited 2005-04-03 00:40 in BASIC Stamp
I've just mounted two Sharp Sensors - and now I can't get them to work:
Here are the details:

Circuit

* 1st problem - the JST Connector that I received with the unit have wires that are coded
White, Red, Blue, and Black - not Yellow,Red, Green, and Black referenced in the Acroname site

However I hooked the sensor up as follows:

White --> Pin 0 through Diode ' Pin 0 Used as Clock input
Blue --> Pin 1 'Pin 1 used as Data Output
Red ---> VDD
Black --> Ground VSS

Code:

Here is the Code:

'{$STAMP BS2}
'{$PBASIC 2.5}
'
' variable declarations

val02 VAR Byte ' value where reading is stored
i VAR Byte ' count variable for loop


'
' constant declarations

cl CON 0 ' pin 14 is output (clock)
dt CON 1 ' 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


'
' main loop

DEBUG "Start", CR ' indicate beginning

FOR i = 1 TO 100 ' take and display 100 readings
GOSUB read02 ' call measurement routine
DEBUG DEC val02, CR ' display the value
'PAUSE 100 ' stall so display readable
NEXT

DEBUG "Finish" ' indicate end

END ' stop Stamp when done


'
' subroutine read02
'
' This subroutine takes a reading from the connected
' GP2D02 detector and stores the value in "val02".
' Any two pins can be used. Set "dt" to the data line
' of the GP2D02 (pin 4 on JST connector, yellow wire).
' Set cl to the clock line of the GP2D02 (pin 2 on the
' JST connector, green wire).

read02:
LOW cl ' turn on detector for reading
PAUSE 70
rl:
IF IN1 = 0 THEN rl ' wait for input high
SHIFTIN dt, cl, MSBPOST, [noparse][[/noparse]val02]
HIGH cl ' turn detector off
PAUSE 40 ' let detector reset
RETURN



RESULT:
The code displays:
Start
255 ' 255 is looped until program terminates

I've looked everywhere for the answer including Acroname the Parallax Forum archives. The problem is still not resolved

Can anyone help?

mad.gif

Comments

  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-04-02 20:00
    These devices draw a big gulp of current when they are actively pulsing the IR LED. I'd recommend that you put a big capacitor, 100uF at least, across the sensor power leads. Strange things can happen if it is starved for current.

    During the 70 millisecond measurement period, the sensor pulses the LED 16 times, and averages the results at the end. The average current drawn from the power supply during the measurement interval is around 30 milliamps, but the pulses are much more. I recall I had a similar problem with the GP2D12, which is the analog output version of the sensor. There the measurement is executing 100% of the time, so the problem is most acute when you try to run two or more of them at the same time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • gordianknotgordianknot Posts: 12
    edited 2005-04-03 00:40
    Unfortunately, I've tried that - still no joy.

    Any more suggestions?
Sign In or Register to comment.