Accessing the compass programmatically
Now that the device is connected, you'll need to configure access via the software. Following are the steps:
In order to access the compass capability, you'll need to enable the I2C library on Raspberry. The first step in enabling the analog-to-digital converter (ADC) is to enable the I2C interface. The I2C interface is a synchronous serial interface and provides more performance than an asynchronous Rx/Tx serial interface. The SCL data line provides a clock while the data flows on the SDA line. The bus also provides addressing so that more than one device can be connected to the master device at the same time. To enable this bus, run
sudo raspi-config
and select the 8 Advanced Options, as follows:Then go to the A7 I2C selection and enable the I2C, as shown in the following:
Make all the selections to enable the I2C interface and load the library, and then reboot Raspberry Pi.
You'll also need to edit the
/etc/modules
file and add the following two...