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:

Accessing the compass programmatically

Once there, go to the I2C ...

Get Raspberry Pi Robotic Projects - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.