|
This tutorial will walk
you through connecting the Sharp GP2D02 infra red proximity sensor to
the Robocore. Here at Robologic we love this sensor, its easy to
interface and allows your robot (or whatever your building) to 'see'
objects in front of it and magically steer around them.
Your Sharp GP2D02 comes
with the connector,wires and diode needed to attach it to the Robocore.
So to start lets attach the wires to the connector pin. There are
numbers on the conductor but they are very small and hard to see. The
following diagram should show the order of the pins.

|
|
Pin 1 |
Pin 2 |
Pin 3 |
Pin 4 |
|
SharpPin |
GND |
Vin |
Vcc |
Vout |
|
Wire Colour |
Black |
Green |
Red |
Yellow |
The Sharp sensor uses
something called an open drain input. This is outlined in the
specification tables but means that it can't directly interface with
the 5 volt logic outputs of the Robocore.
The open drain input Vin
naturally floats high at 3 volts, where as the Robocore (or any other
logic circuit) is high at 5 volts. It is Activated when it is pulled
to ground. The problem is that the line can't be pulled high to 5
volts because it exceeds the maximum characteristics of the open drain
circuit. If the Vin line is connected directly to the Robocore the
sensor will not work.
A solution to this
problem is to use the diode provided to only enable the current to
flow when the Robocore logic level is low. The diode stops the Vin
line from being pulled too high but allows it to be pulled to ground
to enable the sensor.

The diode can be
soldered onto the green wire connected to the Vin pin of the Sharp
sensor. Once the diode is soldered in place cover it with insulation
tape or heat shrink tubing to prevent it making contact with any other
electrical lines. The diode has a black stripe on one side, it is
essential that the black strip is facing in the direction of the
Robocore.
The Vcc line can be
connected to any 5 volt regulated output of the Robocore.
The interface between
the Robocore and the sensor is a serial interface. If you are familiar
with serial interfaces the following timing diagram will show the
sensors operation. The clock line is Vin, the Data line is Vout.

If you are not familiar
with timing diagrams here is an expalin the operation of the sensor.
Vin is used by the
Robocore to control when we want to receive data, Vout is the line
used by the sensor to give data to the Robocore. When the sensor is
deactivaled (Vin line is high) the sensors output line Vout floats
high (at 5 volts). To activate the sensor we pull Vin low. To show
that the sensors active Vout goes low for about 70ms, this is when the
sensor takes its measurement. When it is done Vout goes high. So we
must wait for at least 70ms or until Vout goes high again.
Once the measurement has
been taken we can read in the data. We use Vin as a clock to tell the
sensor when we are ready for the data. A clock is a on off pulse,
every time the pulse goes low another bit can be read in from the Vout
line.
So, we wait for Vout to
go high, telling us the sensor is done taking its reading. Now we pull
Vin high and start our clock. Note, the timing diagram says that there
must be no longer than a 0.2ms pause between pulling Vin high and
starting the clock.
To take readings we
simply cycle Vin through an On - Off loop, the data is an 8 bit number
so the clock must make 8 on -off cycles. Every time we turn the clock
off we can look at Vout and get a data bit (either on or off). The
first bit outputted is the most significant bit (or the largest bit).
Once we have pulled all
the 8 bits from the sensor we can pull Vin high again so the sensor is
ready to take its next reading.
The sensor will give us
an 8 bit binary number (0 - 255 in decimal), and so finally we will
need to convert it into a decimal number to be able to use it. If you
don't understand binary numbers the following paragraph might help
you.
Binary is a number
system that is to the base 2, instead of to the base 10 like decimal.
Instead of writing Hundreds, Tens, and Units as in the Decimal
numbers, we write (from left to right) 1s, 2s, 4s, 8s, 16s, etc.
This means that in the
binary system, the number 10111
would represent one lot
of 16, no lots of 8, one lot of 4, one lot of 2 and finally one unit,
or else
(1 x 16) + (0 x 8) + (1
x 4) + (1 x 2) + (1 x 1) = 23
So 10111 in binary is 23
in decimal. Using this system we can convert the 8 bit binary number
into a decimal format that we can work with.
Finally, there are a
couple of sample programs that will hopefully get you started with the
Sharp GP2D02, they both take readings from the sensor, convert the
binary number into decimal and print it back to the PC screen. They
should give you a few ideas as to how to program the sensor. |