Making an IR Sensor

normally i always use the terrminal. I only tried debug because i whas told to.

I will try this new code tonight. So this will give me an output?

Hey guys,

I received my gp2d12 sensor today. But i’m still having difficulties with the code…

This is the code i want to use because i can easily (i presume) add it to Xan’s code.

[code]’ ----- Program Description ]---------------------------------------------

’ This program demonstrates how to read the Sharp GP2D12 infrared analog output
’ detector with an Atom module and display the results in a terminal window.
’ Hardware Connections:

’ Atom Module Sharp Sensor
’ ------ --------------------------------
’ P16 Pin 1

'----- Variables ]------------------------------------------------------------

scanrange var word ’ A/D result variable
floating var float ’ Floating point math result storage
val var byte ’ Table conversion result storage

'---- Table Setup ] ----------------------------------------------------------

scantable bytetable 80,80,80,80,80,80,80,80,80,78, |
76,74,72,70,68,66,64,62,60,59, |
58,57,55,53,52,51,50,49,48,47, |
45,43,42,41,40,39,38,37,35,33, |
32,31,30,30,29,29,28,28,27,27, |
26,26,26,25,25,25,24,24,24,23, |
23,22,22,21,21,20,20,20,19,19, |
18,18,18,17,17,16,16,16,15,15, |
15,14,14,13,13,13,12,12,11,11, |
11,10,10,10,10,10,10,10,10,10

'---- Main Loop ] -----------------------------------------------------------

main

