View Full Version : Can Sharp GP2D12 proximity sensors be used with Prop chips without additional h

12-24-2009, 03:00 PM

So I have a few Sharp GP2D12 proximity sensors laying around and also a Digital Infra-Red Rangefinding (DIRRS+) (http://www.hvwtech.com/products_view.asp?ProductID=91) version.
Will both types work with the propeller chip without additional hardware? If so does anyone have code samples that will work with whichever will work?

:) Thank you!

12-24-2009, 05:58 PM


Amateur radio callsign: G1HSM

Mike G
12-24-2009, 08:13 PM
An analog to digital converter (A/D) is needed to convert the GP2D12 analog output to a distance reading. The GP2D12 datasheet has a lot of really good info.

There are several A/D examples on the object exchange http://obex.parallax.com/objects/category/9/

12-25-2009, 02:19 AM
So these objects will work to convert it then? Or are they just to work with A/D converter?

12-25-2009, 04:42 AM
Here is the code that I am trying to emulate in spin, this is a bs2 program to output the distance into a terminal window.

'DIRRS Plus demo software version 1.0
'Date: March 2000
'Author: Dan Henne
'This software is used with the DIRRS Plus when it is configured
'for Original DIRRS mode. The input from the DIRRS Plus is
'triggered by a high low transition with the resulting
'distance measurement shifted into the DIST variable.

DIST VAR BYTE 'Variable used to store DIRRS result
clock CON 1
datain CON 0

OUTPUT clock 'Pin 0 connects to Pin 2 of DIRRS Plus
INPUT datain 'Pin 1 connects to Pin 4 of DIRRS Plus

High clock 'Start Vin must have high-low transition
Pause 3 'Wait for high to be recognized
Low clock
For T= 1 to 30 'Begin 30 ms wait
Pause 1
If IN0=1 Then JUMP
'If Vout is HIGH, measurement is complete -jump
Next 'Measurement not complete, wait another 1 ms

Shiftin datain,clock,2,[DIST\8]
'Shift 8 bits into DIST via pin P1, clocking with P0, MSB first
Debug "Distance= ", dec DIST,cr
'Display distance (in decimal form) in debug window
Goto START 'Start over

John Abshier
12-25-2009, 06:17 AM
That code is for a version of the Sharp sensors that had a digital output. It is not for a GP2D12. The output pin from the GP2D12 will be seen by a Propeller as transitioning from high/low at one fixed distance.

John Abshier

12-26-2009, 09:35 AM
If you use the MCP3208 ADC chip then there are several good objects that you can use, depending on the number of channels that you need: obex.parallax.com/objects/search/?q=MCP3208 (http://obex.parallax.com/objects/search/?q=MCP3208)

Plus, Parallax sells the MCP3208 ADC chip.

Powered by enthusiasm

12-26-2009, 10:38 AM
John, yes I know it is, I have 1 digital output one which I linked to earlier in the thread and am trying to use as well. SRLM thanks i might order one of those so I can use these, one of the microcontrollers I used to use must have had A/D built in and I just didn't realize it.

But my question still remains, if anyone has any ideas for outputting distance to a terminal from a digital sharp sensors (such as this one www.hvwtech.com/products_view.asp?ProductID=91 (http://www.hvwtech.com/products_view.asp?ProductID=91)) it would be much appreciated. http://forums.parallax.com/images/smilies/smilewinkgrin.gif

12-26-2009, 10:47 AM

This thread from a year ago involved interfacing 24 of the "analog" sharp sensors to the prop via 3 MCP3208's (as SRLM suggested).

There's code there too

12-26-2009, 10:59 AM
This should work great, thanks you!

John Abshier
12-26-2009, 09:42 PM
I just looked at the link to the DIRRS+ page. I did not download the product manual. It supports asynchronous serial. For that you could use simple serial or full duplex serial. It also supports synchronous serial. That would use code similiar to what you posted earlier. The key is to read the DIRRS manual and the sample code.

John Abshier