Got a Question? Contact me at enquiries@virtualfrontiers.co.uk

Digital Compass

Wiring Up The Compass

This is the digital compass I have. You can buy this from as little as £0.99 on eBay. There are 4 pins on this chip but we only need to use four of them. We don’t need to connect DRDY to anything. I have wired it up as follows: Compass Raspberry Pin # VCC 3.3v (Pin #19) GND GND (Pin #25) SCL GPIO2 (Pin #3) SDA GPIO3 (Pin #5)

Installing the Software

First we need to enable I2C on the Pi. Edit the  /etc/modprobe.d/raspi-blacklist.conf file and comment out the entry for I2C, then reboot. Now install the i2c tools. sudo apt-get install i2c-tools Now run i2cdetect to check that the compass can be read from. sudo i2cdetect -y 0 (for a Revision 1 board) or sudo i2cdetect -y 1 (for a Revision 2 board) If all goes well you should see the following:       0 1  2  3  4  5  6  7  8  9  a  b  c  d  e  f 00:          -- -- -- -- -- -- -- -- -- -- -- --  -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1e  -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  -- 70: -- -- -- -- -- -- -- -- The ‘1e’ is the address the compass has been found on. technically you are all good and ready to go, however you will probably find that the compass readings will be a bit wonky when you come to use it. This is because it needs to be calibrated. Every compass is unique and needs it’s own calibration settings. You can find instructions on how to read date from, and calibrate the compass here. Note Added 11/04/2015: in the latest version of Raspbian, somethign appears to have broken i2c-tools. If you run the i2cdetect command get the following error: Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory you need to edit the /boot/config.txt file and add the following lines: device_tree=bcm2708-rpi-b.dtb device_tree_param=i2c1=on device_tree_param=spi=on