LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a MMA7660FC 3 Axis Accelerometer connected to Arduino Uno

Hello everyone. I am curretly working on a project to control the yaw, pitch and roll axes of a robotic gimbal wrist using an Arduino UNO and a LabView interface.

In a nutshell, I want to read data from a MMA7660FC 3-axis accelerometer connected to the Arduino UNO via I2C using LIFA, process the data, and then send it back to the Arduino UNO for driving the motors.


I have the MMA7660FC accelerometer connected to the Arduino Uno communicating via I2C. I am able to read the axis values with the Arduino IDE, but I need to read the values from each axis with LabView.

Any suggestions?


0 Kudos
Message 1 of 9
(9,463 Views)

If you post the working Arduino code for the accelerometer, it will be easier to port it over to LabVIEW.

0 Kudos
Message 2 of 9
(5,323 Views)

I downloaded a library for the MMA77660FC. The code I've been using just calls on the library.

#include <Wire.h>

#include "MMA7660.h"

MMA7660 accelemeter;

void setup()

{

          accelemeter.init(); 

          Serial.begin(9600);

}

void loop()

{

          int8_t x;

          int8_t y;

          int8_t z;

          float ax,ay,az;

          accelemeter.getXYZ(&x,&y,&z);

 

          Serial.print("x = ");

    Serial.println(x);

    Serial.print("y = ");

    Serial.println(y);  

    Serial.print("z = ");

    Serial.println(z);

 

          accelemeter.getAcceleration(&ax,&ay,&az);

    Serial.println("accleration of X/Y/Z: ");

          Serial.print(ax);

          Serial.println(" g");

          Serial.print(ay);

          Serial.println(" g");

          Serial.print(az);

          Serial.println(" g");

          Serial.println("*************");

          delay(500);

}

0 Kudos
Message 3 of 9
(5,323 Views)

This is the accelerometer register overview http://www.freescale.com/files/sensors/doc/app_note/AN3837.pdf

0 Kudos
Message 4 of 9
(5,323 Views)

Can you please either attach the full working code (i.e. with library) or link to same files?

0 Kudos
Message 5 of 9
(5,323 Views)

Thanks for your replies Nathan, I really appreciate your help on this.

Here it goes.

Link to the  downloadable library:

http://www.seeedstudio.com/wiki/File:DigitalAccelerometer_MMA7660FC.zip

Link to the accelerometer register chart:

http://www.freescale.com/files/sensors/doc/app_note/AN3837.pdf

cpp file   MMA7660.cpp :

#include <Wire.h>

#include "MMA7660.h"

/*Function: Write a byte to the register of the MMA7660*/

void MMA7660::write(uint8_t _register, uint8_t _data)

{

          Wire.begin();

          Wire.beginTransmission(MMA7660_ADDR);

          Wire.write(_register);  

          Wire.write(_data);

          Wire.endTransmission();

}

/*Function: Read a byte from the regitster of the MMA7660*/

uint8_t MMA7660::read(uint8_t _register)

{

          uint8_t data_read;

          Wire.begin();

          Wire.beginTransmission(MMA7660_ADDR);

          Wire.write(_register);

          Wire.endTransmission();

          Wire.beginTransmission(MMA7660_ADDR);

          Wire.requestFrom(MMA7660_ADDR,1);

          while(Wire.available())

          {

                    data_read = Wire.read();

          }

          Wire.endTransmission();

          return data_read;

}

void MMA7660::init()

{

          setMode(MMA7660_STAND_BY);

          setSampleRate(AUTO_SLEEP_32);

          setMode(MMA7660_ACTIVE);

}

void MMA7660::setMode(uint8_t mode)

{

          write(MMA7660_MODE,mode);

}

void MMA7660::setSampleRate(uint8_t rate)

{

          write(MMA7660_SR,rate);

}

/*Function: Get the contents of the registers in the MMA7660*/

/*          so as to calculate the acceleration.            */

void MMA7660::getXYZ(int8_t *x,int8_t *y,int8_t *z)

{

          unsigned char val[3];

          int count = 0;

            val[0] = val[1] = val[2] = 64;

          while(Wire.available() > 0)

                    Wire.read();

          Wire.requestFrom(MMA7660_ADDR,3);

          while(Wire.available()) 

            {

              if(count < 3)

              {

                          while ( val[count] > 63 )  // reload the damn thing it is bad

                  {

                    val[count] = Wire.read();

                  }

              }

        count++;

            }

          *x = ((char)(val[0]<<2))/4;

            *y = ((char)(val[1]<<2))/4;

            *z = ((char)(val[2]<<2))/4;

}

void MMA7660::getAcceleration(float *ax,float *ay,float *az)

{

          int8_t x,y,z;

          getXYZ(&x,&y,&z);

          *ax = x/21.00;

          *ay = y/21.00;

          *az = z/21.00;

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

library code  MMA7660.h

#ifndef __MMC7660_H__

#define __MMC7660_H__

#define MMA7660_ADDR  0x4c

#define MMA7660_X     0x00

#define MMA7660_Y     0x01

#define MMA7660_Z     0x02

#define MMA7660_TILT  0x03

#define MMA7660_SRST  0x04

#define MMA7660_SPCNT 0x05

#define MMA7660_INTSU 0x06

#define MMA7660_MODE  0x07

          #define MMA7660_STAND_BY 0x00

          #define MMA7660_ACTIVE           0x01

#define MMA7660_SR    0x08         //sample rate register

          #define AUTO_SLEEP_120          0X00  //120 sample per second

          #define AUTO_SLEEP_64          0X01

          #define AUTO_SLEEP_32          0X02

          #define AUTO_SLEEP_16          0X03

          #define AUTO_SLEEP_8          0X04

          #define AUTO_SLEEP_4          0X05

          #define AUTO_SLEEP_2          0X06

          #define AUTO_SLEEP_1          0X07

#define MMA7660_PDET  0x09

#define MMA7660_PD    0x0A

class MMA7660

{

private:

          void write(uint8_t _register, uint8_t _data);

          uint8_t read(uint8_t _register);

public:

          void init();

          void setMode(uint8_t mode);

          void setSampleRate(uint8_t rate);

          void getXYZ(int8_t *x,int8_t *y,int8_t *z);

          void getAcceleration(float *ax,float *ay,float *az);

};

#endif

0 Kudos
Message 6 of 9
(5,323 Views)

I was working on doing this for you but my desktop fatally crashed last night so I will have to start over.  FYI.

0 Kudos
Message 7 of 9
(5,323 Views)

Ok, I've redone the small library.  It is purely based on the library that you linked to.  Let me know if you experience any issues.

Message 8 of 9
(5,323 Views)

Brilliant, thanks for your help, Nathan.

I'll get working on it and give you feedback as soon as possible.

0 Kudos
Message 9 of 9
(5,323 Views)