FIGURE 4. You will need to adjust the
compass readings with the magnetic
declination for your particular location so
that they will point to true north.
maintaining a specific heading set in the DESIRED_
HEADING global constant. It also takes advantage of the
quadrature optical encoder. Finally, in the bit banged
I2C_Start routine in Listing 3, notice how the waveforms
for this Start condition are synthesized using low level clock
and data bit toggling routines.
As mentioned, using the proportional control loop can
help a robot navigate a specified course. This is done by
having the microcontroller issue small motor commands
that are geared down using the VEX gearbox, which
generates tiny motion increments.
Your compass should now be fully operational.
I2C HARDWARE SUPPORT FOR VEX CORTEX OR VEXPRO MICROCONTROLLERS
You can program a VEX Cortex or even a VEXpro
microcontroller to use I2C hardware ports by utilizing the
routines provided in EasyC Pro or Robot C (or even QWERK
C++ for the VEXpro, once I2C hardware drivers become
available from the respective compiler vendors). Until then,
you need to bit bang the I2C routines in a similar fashion to
how we did them here for the microcontroller. In either
case, I don’t believe the main application would need to
change much (although I have not tried it).
I2C support for the Cortex and VEXpro is provided
directly with a hardware port that is used to read the new
integrated quadrature encoders that work with the new
VEX 393 motors. They use the I2C hardware to generate the
necessary signals, and to read the data using Easy C or
Robot C for the Cortex.
One problem with using I2C on these platforms is that
the support is not part of the EasyC or Robot C language
yet. When it does become available, you should be able to
72 SERVO 02.2013
run the main I2C application for the
compass with minimal changes;
just substitute the names of the bit
banged routines for the low level
I2C routines provided by EasyC Pro
or Robot C.
USING THE EM COMPASS
So, how do we get true
bearings? By adjusting the EM
This is where you can make use of the optional
quadrature encoder to enter the declination angle instead
of having to modify the application. For this adjustment, we
use the moving ring on the compass to compensate for
declination from true north by adding or subtracting the
declination for our geographic location (latitude and
longitude). While these abnormalities are mostly caused by
the earth’s molten, they can be adjusted using the on-line
declination compensation calculator. You simply enter your
location (or zip code for the USA) and get the declination
value. Remember when using the declination values
that east declination is positive; west is negative. This
value is then added to the bearing returned from the
Get_Compass_Bearing function in the code.
USING OTHER KINDS OF I2C DEVICeS WITH VEX
Now that we know how to make the VEX 0.5
microcontroller work with our electronic compass, we can
use the firmware to work with other kinds of I2C sensors
and devices such as math coprocessors, serial EEPROMs,
and even LCD displays.
This can be done by tailoring the main I2C application
and customizing it for the specific device in question using
its datasheet (as discussed earlier). To do this, we look up
the necessary I2C command bytes on the respective
datasheet to initialize the device and get it started taking
sensor readings, or we can send it command bytes and
receive back data bytes.
Using some of these sensors, we could easily construct
a weather station, a home security system, or an advanced
robot. Some of these new I2C sensors include: