{"id":13,"date":"2014-04-16T13:00:33","date_gmt":"2014-04-16T13:00:33","guid":{"rendered":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/?p=13"},"modified":"2014-04-25T08:43:23","modified_gmt":"2014-04-25T08:43:23","slug":"using-i2c-with-the-raspberry-pi-step-2-sparkfun-9dof-sensor-stick","status":"publish","type":"post","link":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/2014\/04\/16\/using-i2c-with-the-raspberry-pi-step-2-sparkfun-9dof-sensor-stick\/","title":{"rendered":"Using I2C with the Raspberry Pi, Step 2: SparkFun 9DOF Sensor Stick"},"content":{"rendered":"<p>The hardware I&#8217;m using here is a Raspberry Pi Type A, described in detail <a href=\"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/2014\/03\/18\/the-starting-point\/\">here<\/a>. My previous post (<a href=\"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/2014\/03\/23\/using-i2c-with-the-raspberry-pi-step-1-modules-and-packages\/\">Part 1: Modules and Packages<\/a>) configured the Raspberry Pi to use the I2C connection. The aim in this post is to connect to a <a href=\"http:\/\/www.sparkfun.com\/products\/10724\">SparkFun 9DOF Sensor Stick<\/a> (SEN-10724) which has a 3-axis accelerometer (ADXL345), a 3-axis gyro (ITG-3200) and a 3-axis compass \/ magnetometer (HMC5883L) all sharing an I2C interface.<br \/>\n<div id=\"attachment_76\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/files\/2014\/04\/RPi-SensorStick.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-76\" src=\"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/files\/2014\/04\/RPi-SensorStick-300x235.jpg\" alt=\"Raspberry Pi Type A connected via I2C with a SparkFun 9DOF Sensor Stick (SEN-10724)\" width=\"300\" height=\"235\" class=\"size-medium wp-image-76\" srcset=\"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/files\/2014\/04\/RPi-SensorStick-300x235.jpg 300w, https:\/\/blogs.ncl.ac.uk\/francisfranklin\/files\/2014\/04\/RPi-SensorStick.jpg 700w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-76\" class=\"wp-caption-text\">Raspberry Pi Type A connected via I2C with a SparkFun 9DOF Sensor Stick (SEN-10724)<\/p><\/div><br \/>\nThere are three separate devices on the sensor stick all hooked up to the same I2C bus. You can see the addresses listed below. The HMC5883L compass \/ magnetometer uses address 1e. The ADXL345 accelerometer uses address 53. The ITG-3200 gyroscope uses address 68. (The &#8216;UU&#8217; at address 3b indicates an address reserved by the kernel, but I don&#8217;t know for what.)<\/p>\n<pre style=\"margin-left: 20px;background-color: #cccccc;height: 200px;overflow: auto;padding: 8px\">~ $ sudo i2cdetect -y 1\r\n     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\r\n00:          -- -- -- -- -- -- -- -- -- -- -- -- -- \r\n10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1e -- \r\n20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \r\n30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- \r\n40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \r\n50: -- -- -- 53 -- -- -- -- -- -- -- -- -- -- -- -- \r\n60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- \r\n70: -- -- -- -- -- -- -- --<\/pre>\n<p><b>2. Connecting to the Sensor Stick<\/b><\/p>\n<p>I&#8217;m not the first to use this stick, and there is, for example, a project by Peter Bartz which uses the stick:<br \/>\n<a href=\"http:\/\/github.com\/ptrbrtz\/razor-9dof-ahrs\/wiki\/Tutorial\">Attitude and Heading Reference System (AHRS)<\/a>. More useful, perhaps, is Rolfe Schmidt&#8217;s muCSense work with it <a href=\"http:\/\/chionophilous.wordpress.com\/2012\/02\/10\/connecting-to-sparkfuns-9dof-sensor-stick-i2c-access-to-adxl345-itg-3200-and-hmc5843\/\">here<\/a> and <a href=\"http:\/\/chionophilous.wordpress.com\/2012\/08\/28\/sensorlib-using-calibration\/\">here<\/a>.<\/p>\n<p>All three I2C devices have open source (MIT license) C++ device libraries available from <a href=\"http:\/\/www.i2cdevlib.com\/\">I2Cdevlib<\/a>:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.i2cdevlib.com\/devices\/adxl345\">3-axis accelerometer (ADXL345)<\/a><\/li>\n<li><a href=\"http:\/\/www.i2cdevlib.com\/devices\/itg3200\">3-axis gyro (ITG-3200)<\/a><\/li>\n<li><a href=\"http:\/\/www.i2cdevlib.com\/devices\/hmc5883l\">3-axis compass \/ magnetometer (HMC5883L)<\/a><\/li>\n<\/ul>\n<p>These rely on the underlying Wire class written for the Arduino, however, so a Raspberry Pi implementation of the Wire class is necessary (and one or two other miscellaneous functions).<\/p>\n<p>I am currently working on this &#8211; find the latest source <a href=\"http:\/\/github.com\/FJFranklin\/i2cdevlib\">here<\/a>, and a discussion topic <a href=\"http:\/\/www.i2cdevlib.com\/forums\/topic\/137-raspberry-pi\/\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The hardware I&#8217;m using here is a Raspberry Pi Type A, described in detail here. My previous post (Part 1: Modules and Packages) configured the Raspberry Pi to use the I2C connection. The aim in this post is to connect to a SparkFun 9DOF Sensor Stick (SEN-10724) which has a 3-axis accelerometer (ADXL345), a 3-axis <a href='https:\/\/blogs.ncl.ac.uk\/francisfranklin\/2014\/04\/16\/using-i2c-with-the-raspberry-pi-step-2-sparkfun-9dof-sensor-stick\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1692,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[16,13,17,15,10,11,14,12,3],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","tag-accelerometer","tag-adxl345","tag-gyro","tag-hmc5883l","tag-i2c","tag-imu","tag-itg-3200","tag-sen-10724","tag-type-a","category-2-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/users\/1692"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":44,"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":93,"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/posts\/13\/revisions\/93"}],"wp:attachment":[{"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ncl.ac.uk\/francisfranklin\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}