Accessing the compass programmatically
In order to access the compass capability you'll need to enable the I2C library on the Raspberry Pi. The first step to enable the IMU 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.
Enabling this bus is done by running sudo raspi-config
, and selecting the Advanced Options, like this:
Once there, go to the I2C selection and enable the I2C, like this:
Say yes to all the selections to enable the I2C interface and load the library, then reboot the Raspberry Pi. Install the I2C tool kit by typing sudo apt-get install i2c-tools
. You can see if the I2C is enabled by typing sudo i2cdetect -y 1
, and you should see something like this:
You can see the device...