[Acceleration] MMA7660 3-Axis Accelerometer Library

This is a library to interface with the MMA7660 (FC) 3 axis accelerometer module. It’s a very easy and small library, that returns the X Y and Z coordinates transformed into full degrees. It is written in cpp and you can use this with your arduino module. Below provided is example code and library provided for your ease. You only need 1 line of code to request the accelerometer data.

Download

Include this in your Arduino/Libraries folder.
Download: MMA7660.zip

Sample code

This code is also included in the zipfile in the above.

  1. #include Wire.h
  2. #include MMA7660.h
  3.  
  4. void setup()
  5. {
  6.   Serial.begin(9600);
  7.   MMA7660.init();
  8. }
  9.  
  10. void loop()
  11. {
  12.   int x,y,z;
  13.   delay(100);  There will be new values every 100ms
  14.   MMA7660.getValues(&x,&y,&z);
  15.   Serial.print(x );
  16.   Serial.print(x);
  17.   Serial.print( y );
  18.   Serial.print(y);
  19.   Serial.print( z );
  20.   Serial.println(z);
  21.  
  22. }

Tim Zaman

MSc Biorobotics. Specialization in computer vision and deep learning. Works at NVIDIA.

You may also like...

10 Responses

  1. Harry van Soolen says:

    Tim I would appreciate it if you could update and make all of the fixes required to the .h and .cpp files. I tried using your test but won’t compile. And yes I’m a Dutchman as well (Rotterdammer).

  2. Hi MMA7660 Expert Tim,

    As a young lad I used to play the piano accordion. Now, as a young pensioner (71), I converted an old 120- (sgl. switch-) button Farfisa accordion bass section into MIDI to play with my Tyros3. Each chord has 4 to 5 notes and sound terrific, but it was a hell of a job, for I had to diode wire all chord combinations ! 🙁
    I also love to create that accordion “bellow shake” and for that purpose paralleled the 10K Pot from my Yamaha (MFC10) MIDI foot controller to vary it via a LDR-LED control.

    I just discovered that $200 “HOT Hand 3” audio volume (etc.) controller.
    I suppose its built around that “MMA7660FC” chip or similar.
    My electronics hobby knowledge as to work out how this chip could control the brightness of a LED.
    Because, if I knew that I could easily control the LDR,
    Is that very complex? If not, please kick me in the direction to help myself…
    Thank you in advance, ol’ Joh in St’go de Chile 🙂

  3. Dee says:

    Hello, I think your blog might be having browser compatibility issues.
    When I look at your website in Safari, it looks fine but when opening in Internet
    Explorer, it has some overlapping. I just wanted
    to give you a quick heads up! Other then that, great blog!

  4. Alessandro Proglio says:

    I’m sorry, I wrote the last two lines in the wrong order, you have to replace

    Wire.receive

    with

    Wire.read

    • chandu says:

      i get the values but not change the values when the sensor was moved
      why ? can you help in this ?

  5. Manuel Montoya says:

    I get this error when I try to compile the test code

    In file included from MMA7660_test.cpp:2:
    C:Program Files (x86)arduino-1.0librariesMMA7660/MMA7660.h:29:22: error: WProgram.h: No such file or directory

    • Alessandro Proglio says:

      @Manuel Montoya:
      There are some changes needed since version 1 of Arduino:
      open the files MMA7660.cpp and MMA7660.h and replace the line
      #include "WProgram.h"
      with
      #include "Arduino.h"

      the Wire library now uses different methods, Ioy have to open MMA7660.cpp and replace
      Wire.send
      with
      Wire.write

      and
      Wire.read
      with
      Wire.receive

      • Tim says:

        Thanks a lot Alessandro :).

      • Jay says:

        I’m having the same problem, when I change what you suggested the error changes, now I get –

        Help?

        /Users/jasonscott/Documents/Arduino/libraries/MMA7660/MMA7660.cpp: In member function ‘void MMA::getValues(int*, int*, int*)’:
        /Users/jasonscott/Documents/Arduino/libraries/MMA7660/MMA7660.cpp:62: error: ‘class TwoWire’ has no member named ‘receive’
        /Users/jasonscott/Documents/Arduino/libraries/MMA7660/MMA7660.cpp:63: error: ‘class TwoWire’ has no member named ‘receive’
        /Users/jasonscott/Documents/Arduino/libraries/MMA7660/MMA7660.cpp:64: error: ‘class TwoWire’ has no member named ‘receive’

      • Rodrigo says:

        Sorry, I’m late… 😀

        You should rollback method receive() to read().

        http://arduino.cc/en/Reference/WireRead