Connecting a digital compass to the Raspberry Pi

One of the important pieces of information that might be useful for your robot, if it is going to plan its own path, is its direction of travel. So, let's learn how to hook up a digital compass to the Raspberry Pi.

There are several chips that provide digital compass capability, one of the most common is the HMC5883L, a 3-axis digital compass chip. This chip is packaged onto a module by several companies but almost all of them result in a similar interface. Here is a picture of one the GY-271 HMC5883L triple axis compass magnetometer sensor module available at a number of online retailers:

Connecting a digital compass to the Raspberry Pi

This type of digital compass uses magnetic sensors to measure the earth's magnetic field. The output of these sensors is then made accessible to the outside world through a set of registers that allow the user to set things like the sample rate and continuous or single sampling. The X, Y, and Z directions are the output using registers as well.

The connections to this chip are straightforward: the device communicates with Raspberry Pi using the I2C bus. If you are using the motor controller, then you can connect the device to the I2C bus on the controller board, and if you are using the motor controller to connect to the LIDAR, you'll need to connect the I2C bus to the GPIO pins on Raspberry Pi. At the back of the module, the connections are labelled as shown in the following image:

Connecting a digital compass to the Raspberry Pi

You then connect the module to the GPIO pins on Raspberry Pi. You need to connect the VCC pin on the module to Pin 1 3.3 V on Raspberry Pi and GND to Pin 9 GND. Then connect SCL on the module to Pin 5 GPIO3 and SDA to Pin 3 GPIO2 on the Raspberry Pi. Note that you will not connect the DRDY (Data Ready) pin. Now, you are ready to communicate with the device.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.17.40