Initial report by John Schimmel, 25 October 2005

This Compass Module made exclusively by Parallax is a dual-axis magnetic field sensor built around the Hitachi HM55B IC. Parallax has made this compass IC accessible by providing Hitachi’s surface mount sensor chip with a 3 V onboard voltage regulator and resistor protection, all in a 0.3” wide 6-pin DIP module. Acquiring measurements from the module is made easy with a synchronous serial interface, and even easier with the commands SHIFTIN and SHIFTOUT. ^{This paragraph is pulled from the parallax compass documentation}

**Parallax Compass Module**

The compass module is ideally made for the Parallax's Basic Stamp but remember that the Stamp is just a glorified PIC! So anything you can do on a Basic Stamp you can do on a typical PIC with PICBasic - for example the SHIFTIN and SHIFTOUT commands are identical, along with many other commands.

The documentation that Parallax provides is incredibly useful, read it completely - several times. The first problem you'll encounter is that the code written for the Basic Stamp uses the arctan (ATN) function, PICBasic Pro has no arctan() function, some alternative solutions will be provided below as they are found. So don't worry about the missing PICBasic arctan, you really only need it for applications that need precise direction/degree information.

### Applications

- Mobile robot direction sensor
- Handheld electronic compass
- Weathervane indicator for remote weather stations
- Audible compass for the visually impaired
- Automotive electronic compass
- Compass jacket, pants or jewerly

### Electrical Characteristics

- To find out about the compass from the manufacturer - Hitachi's HM55B IC datasheet
- But the one you want to look at is really at is Parallax's datasheet documentation
- Buy it here at Parallax's online store
- Voltages
- Vcc = Supply Voltage = 4.8 - 5.2 Volts (standard ITP breadboard voltage safe!)
- Icc = Average active current = 5 mA
- Icc = Standby current = 2 mA
- Icc = Peak instanteous current = 30 mA (for about 5 micro-seconds)

- Magnetic Compass Sensor
- The compass module detects the magnetic fields parallel to the internal x and y axes. Think of trig class in 10th grade, the x-axis tells us (field strength) * cos(@) and the y-axis tells of the (field strength) * sin(@).
- The sensor reports both x and y
- +X = NORTH
- -X = SOUTH
- +Y = WEST
- -Y = EAST

- TESLA! MICRO-TELSA!
- The sensors detects microteslas. Tesla is the value of a magnet's flux or power divided by the area.
- From wikipedia, in the Earth's magnetic field at latitude of 50° is 20 µT (2×10-5 T) and on the equator at a latitude of 0° is 31 µT (3.1×10-5 T).

### Pin Descriptions

The 6 pins include:

- Din - Data Input Pin - used in SHIFTOUT command
- Dout - Data Output Pin - used in SHIFTIN command
- GND, Vss - Ground
- CLK - Clock Pin - used in SHIFTIN & SHIFTOUT commands
- EN - Enable Pin - used in SHIFTIN & SHIFTOUT commands
- Vcc, +5 Volts power

There are two ways to wire the compass, the first model uses 3 wires instead of 4

The data lines share a line into the PIC.

But the 4 wire hookup works fine too.

### Microcontroller Connections

### Code Sample

PICBasic Pro compass code does not provide angles, it simply finds NORTH, SOUTH, EAST & WEST.

### Work Arounds for ArcTan in PICBasic Pro

- Use PIC C
- Make a lookup table
- Buy a Floating Point Coprocessor IC
- Try to use vector math
- Arctan() - bit shifting code
- Learn assembly

### Typical Behavior

Sample data from the PICBasic Pro code:

x | y | -+x | -+y | abs(y/x) | =abs(y/x) |
---|---|---|---|---|---|

pointed northwest | |||||

5 | 12 | +x | +y | 12/5 | 20 |

3 | 13 | +x | +y | 13/3 | 40 |

4 | 12 | +x | +y | 12/4 | 30 |

pointed north | |||||

8 | 0 | +x | +y | 0/8 | 0 |

9 | 0 | +x | +y | 0/9 | 0 |

pointed northeast | |||||

-1 | -9 | -x | -y | 9/1 | 90 |

-1 | -10 | -x | -y | 10/1 | 100 |

pointed east | |||||

-12 | -11 | -x | -y | 11/12 | 0 |

-11 | -12 | -x | -y | 12/11 | 10 |

-12 | -11 | -x | -y | 11/12 | 0 |

pointed southeast | |||||

-23 | -2 | -x | -y | 2/23 | 0 |

-24 | -4 | -x | -y | 4/24 | 0 |

pointed south | |||||

-27 | 7 | -x | +y | 7/27 | 0 |

-26 | 8 | -x | +y | 8/26 | 0 |

pointed southwest | |||||

-20 | 18 | -x | +y | 18/20 | 0 |

-20 | 17 | -x | +y | 17/20 | 0 |

pointed west | |||||

-9 | 20 | -x | +y | 20/9 | 20 |

-10 | 21 | -x | +y | 21/10 | 20 |

### Application Notes

- Made a portable compass that indicates N, S, E, W with one LED always illuminated to indicate North.
- Processing application would be nice, maybe that will be next.
- The compass is small enough to work nicely with wearable projects.
- Would like to get the angles and arctan working in the PICBasic Pro environment.