GP2D12 and others

Started by matiasmatte June 12, 2005
Hi, I really need help!!

After trying the SRF04 I connected an IR sensor (GP2D12) and I
couldn't use it. I used the 16 pin (ADC input) and got no reading. It
sometimes returns a value, but for the same distance it can be
different. I don't know what happen!!! please tell me how I can check the I/O
ports of the BX-24, maybe they're not working, or what wrong with it.
I can't figure out what should be...

Another question. I can write in the editor, but how can I configure
the editor as the Visual Basic of Excel? I want it to put in green or
blue the text while I'm writing the code, that way I can know if the
code is correct or not. All the examples Ive found has tha special
words in blue or green.

Thank you very very much.

These are the codes I used for the sonar and IR

Option Explicit

Sub Main() 'Pin 11 = Trigger (Output)
Const TriggerPin As Byte = 11

'Pin 12 = Echo (Input)
Const EchoPin As Byte = 12

Dim Distanza As integer
'Trigger = output = 0
Call PutPin(TriggerPin, bxOutputLow)

'Echo = input
Call PutPin(EchoPin, bxInputTristate)

'Loop infinito
do

'Genera un impulso positivo di durata pari a 10uS sul pin Trigger
Call PulseOut(TriggerPin, 10, 1)

'Rileva la durata dell'impulso positivo di eco
'e la converte in centimetri
Distanza = PulseIn(EchoPin, 1) 'Visualizza la distanza sul
video del PC
Debug.Print "ancho pulso = " ; CStr(Distanza)

'Aspetta 10mS e ricomincia
Call Delay(1.0)

loop

End Sub

Option Explicit

' This program reads a Sharp GP2D12 infrared object detector, and
' continuously displays range at a rate of about 3 times per second.
'---------------------------------
----------
Public Sub Main()

Dim Range As Single
Dim Success As Boolean

Debug.Print
Debug.Print "Sharp GP2D12 IR object detector"
Debug.Print

Do
Call GetRange(Range, Success)

Debug.Print "Range = "; Debug.Print CStr( CInt(Range * 1000.0) ) Delay 0.3
Loop

End Sub
'---------------------------------
----------
Public Sub GetRange( _
ByRef Range As Single, _
ByRef Success As Boolean)

Dim Voltage As single

' This pin number is for a BX-24. The pin number may need to be
changed
' depending on the BasicX system being used.
Const InputPin As Byte = 16

Call GetADC(InputPin, Voltage) End Sub
'---------------------------------
----------



Hi,

You don't need to pulse the GP2D12.

So if you just getADC you will get a voltage relative to the distance.

In the Appnotes there is an example for converting the voltage to
distance in cm for the GP2D12

/lars

--- In basicx@basi..., "matiasmatte" <matiasmatte@y...> wrote:
> Hi, I really need help!!
>
> After trying the SRF04 I connected an IR sensor (GP2D12) and I
> couldn't use it. I used the 16 pin (ADC input) and got no reading. It
> sometimes returns a value, but for the same distance it can be
> different. > I don't know what happen!!! please tell me how I can check the I/O
> ports of the BX-24, maybe they're not working, or what wrong with it.
> I can't figure out what should be...
>
> Another question. I can write in the editor, but how can I configure
> the editor as the Visual Basic of Excel? I want it to put in green or
> blue the text while I'm writing the code, that way I can know if the
> code is correct or not. All the examples Ive found has tha special
> words in blue or green.
>
> Thank you very very much.
>
> These are the codes I used for the sonar and IR
>
> Option Explicit
>
> Sub Main() > 'Pin 11 = Trigger (Output)
> Const TriggerPin As Byte = 11
>
> 'Pin 12 = Echo (Input)
> Const EchoPin As Byte = 12
>
> Dim Distanza As integer
> 'Trigger = output = 0
> Call PutPin(TriggerPin, bxOutputLow)
>
> 'Echo = input
> Call PutPin(EchoPin, bxInputTristate)
>
> 'Loop infinito
> do
>
> 'Genera un impulso positivo di durata pari a 10uS sul pin Trigger
> Call PulseOut(TriggerPin, 10, 1)
>
> 'Rileva la durata dell'impulso positivo di eco
> 'e la converte in centimetri
> Distanza = PulseIn(EchoPin, 1) 'Visualizza la distanza sul
> video del PC
> Debug.Print "ancho pulso = " ; CStr(Distanza)
>
> 'Aspetta 10mS e ricomincia
> Call Delay(1.0)
>
> loop
>
> End Sub
>
> Option Explicit
>
> ' This program reads a Sharp GP2D12 infrared object detector, and
> ' continuously displays range at a rate of about 3 times per second.
> '---------------------------------
> ----------
> Public Sub Main()
>
> Dim Range As Single
> Dim Success As Boolean
>
> Debug.Print
> Debug.Print "Sharp GP2D12 IR object detector"
> Debug.Print
>
> Do
> Call GetRange(Range, Success)
>
> Debug.Print "Range = "; > Debug.Print CStr( CInt(Range * 1000.0) ) > Delay 0.3
> Loop
>
> End Sub
> '---------------------------------
> ----------
> Public Sub GetRange( _
> ByRef Range As Single, _
> ByRef Success As Boolean)
>
> Dim Voltage As single
>
> ' This pin number is for a BX-24. The pin number may need to be
> changed
> ' depending on the BasicX system being used.
> Const InputPin As Byte = 16
>
> Call GetADC(InputPin, Voltage) > End Sub
> '---------------------------------
> ----------


