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. Extract it to “. . ./Applications/Processing 0118/libraries” and you will have the following files:

  • sms.jar — contains the Unimotion class
  • libUnimotionLib.jnilib — The java native interface to Unimotion
  • 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

  • 23 Responses to “Processing Sudden Motion Sensor Library”  

    1. 1 Dan

      seems to work in my black macbook. Thanks!

    2. 2 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!

    3. 3 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.

    4. 4 classiclll_jp

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

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

    5. 5 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.

    6. 6 Roy Vanegas

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

    7. 7 Todd Anderson

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

    8. 8 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/

    9. 9 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??

    10. 10 Tony

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

    11. 11 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)

    12. 12 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. . .

    13. 13 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

    14. 14 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…

    15. 15 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

    16. 16 注册香港公司

      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.

    17. 17 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…

    18. 18 Lucio

      Hello,

      How I can use it using Ecplise?

      Thanks,
      Lucio.

    1. 1 dasAutomat.com » Blog Archive » Analog Laptop Extension: Marionette
    2. 2 color fun at Syed Salahuddin
    3. 3 The Apple Sudden Motion Sensor (SMS) to Flash | labs.boulevart
    4. 4 URBANGAP | URBANBLOG: web, multimedia e non solo » Tilt SCREAM Pong
    5. 5 angry-pixel » Blog Archive » aliens hate cows


    Leave a Reply