Problem with Sharp Distance Sensor GP2D12 F 04

I plug the distance sensor to port 15/A1
and here is my code:


FEZ_Components.DistanceDetector myRanger = new
FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An1, 
FEZ_Components.DistanceDetector.SharpSensorType.GP2D120);
float value = 0;

// Create ServoMotor object assigned to the Servo Motor connected to Di8
FEZ_Components.ServoMotor myServo = new FEZ_Components.ServoMotor(FEZ_Pin.Digital.Di8);
while (true) {

	myServo.SetPosition(45);
	value = myRanger.GetDistance_cm();
	Debug.Print("Range reading at 45 angle is: " + value.ToString()); 
	Thread.Sleep(2000);

	myServo.SetPosition(90);
	value = myRanger.GetDistance_cm();
	Debug.Print("Range reading at 90 angle  is: " + value.ToString()); 
	Thread.Sleep(2000);

	myServo.SetPosition(135);
	value = myRanger.GetDistance_cm();
	Debug.Print("Range reading at 135 angle  is: " + value.ToString()); 
	Thread.Sleep(2000);

	myServo.SetPosition(90);
	value = myRanger.GetDistance_cm(); 
	Thread.Sleep(2000);
}

and this is what the readinge were, regardless of  if  I put an object right in front of the sensor
What is happening?


Range reading at 45 angle is: 11.6354799
Range reading at 90 angle  is: 11.4901962
Range reading at 135 angle  is: 11.3485441
Range reading at 45 angle is: 11.3485441
Range reading at 90 angle  is: 11.4901962
Range reading at 135 angle  is: 11.4901962
Range reading at 45 angle is: 11.0756054
Range reading at 90 angle  is: 11.4901962
Range reading at 135 angle  is: 11.3485441
Range reading at 45 angle is: 11.6354799
Range reading at 90 angle  is: 11.4901962
Range reading at 135 angle  is: 11.4901962
Range reading at 45 angle is: 11.4901962
Range reading at 90 angle  is: 11.4901962
Range reading at 135 angle  is: 11.4901962
Range reading at 45 angle is: 11.4901962
Range reading at 90 angle  is: 11.4901962
Range reading at 135 angle  is: 11.4901962
Range reading at 45 angle is: 11.4901962
Range reading at 90 angle  is: 11.4901962
Range reading at 135 angle  is: 11.4901962
Range reading at 45 angle is: 11.4901962
Range reading at 90 angle  is: 11.4901962



...Look like i may have assigned wrong sharp sensor model to my bot, the sensor i have is GP2D12 F (there is a space before F). does mini not support this sensor? can I still make it work?


I look at drivers, it read that

[quote]This component comes in two types: 
1.GP2D120: Range is 4 to 30 cm
2.GP2Y0A21: Range is 10 to 80 cm
Works with any analog input pin on FEZ Mini Starter Kit/Robot and FEZ Domino Component shield[/quote]. 

so is that true that currently Mini does support GP2D12 ?
 
Thanks, Hai

Try the blank example code to minimise problems first.

Code:


using System;
using Microsoft.SPOT;
using System.Threading;
using GHIElectronics.NETMF.FEZ;
public class Program
{
public static void Main()
{
// Create DistanceDetector object assigned to the a Sharp IR Distance Detector Component connected to
An0 with analog input feature.
FEZ_Components.DistanceDetector myRanger = new
FEZ_Components.DistanceDetector(FEZ_Pin.AnalogIn.An0,
FEZ_Components.DistanceDetector.SharpSensorType.GP2D120);
float value = 0;
while (true)
{
value = myRanger.GetDistance_cm();
Debug.Print("myRanger reading is: " + value.ToString());
Thread.Sleep(100);
}

If you are still having problems with this code, please let us know :wink:

I don’t think your issue has to do with a wrong sensor. If it did, your code would work, it’s just that the two sensors are differnt ranges. One is meant for close up sensing, one is meant for long distance. they both have the same pinout, although you might not be using the right driver.

Foekie (Robert)
I will try the baby step again tonight :-). however, I tried FEZ_Pin.AnalogIn.An0 and run into exception, I could not find A0 port on the Mini board, so I assume to use An1-An6 for this?

Chris,
I only see one driver avaible on this site for these 2 types, and GP2D120 seems to be closer to one I have. I look around, but couldnt find another driver for mine.

1.GP2D120: Range is 4 to 30 cm
2.GP2Y0A21: Range is 10 to 80 cm

Thanks!

i retried with simple code, and yes it seems issue still there.
thanks!

myRanger reading is: 895263.25
myRanger reading is: 895263.25
myRanger reading is: 895263.25
myRanger reading is: 895263.25
myRanger reading is: 895263.25
myRanger reading is: 895263.25
myRanger reading is: 895263.25
myRanger reading is: 895263.25

How are you testing the sensor? Did you try to put a book in front of the sensor and try to move the book closer and further? You need object with good reflection. A pillow may not work nicely.

I have one of these sensors, and I have always used a white piece of printer paper. Try that.

i tried with paper, photo paper, back of my iphone leather cover, book, and some other things, nothing seems working

Did you buy the sensor from this website?

not from this website, that is problem I have GP2D12, not GP2D120

That is your problem. It will not work. You need to fix the wires because the pinout of our JST is not same as your sensor

Definitely my problem, I will beat myself up… sounds like it needs a minor surgery. I may be able to handle small surgery, any how-to document that you know of? would a turn the cable backward fix?

Appreciate!!!

it seems problem solved by blindly swaping wires around, and lucky enough, nothing burn :slight_smile:

I’d try looking at the distance sensor pinout information where you bought your sensor from and see if they can tell you what the layout is meant to be.

From the Fez sensor page it shows:

Important Note: The cable pin-out of this sensor is made to match the connectors’ pin-out on FEZ (Ground, Signal, Power). Sensors from other suppliers might have cables with a different pin-out. Make sure you modify the cable to match the pin-out we provided.

So you need to figure out on your sensor what wire is the GND, Power and Analog in, and rearrange appropriately - in the case of a JST connector you could try jumpering from the JST socket with breadboard wires, running from the socket to your Mini, which would at least allow you to test things out. For a more permanent solution you could cut the wire between the plug and the sensor, and resolder with the correct orientation, and tape them (insulate) appropriately.

(edit) looks like you have that sorted :slight_smile: