If you are asking how to convert the value to centimeters, there’s an example I cam across at the Basic Micro website. At the bottom of the page there’s example code for the GP2D12. the code uses a byte table, which is an array of constants.
'---- Main Loop ] -----------------------------------------------------------
main
adin AX0,2,AD_RON,scanrange ' Read sensor value
floating = float scanrange fdiv 5.12 ' Limit value to <200 values
val = scantable(int floating) ' Convert A/D to measurement
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
’ 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]
Because the sensors response is NOT linear Nathan has set up a lookup table, to get accurate distance measurements. Unfortunately his example is for an atom not the pro.
I did a quick and dirty conversion to Pro… Did not try running it but it did compile. Note: I made a simply logic change as I don’t like accessing random memory if I am outside of the array…
[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:
'---- 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]
ok great. i will be using AX2 on the ABB. question: what jumpers would i need to install?
iv read though loads of docs and some of them contradict each other so im now left confused.
I’m not sure anything conflicts so much as there are many acceptable but different ways to do things with the boards. AX0,1,2,3 are Atom pins. On the pro they are 16,17,18,19. I/O pins 0,1,2,3 are also analog capable. As far as jumpers, you only need one to apply 5vdc power to the I/O buss (group of four) that you will connect the GP2D12 to. Hope this helps.
Hi Jim,
I use a SSC32 with a BBII and BATOMpro 28 and I’ve create a simple program to move my robot ARM.
I’ve added a sensor on the input pin on the SSC32 (A) and I wont use it with the basic code:
Do you have a simple example code?
THX