Processing Sudden Motion Sensor Library

SMS Axes

Thanks to the open source Unimotion library by Lincoln Ramsay, I have developed a java native interface that allows access to the Apple Sudden Motion Sensor available in powerbooks (and macbooks) since 2005.

Download the library sms.zip. Source code for unimotion.c and Unimotion.java is contained in the src directory.

Available functions:

// Return x, y, and z values as array
public static int[] getSMSArray();
 
// Return just the X
public static int getSMSX();
 
// Return just the Y
public static int getSMSY();
 
// Return just the Z
public static int getSMSZ();

Example code:

import sms.*;
 
void setup() {
  size(200,200);
}
 
void draw() {  
  int[] vals = Unimotion.getSMSArray();
  println(vals[0] + " " + vals[1] + " " + vals[2]);
}

History of Motion

  • Written by Christian Klein
  • JNI Implementation of motion by Dave Chatting
  • Modified for iBook compatibility by Pall Thayer
  • Modified for Hi Res Powerbook compatibility by Pall Thayer
  • Modified for MacBook Pro compatibility by Randy Green
  • Disparate forks unified into UniMotion by Lincoln Ramsay
  • Made into a Java Native Interface by Daniel Shiffman
    • http://allthingsalceste.com Dan

      seems to work in my black macbook. Thanks!

    • Claudio Midolo

      i’ve installed it but how to make it work?
      with the code in the example I get :

      java.lang.UnsupportedClassVersionError: sms/Unimotion (Unsupported major.minor version 49.0)
      at java.lang.ClassLoader.defineClass0(Native Method)

      Thanks!

    • http://www.abstractmachine.net Douglas Edric Stanley

      I did a quick check on my MacBook. I just threw up a couple lines moving about. It works great.

      The only wierd thing was it said:

      >Detecting SMS
      >Detected SMS type 4 (macbookpro)

      Whereas I’m on a MacBook. But this is such a minor detail I could care less.

    • http://www.geocities.jp/classiclll_newweb/ classiclll_jp

      I have no AppleNote. And I become to want to get one.

      Now,
      What is the returned value? Location, Velocity, Acceleration?

    • james

      douglas – the message is generated by unimotion’s sms type detection code. check out unimotion.c (in daniel’s src folder) and search for “macbookpro”. unimotion seems to label all macbooks (sms hardware type 4) as “macbookpro”. no biggie.

    • Roy Vanegas

      Tested on a 2 GHz intel Core Duo MacBoo Pro running Mac OS X v10.4.8. Works sweetly!

    • Pingback: dasAutomat.com » Blog Archive » Analog Laptop Extension: Marionette

    • http://www.stanford.edu/~tanders Todd Anderson

      Yeah, it even works on an iBook G4 bought in August 2005. Thanks!

    • cw wang

      It’s working great on my MacBook Pro. I made a game called Tilt SCREAM Pong. http://futurefeeder.com/index.php/archives/2007/01/02/tilt-scream-pong/

    • Pingback: color fun at Syed Salahuddin

    • Tony

      Hey people,

      I downloaded the zip file to my desktop, does anyone know how to set it up so i can use the library in eclipse??

    • Tony

      Its ok i answered my own question, just needed to set a build path. If anyone needs specifics just leave a post.

    • Pingback: The Apple Sudden Motion Sensor (SMS) to Flash | labs.boulevart

    • http://www.freebiesms.co.uk Dan

      I’m getting the same error

      java.lang.UnsupportedClassVersionError: sms/Unimotion (Unsupported major.minor version 49.0)
      at java.lang.ClassLoader.defineClass0(Native Method)

    • http://www.shiffman.net Daniel

      Dan: Are you on a PC by any chance? The library won’t work on a PC. Otherwise, let me know your Mac OS version, Processing version, etc. . .

    • http://www.alexmil.de alex

      hi
      amazing work!
      just one question. have you ever tried to work with the environment light sensor. or can you tell me how i can get the lightsensor data in flash.

      i would be glad for any hint
      alex

    • another alex ;o)

      oh yeah – accessing the environment light sensor in java would be sweet – though I have to admint that I haven’t really looked at this matter yet – well possible that there is already some way to do that…

    • Pingback: URBANGAP | URBANBLOG: web, multimedia e non solo » Tilt SCREAM Pong

    • http://www.alexmil.de the old alex :-)

      hi. for everyone who wants to use the light sensor. a friend of mine hast developed such an api and but it on his blog:
      http://blog.formatlos.com

      have fun

    • http://www.tianguangroups.com 注册香港公司

      This article writes extremely well, I like very much, later I will be able to come here to have a look,Comes here to support your.

    • Juhana Siren

      Hi, this is great. I just wrote a sketch that does spectrum analysis (with the FFT class from Krister Olsson’s Ess library) on the output of the motion sensors. It was interesting to see how even the vibration of the internal hard drive shows up as a spike in the spectrum. Nevertheless, it’s hard to say how much of the output is sensor noise.

      Then again, the sensors do seem to be pretty darn sensitive. My typing makes the Z sensor go wild…

    • Pingback: angry-pixel » Blog Archive » aliens hate cows

    • http://www.etnaskynet.org Lucio

      Hello,

      How I can use it using Ecplise?

      Thanks,
      Lucio.

    • Carl

      Hi Guys,

      it works fine with my C2D MacBook.
      But one question.
      Can someone send me the Unimotion.h File to my mailadresse. (jahncarl@gmail.com)

    • Pingback: the King of Catan » Blog Archive » sudden Motion Sensor

    • Pingback: David Steele Overholt | Research: Testing Kit

    • Pingback: Your Macbook has an accelerometer. | brunokruse

    • jenni

      For those who haven’t figured it out, I put the library- and jar-files in System:Library:Java:Extensions on the Mac harddrive. I don’t know if that’s the way to do it, but it worked for compiling some code and no longer threw an unlinked error.

    • Charlie McDowell

      The posts here are all very old. I had sms working on my black macBook but it stopped.
      I’ve tried updating the library. The current message I get is:

      Exception in thread “Animation Thread” java.lang.UnsatisfiedLinkError: /Users/charlie/Documents/Processing/libraries/sms/library/libUnimotionLib.jnilib: no suitable image found. Did find: /Users/charlie/Documents/Processing/libraries/sms/library/libUnimotionLib.jnilib: no matching architecture in universal wrapper

      I’d love to get this working again but I’m stuck.

    • Charlie McDowell

      I’ve got it working again. I solved the problem by reverting to Java 5. Does anyone have it working with Java 6 on a Mac?

    • mik

      Anybody got it working under Snow Leopard?

    • http://tiagopedras.com Tiago Pedras

      Hey Daniel

      Do you have any insight on whether Snow Leopard and the most current versions of Processing and Java handle your code?

      Best regards

    • http://www.shiffman.net Daniel

      I think I heard it does not work on Snow Leopard unfortunately. I’ll look into updating it when I get a chance!

    • Suse

      has this library ever been used on an iphone/ipod touch? I was thinking about trying it once… do the sudden motion sensor and the iphones Three-axis gyro-sensor work in a similar way? any suggestions, thoughts?
      thanks already!
      and thanks for the library! it’s great! have done some interactive film with it :)

    • http://www.shiffman.net Daniel

      @Suse: the library only works with mac, iphone/ipods do not support Java. If you are interested in doing something similar on the iphone check out OF for the iphone:

      http://www.openframeworks.cc/setup/iphone

      Also, Processing for Android!

      http://wiki.processing.org/w/Android

      Good luck!

    • Anonymous

      is there any way to calibrate the sensor? at least in my computer its very unstable.
      for instance, my laptop lies still on the table and the values captured by sms have big variations over time.
      from
      println(vals[0] + ” ” + vals[1] + ” ” + vals[2]);
      i get all these different values…

      12 -1 260
      7 10 262
      8 7 274
      7 3 269
      25 -3 268
      10 7 263
      7 8 265
      10 12 265
      8 5 252
      8 13 280

      is there a way to estabilish thresholds or any other kind of filtering results or calibrate the sensor so it can be stable and read movement only when theres movement?

      tks
      eduzal

    • Anonymous

      These are great ideas for features for the library.  As of now nothing like that is implemented so you’d have to do any smoothing or calibration with your own logic.  Take a look at Processing’s lerp() and map() functions which may help you.

    • http://www.facebook.com/laval Valentine Lapchevsky

      great! thanks a lot.

      but can i extract some information about laptop moving not just rotation?

    • wbg

      I just ran your numbers through matlab to see what the distribution looks like….of course there aren’t enough to really see. But there is a case for believing that the third column looks like random variation with a true peak or outlier from the noise. From the first and second column I couldn’t say without more points.

      The variation can be thought of as noise. It may be random and have a “bell curve” distribution.

      A histogram will show you the distribution and excel can do that. You then would fit a curve to the histogram  by trial and error, another excel tool. Shouldn’t be too hard to write a sub routine to look for values outside the curve by some amount you design. That is, points at least one standard deviation from the mean (or the peak point of the hist).

      The curve can be built from the output of the excel fitting tool. There are several online ones too that I have not used but know they exist.

      This is my 2 cents trying to be smart…..I’m not that experienced though…!
      cheers