adin P16,scanrange ’ Read sensor value
if scanrange > 512 then ’ Test for obstacle to close to detector
serout s_out,I9600,“Too Close To Measure”, 13] ’ Send “Too Close” message
else
floating = tofloat( scanrange) / 5.12 ’ Limit value to <200 values
val = scantable(toint floating) ’ Convert A/D to measurement
’ debug [REAL floating," “,DEC val,13] ’ Output result to debug window
serout S_OUT,i9600,[REAL floating\2,” - “,DEC val,” cm",13]
endif ’ End If-Then-Else command
goto main ’ Loop back and get another reading[/code]

So, the output i’m getting is:

0cm - 80cm
0cm - 80cm
0cm - 80cm
0cm - 80cm
etc.

But no reaction to the sensor.

Please help!

How do you have it connected? Images pleaase…

The colors are connected the way they lie on the pic.

Connected here:

The sensor as it is in the image should be in this order.

signal - ground - 5vdc.

It’s quite impossible to tell if the black wires are in order. But if the black wires are in the same order in the sensor as they are on the header post connector then you have it backwards.

Also you have in your program pin 16, but in fact you are connecting it to pin 19. You will never get a change if you are reading the wrong pin. Sorry you deserve the roll… :unamused:

I’m updating the Bot Board II manual now. It appears there is no mention that AX0-3 corresponds to P16-19. Must have gotten missed when we changed from booklet to HTML. This one is for me… :unamused:

Hard to tell the connections using the black wiring harness but per the data sheet, Ground sould be the middle pin on the sensor and to the left of that pin is power (red) and the white wire should be to the Left.

[code]
|----------------|

Front
 S   G   P

S = White wire
G = Black wire
P = Red wire[/code]

lynxmotion.com/images/data/gp2d12.pdf

EDIT>> Ope! looks like Jim beat me on the post.

Okay i changed the wires. And corrected the pin in the code. I tried several different pins so that’s why the pin wasn’t the same as in the code.

But still no difference… :question:

Any other ideas?

Ok, you made me break out my test board. :imp:

Here is the code I ran.

[code]AM var sword

main

adin 19, AM

serout s_out,i38400,[sdec AM ,13]

goto main[/code]

Open a terminal window and set it for 38.4k. The numbers should change from about 5 to 500. The I/O pins are like this.

AX0=P16
AX1=P17
AX2=P18
AX3=P19

Works for me…

i get this output:

0
0
0
0
0
00

This code is ment for the atom pro 28 on BBII right?

I really cant get this to work…

Help Needed!!

*update

I used the code i showed before and now it gives me this:

7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7w7

I read in another post that means the sensor is off. is this correct? and if yes, How do i turn it on?

Not sure how to help here. But things to look at. In you last update you showed something like output is 7w… You also said with the program from before. So what baud rate is this program outputing at, and what do you have the terminal set to? The reason I ask is Jims program was outputting at 38400 and your previous was 9600. Personally until you figure it out I would stay with the simpler program like Jim mentioned.

Also I would double check all of my wiring. I use the sharp IR sensor wire that Lynxmotion sells, which eliminates any of these issues. The all black makes it hard to figure out if you have the right wires hooked up to the right pins…

Do you have a volt meter? If so can you measure the voltage of the signal pin to see what it is returning (if anything).

You might also try IO pin P0 to see if that works any better. Make sure you are sending +5v to the IO pin group and not VS. It looked like you board was jumpered correctly for this before. You can use IO pins P16-P19 and P0-P3 for analog input.

To see if the AtoD is working at all for you, you might try Jims program with P16 or P17 with the jumpers still installed, which should give you values relative to that the input voltage is being passed into your board…

Beyond this I don’t know what to suggest.

Kurt

The problem is not that it doens’t output anything…
It’s that it doesn’t show the sensor info. only 000000 (your code) or the 7]W thingy (for the other code i came with).

I tried your code a few more times but no luck. Only zeros

I checked the wires over and over again. Although when i look at the picture on the lynxmotion site (it shows the cable coming with…) it shows i have to attach it with the white/yellow thread on the right and not on the left. But even though, that didn’t work either. The led is working fine. I checked with my cam.

Ive tried every possible port allready. No difference.

I have a voltmeter (with a bad display) but the battery is empty at the moment so i can’t use it.

And who is Jim? Or what code did you mean?

:laughing: Jim is Robot Dude, as in Jim Frye the robot guy, as in owner of Lynxmotion… the guy posting the simple example code a few posts back. :wink:

fix your meter… or borrow one. You appear to be focusing on the code not output anything and as far as I can tell you have not definitively determined your ir sensor is wired up correctly. if you have to, lay it out on the table so it is plainly clear what is connected to what and take a picture to post. a jumble of the same color wires coiled around each other as they go from point A to point B isn’t useful for anyone trying to help you. the code makes absolutely no difference until you are certain your sensor is wired correctly and operating… as in it outputs a voltage you can read with a meter on the input pin of a port of the BB2. Once you know that works then the code is trivial.

I agree you need a multimeter (they are cheap now days and even walmart has them in the auto and hardware areas) and verify the sensor is indeed putting out an analog voltage. In the mean time have you tried connecting a voltage source on the board to see if you get a result that indicates the voltage is being read using your code?

No i did not… But isn’t that a bit dangerous? Well maybe not if you do it right. Let’s save this as a last option. :laughing: (PS: We don’t have wallmart in the netherlands. wish we did though. Best store ever!!)

As for Jim’s code: I will look it up and try it. I will post a picture of my sensor soon. The black wiring came with the sensor and since i need that connector i have no option.

here is the picture of my wiring:

So i got a battery and mesured the power over the white cable. Since my display is broken i can’t tell what the exact voltages are but i can see the sensor is working correct. The voltage is increasing as i hold it closerby, about 3.* V and when i hold it in open space it goes back to -0.* V

I just thought of the firmware of the BAP-28. Do i need to use the XE or the GP firmware? or doen’t it make a difference?

From your description it sounds like you have a voltage coming back, so now lets see if we can get it to read…

Here is some of the simple code that Jim (Robot Dude) posted earlier.

AM var sword 

main 

adin 19, AM 

serout s_out,i38400,[sdec AM ,13] 

goto main

This one assumes P19. It assumes that your terminal window is set to 38400 baud rate…

Here is a sligtly extended version that tries all 8 pins:

AM var sword 
i var sword
pins bytetable 16,17,18, 19, 0, 1, 2, 3


main:

	for i = 0 to 7
		adin pins(i), AM 
		serout s_out,i38400,[sdec AM ," "]
 	next
 	serout s_out, i38400, [13]
 	pause 100

goto main

On my new brat with nothing connected to those 8 pins, but I do have the two voltage detection jumpers plugged in, I get these results:

329 329 328 354 851 1023 1023 1023 329 329 443 537 893 1023 1023 1023 329 329 506 649 923 1023 1023 1023 329 329 545 724 955 1023 1023 1023

The 329s for P16 and p17 make sense. As I have the jumpers, which if I remember my stuff: computes to 329/1024 * 5v = 1.6V. Then if you look at the BB2 circuit, it has a voltage divider on these pins, which I am only measuring 1/4 of the battery voltage. So my battery has about 6.4V…
The others are sort of showign trash as these signals are floating. That is a different conversation…

The firmware you mention is for an SSC-32 not a bap…

Kurt

This is the output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

I used port 0 and 3, no difference.

Wouldn’t it be better to attach it to the ssc-32?

About the firmware:
You’re right. but still, does the BBAP need to have a specific firmware? I noticed while checking firmware i can’t connect to the BBAP with the serial cable in powerpod and when checking for firmware it only gives me 6 bytes instead of 30.

With this output, I am not sure how to help. You still have the 2 jumpers on P16 and P17 (ax0 and ax1) that should feed in VS and VL to these two pins? What else is plugged into this board? Try unplugging everything from this board, except power and leave the jumpers mentioned above, do you still get all zeros?

What version of the Basic Atom Pro IDE are you running? Should be able to get from Help/About menu item. Do you have that it is a Basic Atom Pro 28 selected at the top of the window? I think it will compain if you have something else choosen other than what it thinks you have…

I think you meant P0 and p3 right?

The Bap is reprogrammed by the IDE. There is a boot loader that the IDE talks to, to download new programs. More or less everything is reprogrammed each time you hit program.

Have you double checked that all of the pins of the BAP are properly inserted into the BB2? ie none bent over or the like? If I were getting these results, I would try to verify that the IO lines were working at all. Sometimes I used the built-in LEDS on the BB2 to have a visual output. How I do this is to undo the 3 PS2 jumpers that are under the A/BC led/buttons (normally connected to P12-P14), I take a 3 wire servo extension wire and plug it into 3 IO lines like p0-p2) and then plug the other end into where the three jumpers were you removed. Plugged into the pins that is closest to the leds/buttons. I hope this makes sense. Then you can try simple programs like:

main:
    toggle p0
    pause 250
    goto main

One of the leds should flash on and off…

Good Luck
Kurt