{"id":65,"date":"2010-01-31T21:14:35","date_gmt":"2010-01-31T21:14:35","guid":{"rendered":"http:\/\/www.coolfactor.org\/blog\/?p=65"},"modified":"2010-02-03T03:22:58","modified_gmt":"2010-02-03T03:22:58","slug":"hacking-the-wii-motion-plus","status":"publish","type":"post","link":"http:\/\/www.coolfactor.org\/blog\/2010\/01\/31\/hacking-the-wii-motion-plus\/","title":{"rendered":"Hacking the Wii Motion Plus"},"content":{"rendered":"<p>I&#8217;ve been looking for a 3-axis gyroscope recently, and I came across the Wii Motion Plus. Fortunately, other people have done the hard work of reverse engineering the protocol and written this up <a href=\"http:\/\/randomhacksofboredom.blogspot.com\/2009\/06\/wii-motion-plus-arduino-love.html\">elsewhere<\/a>. In short, it&#8217;s a nice simple I2C interface.<\/p>\n<p>So I bought one.<br \/>\n<!--more--><br \/>\nTo have a little play with it, I knocked up a simple parallel port I2C interface on some breadboard, using a bunch of random NPN transistors that I had lying around. It doesn&#8217;t help that the parallel port on my PC (like most PCs) runs at 5V and the Wii Motion Plus wants 3V3, but that&#8217;s what transistors and breadboard are for, after all.<\/p>\n<div id=\"attachment_66\" style=\"width: 460px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.coolfactor.org\/blog\/wp-content\/uploads\/2010\/01\/IMG_8568.jpg\"><img aria-describedby=\"caption-attachment-66\" loading=\"lazy\" src=\"http:\/\/www.coolfactor.org\/blog\/wp-content\/uploads\/2010\/01\/IMG_8568-768x1024.jpg\" alt=\"\" title=\"I2C interface\" width=\"450\" height=\"600\" class=\"size-large wp-image-66\" srcset=\"http:\/\/www.coolfactor.org\/blog\/wp-content\/uploads\/2010\/01\/IMG_8568-768x1024.jpg 768w, http:\/\/www.coolfactor.org\/blog\/wp-content\/uploads\/2010\/01\/IMG_8568-225x300.jpg 225w, http:\/\/www.coolfactor.org\/blog\/wp-content\/uploads\/2010\/01\/IMG_8568.jpg 1944w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><p id=\"caption-attachment-66\" class=\"wp-caption-text\">I2C interface on breadboard<\/p><\/div>\n<p>What are the LEDs for, you may ask? Well, I had to figure out which parallel port pin was hooked up to which wire somehow, didn&#8217;t I? It was easier to recycle and old cable knocked up years ago for another hack than to go out and get a new 25 pin D plug and spend time with the soldering iron.<\/p>\n<p>The Wii Motion Plus is the small white thing in the background, just in front of the power supply.<\/p>\n<p>So I implemented some simple I2C bitbanging code and after shaking the last of the bugs out, I was ecstatic to see some numbers coming out of it that seemed to represent the physics of what I was doing to the device.<\/p>\n<p>Obviously, I couldn&#8217;t leave it at that. I wanted to know how it behaved in a slightly more complex test case. So after speeding up the I2C code a bit to get closer-to-realtime readings, I devised a cunning demonstration.<\/p>\n<p>I used SDL and OpenGL to knock up a cube, rotating around its centre. Instead of various non-interactive pretty spinning things that you can do with a cube to make a demo, in this case I integrated the readings from the Wii Motion Plus to form a rotation matrix. Rotating the Wii Motion Plus causes similar rotation to apply to the cube.<\/p>\n<p>After guessing at some scaling factors, I got &#8220;close enough&#8221;, and I was rather impressed with the responsiveness of it all. Other than the few times when the wires fell out while I was moving it, the system was responsive and quite intuitive. It did drift a little, as expected with a gyro and also as expected when I&#8217;m not taking samples as often as I could. I think a proper hardware or microcontroller I2C implementation would be less prone to overload and be able to integrate more accurately.<\/p>\n<p>Here&#8217;s the video:<\/p>\n<p><object width=\"425\" height=\"344\"><param name=\"movie\" value=\"http:\/\/www.youtube.com\/v\/7aj-JIishVo&#038;hl=en_US&#038;fs=1&#038;\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><param name=\"allowscriptaccess\" value=\"always\"><\/param><embed src=\"http:\/\/www.youtube.com\/v\/7aj-JIishVo&#038;hl=en_US&#038;fs=1&#038;\" type=\"application\/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"425\" height=\"344\"><\/embed><\/object><\/p>\n<p>Update: You can pull the source code using monotone from mtn.coolfactor.org (branch org.coolfactor.demo.wiimotionplus), or you can <a href=\"http:\/\/mtn.coolfactor.org\/viewmtn.py\/branch\/changes\/org.coolfactor.demo.wiimotionplus\">browse it here<\/a>.<\/p>\n<p>Note: This isn&#8217;t polished code, it&#8217;s just a hack. It works for the purpose of my demo, but it may not work for yours.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been looking for a 3-axis gyroscope recently, and I came across the Wii Motion Plus. Fortunately, other people have done the hard work of reverse engineering the protocol and written this up elsewhere. In short, it&#8217;s a nice simple &hellip; <a href=\"http:\/\/www.coolfactor.org\/blog\/2010\/01\/31\/hacking-the-wii-motion-plus\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/posts\/65"}],"collection":[{"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":6,"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":71,"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions\/71"}],"wp:attachment":[{"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.coolfactor.org\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}