Sunday, March 6, 2016

Raspberry pi MPU9150 setup

We'll begin our journey by connecting the inertial sensors (accelerometer and gyroscope) and the compass (magnetometer) to the pi. With these sensors we'll be able to estimate 3 out of the 6 dimensions describing a quadcopter in flight. Those 3 being roll, pitch and yaw. Latitude, longitude and altitude will come later.

The sensor I chose is a MPU9150. It comes with a 3-axis accelerometer, 3-axis gyroscope and a 3-axis magnetometer embedded on the board. These sensors are then connected to the pi under the following diagram:
Image from:
 http://www.slideshare.net/steveonjava/java-8-for-tablets-pis-and-legos
Next is accessing the MPU9150 from inside a programing language. RTIMULib is an open source library for a collection of navigation based sensors for use on the raspberry pi. Among the supported ones is the MPU9150. The library also supports python which is why I'll be using it for the foreseeable future. It's project page contains installation instructions, follow those and move on to the next steps.

After wiring the MPU9150 to the pi and installing RTIMULib, the pi is almost ready to use the sensors. The last step is to enable i2c on the pi. There are a few ways to do this, but heres what worked for me. Run:
sudo nano /etc/modules

At the bottom add:
i2c-dev

The file /etc/modules now should look something like:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
i2c-dev

Reboot the pi. This should have created 'i2c-0' or 'i2c-1' in In the /dev/ directory. One last problem that might come up is that the pi does not grant permission to the i2c lines by default. The easiest way I know of enabling it is running the following command:

sudo chmod o+rw /dev/i2c*

This gives everyone permission to the i2c line only for the current session. It will have to be re-entered if the pi restarts. I'll update it with a permanent method when I find one.

The MPU9150 should now be fully accessible to the pi. On the project repo I've uploading a demo which reads from the MPU9150 for 10 seconds and outputs the results to the terminal. Before I dive into fusing the sensors together to give orientation, they need to be calibrated. I'll go over calibration in the next series of post.

Thanks for reading

No comments:

Post a Comment