<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eclecticc &#187; magnetometer</title>
	<atom:link href="http://eclecti.cc/tag/magnetometer/feed" rel="self" type="application/rss+xml" />
	<link>http://eclecti.cc</link>
	<description></description>
	<lastBuildDate>Tue, 20 Dec 2011 07:16:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Easy Absolute Orientation: PNI SpacePoint Fusion in Python</title>
		<link>http://eclecti.cc/hardware/easy-absolute-orientation-pni-spacepoint-fusion-in-python</link>
		<comments>http://eclecti.cc/hardware/easy-absolute-orientation-pni-spacepoint-fusion-in-python#comments</comments>
		<pubDate>Mon, 01 Feb 2010 08:42:21 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[imu]]></category>
		<category><![CDATA[magnetometer]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[spacepoint fusion]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=414</guid>
		<description><![CDATA[My college roommate Donnie mentioned the PNI SpacePoint Fusion in comments of the HMC5843 post, and it seemed too good to be true.  A 9 DOF controller (3 axes each of magnetometer, accelerometer, and gyro) with a Kalman filter to calculate a smooth quaternion that interfaces as a USB HID device, all for under $100.  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://eclecti.cc/files/2010/01/spacepoint.jpg"><img class="alignnone size-large wp-image-439" title="That is the cel shading tutorial from Panda3D, with the character quaternion set by the SpacePoint Fusion." src="http://eclecti.cc/files/2010/01/spacepoint-700x525.jpg" alt="SpacePoint Fusion" width="700" height="525" /></a></p>
<p>My college roommate Donnie mentioned the <a href="http://www.pnicorp.com/products/all/spacepoint-fusion">PNI SpacePoint Fusion</a> in comments of the <a href="http://eclecti.cc/hardware/hmc5843-magnetometer-library-for-arduino">HMC5843 post</a>, and it seemed too good to be true.  A 9 DOF controller (3 axes each of magnetometer, accelerometer, and gyro) with a <a href="http://en.wikipedia.org/wiki/Kalman_filter">Kalman filter</a> to calculate a smooth quaternion that interfaces as a USB HID device, all for under $100.  I&#8217;d be surprised if PNI is making any profit on it.  I sound more like a shill than I&#8217;m normally comfortable with, but I&#8217;m truly impressed with this gadget.  I have some plans for it involving a <a href="http://www.microvision.com/showwx/">Microvision SHOWWX</a> that I&#8217;m quite excited about; I&#8217;ll write more on that when it&#8217;s available in a couple of months.</p>
<p><a href="http://eclecti.cc/files/2010/01/innards.jpg"><img class="alignnone size-large wp-image-442" title="There's a mini usb port inside too, how convenient!" src="http://eclecti.cc/files/2010/01/innards-700x525.jpg" alt="SpacePoint Fusion Innards" width="700" height="525" /></a></p>
<p>PNI provides some Windows only <a href="http://www.pnicorp.com/support/downloads/spacepoint-fusion">sample apps</a> that show off how weirdly stable and precise the SpacePoint Fusion is.  Luckily, since it&#8217;s a normal USB HID device (redundant, I know), and PNI provides <a href="http://www.pnicorp.com/files/SpacePoint%20Fusion%20Game%20Pad%20Application%20Note.pdf">application notes</a>, it&#8217;s easy to use on any platform.  I wrote a Python module that uses <a href="http://libhid.alioth.debian.org/">libhid</a> via python-hid to make it easy to prototype with in Linux.  The usage is pretty simple, as shown below.  Note that when plugging the device in, you need to keep it still for a few seconds while the gyros are calibrated.  After that, the quaternion, accelerometer, and button data can be updated 62.5 times a second.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> spacepoint
<span style="color: #66cc66;">&gt;&gt;&gt;</span> fusion = spacepoint.<span style="color: black;">SpacePoint</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion.<span style="color: black;">quat</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#40;</span><span style="color: #ff4500;">0.987518310546875</span>, -<span style="color: #ff4500;">0.04425048828125</span>, -<span style="color: #ff4500;">0.04119873046875</span>, <span style="color: #ff4500;">0.145294189453125</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion.<span style="color: black;">accel</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#40;</span>-<span style="color: #ff4500;">0.054016113354999999</span>, <span style="color: #ff4500;">0.018859863306999999</span>, -<span style="color: #ff4500;">0.89648437622400001</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion.<span style="color: black;">buttons</span><span style="color: black;">&#41;</span>
<span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> fusion.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>fusion<span style="color: black;">&#41;</span>
accel: <span style="color: black;">&#40;</span>-<span style="color: #ff4500;">0.054016113354999999</span>, <span style="color: #ff4500;">0.018859863306999999</span>, -<span style="color: #ff4500;">0.89648437622400001</span><span style="color: black;">&#41;</span>
 quat: <span style="color: black;">&#40;</span><span style="color: #ff4500;">0.97186279296875</span>, -<span style="color: #ff4500;">0.233428955078125</span>, -<span style="color: #ff4500;">0.030548095703125</span>, <span style="color: #ff4500;">0.005401611328125</span><span style="color: black;">&#41;</span>
 buttons: <span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span></pre></div></div>

<p><strong>Update on February 7, 2010:</strong> I emailed PNI about a bug in the firmware, and got the following response:</p>
<blockquote><p>Thank you for submitting the SpacePoint bug regarding libusb, Python, and Linux.  You&#8217;re right!  There is a bug in the SpacePoint FW that prevented opening interface 1 without opening interface 0 when using libusb under Linux.  While your work around was effective in allowing the device to operate normally, one should be able to open interface 1 directly without the work around.  We were able to use your Python source code to quickly diagnose and repair the bug.  Please see the attached for the modified Python script.  Please feel free to post this paragraph, the modified code, and all bragging rights on your blog (http://eclecti.cc/).</p></blockquote>
<p>Units being shipped now have the fix.  I modified the Python module to handle units both with and without the firmware fix and bumped the version to 0.2.</p>
<p><strong>Download:<a href="http://eclecti.cc/files/2010/02/spacepoint-0.2.tar.gz"><br />
SpacePoint Python Module</a></strong> or<br />
Standalone <strong><a href="http://eclecti.cc/files/2010/01/spacepoint.py">spacepoint.py</a></strong></p>
<h3>Setting udev rules to get the permissions right</h3>
<p>In most cases, the module will just work properly.  However, if you get the following error, you probably don&#8217;t have the right permissions to access the usb device.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> spacepoint
<span style="color: #66cc66;">&gt;&gt;&gt;</span> fusion = spacepoint.<span style="color: black;">SpacePoint</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
hid_force_open failed <span style="color: #ff7700;font-weight:bold;">with</span> <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">code</span> <span style="color: #ff4500;">12</span>.</pre></div></div>

<p>On most modern Linux distros, you can fix this by setting a <a href="http://reactivated.net/writing_udev_rules.html">udev rule</a> for the device.  In Ubuntu Karmic Koala, saving the following as <code>/etc/udev/rules.d/45-spacepoint.rules</code> , running <code>sudo service udev restart</code> , and then unplugging and replugging in the device should fix it:</p>

<div class="wp_syntax"><div class="code"><pre class="cmake" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># PNI SpacePoint Fusion</span>
SYSFS{idVendor}==<span style="color: #912f11;">&quot;20ff&quot;</span>, SYSFS{idProduct}==<span style="color: #912f11;">&quot;0100&quot;</span>, MODE=<span style="color: #912f11;">&quot;0664&quot;</span>, GROUP=<span style="color: #912f11;">&quot;admin&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/hardware/easy-absolute-orientation-pni-spacepoint-fusion-in-python/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>HMC5843 Magnetometer Library for Arduino</title>
		<link>http://eclecti.cc/hardware/hmc5843-magnetometer-library-for-arduino</link>
		<comments>http://eclecti.cc/hardware/hmc5843-magnetometer-library-for-arduino#comments</comments>
		<pubDate>Mon, 16 Nov 2009 07:01:56 +0000</pubDate>
		<dc:creator>nrp</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[hmc5843]]></category>
		<category><![CDATA[i2c]]></category>
		<category><![CDATA[magnetometer]]></category>

		<guid isPermaLink="false">http://eclecti.cc/?p=344</guid>
		<description><![CDATA[I (finally) have a project taking up the idle cycles of my brain, the first step of which involves figuring out how to use a magnetometer.  The project will eventually use the digital compass, accelerometers, perhaps a gyro, and maybe absolute forms of positioning like an IR camera.  I&#8217;m being slightly vague about this project [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://eclecti.cc/files/2009/11/hmc5843.jpg"><img class="size-large wp-image-346" title="The Arduino Pro Mini up top is what will eventually be using the magnetometer" src="http://eclecti.cc/files/2009/11/hmc5843-700x525.jpg" alt="HMC5843 and Arduino" width="700" height="525" /></a></p>
<p>I (finally) have a project taking up the idle cycles of my brain, the first step of which involves figuring out how to use a magnetometer.  The project will eventually use the digital compass, accelerometers, perhaps a gyro, and maybe absolute forms of positioning like an IR camera.  I&#8217;m being slightly vague about this project both because the idea is by far the coolest thing I&#8217;ve ever come up with and because it is still somewhat short of half baked.</p>
<p>Anyway, Honeywell recently released a rather reasonably priced three axis magnetometer, the <a href="http://www.ssec.honeywell.com/magnetic/datasheets/HMC5843.pdf" target="_blank">HMC5843</a>, which SparkFun carries a <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9371" target="_blank">breakout board</a> for.  It interfaces over i2c, which is conveniently supported in hardware by most AVR microcontrollers, including the ones used on Arduino.  Arduino is something of paradox.  On one hard, the hardware is so simple and easy to use, vastly cutting down on the amount of time I need to spend arranging parts on a breadboard.  On the other hand, computations that should take a few operations instead call long functions that get compiled into hundreds, and the IDE makes me want to stab a stick of RAM into my jugular.  Luckily, one can mitigate the downsides by using an external editor, communicating with cutecom/minicom, and using avr-libc instead of the Arduino libraries as much as possible.  Back to the project.</p>
<p>The actual circuit is fairly simple.  Analog pins 4 and 5 on the Arduino serve as i2c&#8217;s SDA and SDC lines, respectively.  I&#8217;m using a <a href="http://www.sparkfun.com/commerce/product_info.php?products_id=8745" target="_blank">level shifter</a> from SparkFun to get the Arduino&#8217;s 5v lines down to the 3.3v that the HMC5843 is looking for.  Note that one can skip this by using a 3.3v Arduino Pro.  The FTDI chip on the Arduino outputs 3.3v, which is brought out on the headers, allowing the level shifter and the magnetometer to be powered off the Arduino.</p>
<p>I tried using the Arduino Wire library for i2c communication, but had no luck.  Atmel made TWI, the i2c implementation on the AVR, fairly easy to use, so I read through the <a href="http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf" target="_blank">datasheet</a>, looked at some examples, and wrote my own Arduino library specifically for the HMC5843.  The current implementation is absolutely alpha, but it seems to read the x, y, and z values at 10 Hz correctly.  Note that you probably can&#8217;t use this library at the same time as Wire or another i2c library, and that it also doesn&#8217;t support having multiple i2c devices connected.  Its sole purpose is interfacing the HMC5843.  Here is an example sketch using it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;HMC.h&gt;</span>
&nbsp;
<span style="color: #993333;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  Serial.<span style="color: #202020;">begin</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">9600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// The HMC5843 needs 5ms before it will communicate</span>
  HMC.<span style="color: #202020;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>z<span style="color: #339933;">;</span>
  delay<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// There will be new values every 100ms</span>
  HMC.<span style="color: #202020;">getValues</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>x<span style="color: #339933;">,&amp;</span>y<span style="color: #339933;">,&amp;</span>z<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;x:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; y:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span>y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; z:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  Serial.<span style="color: #202020;">println</span><span style="color: #009900;">&#40;</span>z<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Continuing the theme of a different license for each set of code I release, this library is under a two clause BSD style license.  Please feel free to try it out and give me feedback/suggestions/patches/pedantic advice/flames.</p>
<p><strong>Download and extract into the hardware/libraries/ folder of your Arduino directory:<br />
<a href="http://eclecti.cc/files/2009/11/HMC.zip" target="_blank">HMC.zip</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://eclecti.cc/hardware/hmc5843-magnetometer-library-for-arduino/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.335 seconds -->

