Accessing the compass programmatically
In order to access the compass capability, you'll need to enable the I2C library on Raspberry. If you used the IR sensor and ADC additional hardware in Chapter 4, Avoiding Obstacles Using Sensors, you will have already done this. If not, follow these instructions to enable the I2C interface:
- Run
raspi-config
. Select the Configure advanced settings, as shown in the following screenshot:From the next selection page, select the Enable/disable automatic loading of the I2C interface, as shown in the following screenshot:
Then select yes, as shown in the following screenshot:
You'll also want to edit the file
/etc/modules
and add the linesi2c-bcm2708
andi2c-dev
, as shown in the following screenshot:And one final edit, change the last line in
/boot/config.txt
, as shown in the following screenshot:Now, reboot Raspberry Pi.
- With the device connected, you can see if the system knows about your device. To do this, type the following command:
You can see...