Home           Info Request           Quote/Order           Contact           Site Map           About           Search           Support/FAQ  

 ARobot Digital Compass App Note
Back to ARobot Projects Page

This application note in PDF format

Digital Compass on ARobot

A compass can be a valuable sensor that your robot can use to navigate the world. The Dinsmore 1490 compass is a cheap and durable unit that is relatively easy to interface to. It provides 8 headings (N, NE, E, SE, S, SW, W, and NW). 4 signals, N,S,E,W are read by the Basic Stamp II controller to determine the robot’s heading.

There are more expensive units available but for simplicity sake we’ll stick with the Dinsmore. This application note will require soldering, cabling, and mounting which includes drilling and cutting of metal or plastic.

      Parts List
The Dinsmore compass can be found on the web: http://www.dinsmoresensors.com/

The wire is generally used for wire wrapping but it makes excellent point to point soldering on circuits. All three colors are not necessary, but it makes it easier to track wires later when trouble shooting. Power wires can be red, signals can be blue, and ground can be white. The compass can be soldered directly into the perf board but we highly suggest using a socket created by cutting IC sockets into 4) 3-pin sections (we'll discuss this more later). The dual row header and the 10 pin connector are used to attach the compass PCB to ARobot’s expansion connector. The aluminum brackets are used to mount the compass to ARobot’s body away from motors and other devices that create magnetic fields. Some of these electronic parts can also be found at Mouser Electronics http://www.mouser.com or Digi-Key http://www.digi-key.com.

   Part                       Part #              Price
Dinsmore compass              1490                $14.00
Perf board                    RS # 276-148        $1.49
Wire, red 30awg               RS # 278-501        $2.99
Wire, white 30awg             RS # 278-502        $2.99
Wire, blue 30awg              RS # 278-503        $2.99
16 pin IC sockets (2)         RS # RSU11661980    $.59
Dual row 40 pin header        RS # RSU11323813    $1.19
10 pin connector              RS # RSU11929643    $.49
40 conductor IDE cable        RS #278-780         $6.99  Or use an IDE disk drive cable.
Aluminum brackets             Hardware store      $4.00

This circuit will be created on a perf board. This means that the wires will be soldered to the components and will be permanent. The compass has 4 sides, each with 3 pins. Since a socket like this isn’t available, we’ll make one by cutting an IC socket to create 4) 3-pin sockets. We’ll arrange these in a square pattern to match the pins of the compass. Select an area on the perf board for the compass. Keep in mind that a 10 pin dual row header and a mounting hole will be needing space also. Drill the mounting hole first, then mount and solder the new compass sockets and the 10 pin connector. Put solder on each pin of each socket so they will accept wire easily. Now begin wiring the circuit. Cut each wire longer than is needed. Strip about 1/10" off each end of the wire. There is no need to tin the wire. Solder each connection carefully according to the pinout below. Avoid shorting to surrounding pins. Another soldering technique that will save time is to daisy chain the connections. Cut a real long wire. Strip only one end. Attach that end to the PCB, determine length and strip a section of wire right there. Attach that exposed wire to the connection point. Repeat until everything on that connection is complete.


!! Incorrect wiring will damage compass !!

10 Pin Header Connector Pinout

  1=GND, to all pin 2’s
  4=+5v, to all pin 1’s
  7=West signal
  8=South signal
  9=East signal
  10=North signal
compass compass

The cable in this example is constructed using a 40 pin IDE disk drive cable which is commonly available at computer stores. You can build your own cable using 40 pin flat cable and a 40 pin dual row header connector. Cut the cable so that the greatest length of cable is attached to one of the 40 pin connectors. The total length will depend on your mount arrangement. Then peel off the first 10 wires of that cable (be sure to start at wire #1). Attach the 10 pin connector to these 10 pins. Be sure to connect wire #1 to pin 1 of the connector (and wire #2 to pin 2, etc.). Now plug the cable into the compass board but NOT ARobot’s controller board yet.

Before the compass is installed into the PCB and before the cable is connected to the expansion connector, testing of the soldering and wiring needs to be performed. Test for continuity between power and ground. There should be NO continuity there. If there is and the power is turned on, ARobot COULD BE DAMAGED! Now check for continuity between the output pins on the compass and the 10 pin connector. You should have only one pin connected to one output. Then check for continuity between power and any of the output pins. There should be NO continuity here. Then connect the cable to ARobot’s expansion connector and turn on power. Check for +5v on the correct compass socket pins. This is very important because incorrect wiring can damage the compass. Notice that the drawing of the compass pinout is the TOP VIEW. Now turn power off and install the compass sensor. It doesn’t matter which direction the device is turned. Insure that all pins connect with their socket pin. Installation is difficult because there are 12 pins to deal with. Use needle nose pliers to insert the leads. Try not to bend the leads when inserting the device.

Since the compass sensor uses the Earth’s magnetic field to sense direction, it’s very important to mount the sensor away from motors and speakers – preferably high above them. We suggest building a mast of 4”-12” tall to mount the compass. The mast can be built using aluminum plates and L brackets from a hardware store, or plastic from discarded toys. Minimize the number of steel nuts and screws that are near the sensor.

Use the following software example as a building block for your own program. You can download this program from our web site at http://www.robotics.com/arobot

You can download this program here.

'compass.bs2    Arrick Robotics   www.robotics.com
'This routine demonstrates how to use a Dinsmore
'digital compass sensor.  The compass gives 8 
'directional headings (N,NE,E,SE,S,SW,W,NW).

heading var     byte(2)

        gosub   compass          'get heading.
        'print heading to debug window.
        debug "heading = ",str heading\2,cr  

        pause 500        'wait half a second.
        goto  main       'keep looping.

'this routine returns the direction of the robot.
'the variable heading has a string that tells the 
'direction of the robot.

        if in4=0 then compassn  'check if north.
        if in2=0 then compasss  'check if south.
        if in5=0 then compassw  'check if west only.

        heading(0)="E"          'Set East.
        heading(1)=" "

        heading(0)="W"          'Set West.
        heading(1)=" "

        if in5=0 then compassnw   'West?
        if in3=0 then compassne   'East?
        heading(0)="N"            'Set North.
        heading(1)=" "

        if in5=0 then compasssw   'Also west?
        if in3=0 then compassse   'Also east?
        heading(0)="S"            'South only?
        heading(1)=" "

        heading(0)="N"          'Set Northwest.

        heading(0)="N"          'Set Northeast.

        heading(0)="S"          'Set Southwest.

        heading(0)="S"          'Set Southeast.

If the compass outputs were wired to different input pins then the software will need to be adjusted to achieve the correct directional output. The best place to start on trouble shooting is to check the circuit connections. Pull out the compass and unplug the PCB. "Beep" out every connection to ensure that it is connected to the right place. Next, check for shorts. Turn the board over to the solder side. Examine very closely all solder joints. The cable can also be a source of problems. Check to make sure that pin 1 of the expansion connector connects to pin 1 of the compass PCB connector (check pin 2 to pin 2, pin 3 to pin 3, all the way to 10). Then check for shorts between wires. See if wire 10 is connected to wire 9 (and wire 9 to wire 8, etc).

Here's are some useful sources for parts:

  Home           Info Request           Quote/Order           Contact           Site Map           About           Search           Support/FAQ  
Copyright (c) Arrick Robotics - ArrickRobotics.com