help with Sharp distance sensor

The place to discuss the Pololu 3pi, m3pi, and Zumo robots and share your code.

help with Sharp distance sensor

Postby JamesC » Mon Dec 13, 2010 12:00 am

I need help getting a Sharp distance sensor working with the 3pi.

Following the example in this website for 3pi Wall Follower, I've connected a Sharpe 2Y0A21 10-80cm range sensor to the 3pi. I'm hoping to experiment with the Sharp sensor to see how well it senses various objects depending on their size, distance, reflectivity/color of surface etc. for possible use in a hockey-bot. Thus, I've only connecting what the example uses as the LEFT wall sensor.

So, I removed the 3pi jumper for the ADC7 to the user trim pot. I've soldered 3 wires to the Sharp sensor Red, Black, and White (ok my wire is Yellow). Then I soldered these to the 3pi board pin/holes for Vcc, Gnd, and ADC7 (respectively) as shown in in the example documentation. (I'm assuming the silkscreen label AD7 is equal to the ATmega ADC7 port.)

For software, since I want to observe the reading from the Sharp sensor, I thought I could just run the 3pi-demo-program/test.c as-is, select the trim pot test, and see (and hear) the value.

The code looks simple enough. I gave it a try but LCD display shows a value of "71" no matter what I point the Sharp sensor at, far or near. The reading never changes.

Am I missing something? The code is show below. I ran as-is from Pololu first. I tried replacing calls to read_trimpot to analog_read(7) but no change. (I turned off the tone to stop annoying me.)

Code: Select all Expand


The only deviation I can see from the example wall follower is that the photo of the underside of the Sharpe (labeled "Sharp distance sensor with connected wires and double sided tape") looks slightly different. The screw and all the layout looks identical but on my part the White and Black wires are very close and the right-most solder point (Red wire) is spaced further away. Also my part is labeled "2Y0A21" where as the example photo shows a Sharp "GP2D12". (Hmmm. I wish I'd ordered the little cable. Says it works with the 30cm would it work with the 80cm part too?)

Also, I guess looking closely now I soldered to the outer most 3 solder points whereas the example photo almost looks like he soldered to the 3 points that are the 2nd row in from the edge.

Is that my problem perhaps? If so, can someone tell me if the 99 cent cable works for the 80cm part? My soldering skills won't let me work at such small detail.

Thanks
JamesC
 
Posts: 8
Joined: Wed Nov 03, 2010 5:24 pm

Re: help with Sharp distance sensor

Postby ryantm » Mon Dec 13, 2010 11:09 am

Hello,

Your code is way too complicated for this kind of troubleshooting. It's so much you didn't even include all of it in your post. Something simple like this would be way better:
Code: Select all Expand

- Ryan
User avatar
ryantm
Pololu Employee
 
Posts: 1268
Joined: Mon May 19, 2008 1:00 pm
Location: Las Vegas, NV

Re: help with Sharp distance sensor

Postby Ben » Mon Dec 13, 2010 12:01 pm

Hello.

Our 3-pin JST cable for Sharp distance sensors works with all three Sharp analog distances sensors we sell. I don't really understand what you're saying about the wires on the back of your sensor, but I suspect you have something connected wrong (or a bug in your code; can you let us know what happens when you try something simpler like what Ryan suggested above?). Can you post a picture of the underside of your sensor?

- Ben
User avatar
Ben
Pololu Employee
 
Posts: 3454
Joined: Mon Aug 28, 2006 1:05 pm
Location: Las Vegas, NV

Re: help with Sharp distance sensor

Postby JamesC » Mon Dec 13, 2010 5:49 pm

I re-soldered the Sharp sensor and the read_trimpot() now works! It gives values in the range of 2 to about 620 (depending on distance to an object) as mentioned in the sample project. I'm running Ryan's simple loop code.

I've experimented with various surfaces - white paper, black paper, white plastic, mirrored, etc. White paper seems to be detected the best (higher numbers and detectable at longest distances).

My next puzzle: Even aimed at a large (12 inch square) box side I get a reading of 0 until the sensor is about 22 cm (9 inches) away. Does anyone else have experience with the 10-80cm Sharp sensor over the longer distances? I'd expect some reading between 20 to the spec max of 80cm.

Do I need a better circuit than just direct connect to the ADC7 port? Or maybe my solder joints are just too terrible? (See photos ... and be ready to 'gasp'.) Or maybe all my soldering, re-soldering heated the sensor too much and altered it?

(I'm ordering the 3-pin cable as making tiny solder joints is a challenge. I have 2 other Sharp sensors: another 10-80cm plus 4-30cm one. I try those once I get my 3-pin cable.)

Other suggestions? Inputs?
Attachments
SecondTry.jpg
Second try soldering to the sensor; worked better
SecondTry.jpg (88.23 KiB) Viewed 7628 times
FirstTry.jpg
My first try soldering wires to the Sharp sensor
FirstTry.jpg (99.7 KiB) Viewed 7627 times
JamesC
 
Posts: 8
Joined: Wed Nov 03, 2010 5:24 pm

Re: help with Sharp distance sensor

Postby ryantm » Mon Dec 13, 2010 6:19 pm

Hello.

Well your picture makes it clear what was wrong before. Your yellow and red wires were soldered to the completely wrong places. Once you apply power to the wrong place, there is a good chance that something will break on the sensor. I suggest you wait and compare the results with the other sensor you got that didn't have power supplied backwards. If it is okay, probably something about the sensor is broken.

Your soldering is pretty bad, especially the part of the wire that looks like it is about to touch the resistor. Generally, you want to keep wires are far apart as possible to avoid shorts. Here was my soldering job:
Image
I'm still not particularly happy with it. The wires could have been wrapped around the pins, the insulation could be a lot closer (especially on the middle wire), the wires could have been trimmed better after I was done soldering, and there could have been about a quarter less solder.

- Ryan
User avatar
ryantm
Pololu Employee
 
Posts: 1268
Joined: Mon May 19, 2008 1:00 pm
Location: Las Vegas, NV

Re: help with Sharp distance sensor

Postby JamesC » Mon Dec 13, 2010 7:28 pm

Yep. I'm retiring from the solder business when it comes to tiny geometries.

If it's not too much trouble you might add a brief note in your wall follower example guide, under Construction. Just after your sentence "Prepare the two distance sensors by soldering three wires to the three leads as shown in the picture." you could add "Be sure to solder to the row of 3 solder points shown in the photo and NOT to the 3 solder points closer to the edge of the connector." ... or such.

OR, EVEN BETTER, for 99 cents, I'd recommend the 3-pin cable part to people. Seems like a worthwhile investment to make sure your $10-13 sensors work properly and don't get damaged.

So, just to confirm, you'd say that the 10-80cm sensor connected directly to the AD7 port will indeed give readings for a wall etc. out closer to the 80cm max distance (if not fried or poorly soldered) in your experience?

Thanks
JamesC
 
Posts: 8
Joined: Wed Nov 03, 2010 5:24 pm

Re: help with Sharp distance sensor

Postby ryantm » Tue Dec 14, 2010 12:58 pm

Hello.

I feel like the solder locations are pretty clear from the picture. The "3 solder points closer to the edge" are really just 1 point that would be slightly reasonable to solder to and the 2 pads of a resistor. I will add the suggestion of the cable to that document. Good idea.

I just tested a 80cm Sharp sensor we had lying around. The ADC was never reading zero and was responding to objects moving all the way up to 80cm. If you look at the output graph of the sensor on its product page, you will see that a reading of zero not very common (only happing when the sensor is completely covered).

- Ryan
User avatar
ryantm
Pololu Employee
 
Posts: 1268
Joined: Mon May 19, 2008 1:00 pm
Location: Las Vegas, NV


Return to 3pi, m3pi, and Zumo Robots

Who is online

Users browsing this forum: No registered users and 1 guest