Matias, while not the Sharp GP2D12, I posted an example of the Sharp
GP2D02 sensor on my web site at [GP2D02.zip]:

http://home.comcast.net/~tomhandley/bx-24/bx-24.html

I had looked at the GP2D12 but one big problem is the lack of a
linear response. You have to add some software to compensate for
that. Check the data sheet and do a search where you can find many
examples. The other problem with the GP2D12 is the current
consumption, around 33ma, and it's always On.

Compare that with the GP2D02 which also has an 80cm range but it
has a serial output. It consumes around 22ma when active and around
3ma when idle. From a software standpoint, you get range data in a
Serial format that is easy to deal with.

Like I mentioned in my earlier response to your SRF04, readings can
vary all over the place depending on the environment.

- Tom

--- In basicx@basi..., "matiasmatte" <matiasmatte@y...> wrote:
> Hi, I really need help!!
>
> After trying the SRF04 I connected an IR sensor (GP2D12) and I
> couldn't use it. I used the 16 pin (ADC input) and got no reading.
It
> sometimes returns a value, but for the same distance it can be
> different. > I don't know what happen!!! please tell me how I can check the I/O
> ports of the BX-24, maybe they're not working, or what wrong with
it.
> I can't figure out what should be...
>
> Another question. I can write in the editor, but how can I
configure
> the editor as the Visual Basic of Excel? I want it to put in green
or
> blue the text while I'm writing the code, that way I can know if
the
> code is correct or not. All the examples Ive found has tha special
> words in blue or green.
>
> Thank you very very much.
>
> These are the codes I used for the sonar and IR
>
> Option Explicit
>
> Sub Main() > 'Pin 11 = Trigger (Output)
> Const TriggerPin As Byte = 11
>
> 'Pin 12 = Echo (Input)
> Const EchoPin As Byte = 12
>
> Dim Distanza As integer
> 'Trigger = output = 0
> Call PutPin(TriggerPin, bxOutputLow)
>
> 'Echo = input
> Call PutPin(EchoPin, bxInputTristate)
>
> 'Loop infinito
> do
>
> 'Genera un impulso positivo di durata pari a 10uS sul pin
Trigger
> Call PulseOut(TriggerPin, 10, 1)
>
> 'Rileva la durata dell'impulso positivo di eco
> 'e la converte in centimetri
> Distanza = PulseIn(EchoPin, 1) 'Visualizza la distanza sul
> video del PC
> Debug.Print "ancho pulso = " ; CStr(Distanza)
>
> 'Aspetta 10mS e ricomincia
> Call Delay(1.0)
>
> loop
>
> End Sub
>
> Option Explicit
>
> ' This program reads a Sharp GP2D12 infrared object detector, and
> ' continuously displays range at a rate of about 3 times per second.
> '-------------------------------
--
> ----------
> Public Sub Main()
>
> Dim Range As Single
> Dim Success As Boolean
>
> Debug.Print
> Debug.Print "Sharp GP2D12 IR object detector"
> Debug.Print
>
> Do
> Call GetRange(Range, Success)
>
> Debug.Print "Range = "; > Debug.Print CStr( CInt(Range * 1000.0) ) > Delay 0.3
> Loop
>
> End Sub
> '-------------------------------
--
> ----------
> Public Sub GetRange( _
> ByRef Range As Single, _
> ByRef Success As Boolean)
>
> Dim Voltage As single
>
> ' This pin number is for a BX-24. The pin number may need to be
> changed
> ' depending on the BasicX system being used.
> Const InputPin As Byte = 16
>
> Call GetADC(InputPin, Voltage) > End Sub
> '-------------------------------
--
> ----------