Maker Pro
Maker Pro

High school project - Using LIS331 to monitor tremors

Hello,
My name is Tom, I am doing a project (high school- final project) that includes using an Arduino and some sensors - One of them is an Accelerometer. The project is about Parkinson's disease - I want to detect and monitor tremors with the Accelerometer....

I bought two products (both SparkFun) - LIS331 & MMA8452Q.
The LIS331 is working fine with a code that I found (which ill add).
The MMA8452Q isn't working :( - I hooked it up and found some codes but it never showed any values.

So I have several requests and questions :p

1. I used the following code for the LIS331:

Code:
#include <LIS331.h>
#include <Wire.h>

LIS331 lis;
int val;

void setup() {
  Serial.begin(9600);
  lis.begin();
}
void loop() {
  val = lis.getXValue();
  Serial.print(val);
  Serial.print("\t");
  val = lis.getYValue();
  Serial.print(val);
  Serial.print("\t");
  val = lis.getZValue();
  Serial.print(val);
  Serial.println();
}


rw0t9y.jpg


I understand how the code works but I honestly have no ideas what the values/output represents....
I read the Datasheet (https://www.sparkfun.com/datasheets/Sensors/Accelerometer/LIS331HH.pdf), section 2.5.1 about sensitivity - I tried to understand what the values represent but I just didn't understand it . what is "Gain"?

okay so I tried measuring the "sensitivity" (I still have no idea what it means). I pointed the Z axis straight down:

It shows -6000 (approximately) when I point the Z axis straight down......

This is the axis indicator:

2uqm54o.jpg


This is how I pointed it:

2rz48kl.jpg


*the picture is rotated but the Z axis points downwords

so it means that 6000 = 1g?
It doesn't sound right.....

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


2. I tried hooking up the MMA4852Q with the hooking up guide of sprakfun -

https://learn.sparkfun.com/tutorial...up-guide?_ga=1.26243133.1813833853.1450790034

Code:
/******************************************************************************
MMA8452Q_Basic.ino
SFE_MMA8452Q Library Basic Example Sketch
Jim Lindblom @ SparkFun Electronics
Original Creation Date: June 3, 2014
https://github.com/sparkfun/MMA8452_Accelerometer

This sketch uses the SFE_MMA8452Q library to initialize the
accelerometer, and stream values from it.

Hardware hookup:
  Arduino --------------- MMA8452Q Breakout
    3.3V  ---------------     3.3V
    GND   ---------------     GND
  SDA (A4) --\/330 Ohm\/--    SDA
  SCL (A5) --\/330 Ohm\/--    SCL

The MMA8452Q is a 3.3V max sensor, so you'll need to do some
level-shifting between the Arduino and the breakout. Series
resistors on the SDA and SCL lines should do the trick.

Development environment specifics:
    IDE: Arduino 1.0.5
    Hardware Platform: Arduino Uno

This code is beerware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!

Distributed as-is; no warranty is given.
******************************************************************************/
#include <Wire.h> // Must include Wire library for I2C
#include <SFE_MMA8452Q.h> // Includes the SFE_MMA8452Q library

// Begin using the library by creating an instance of the MMA8452Q
//  class. We'll call it "accel". That's what we'll reference from
//  here on out.
MMA8452Q accel;

// The setup function simply starts serial and initializes the
//  accelerometer.
void setup()
{
  Serial.begin(9600);
  Serial.println("MMA8452Q Test Code!");
  // Choose your adventure! There are a few options when it comes
  // to initializing the MMA8452Q:
  //  1. Default init. This will set the accelerometer up
  //     with a full-scale range of +/-2g, and an output data rate
  //     of 800 Hz (fastest).
  accel.init();
  //  2. Initialize with FULL-SCALE setting. You can set the scale
  //     using either SCALE_2G, SCALE_4G, or SCALE_8G as the value.
  //     That'll set the scale to +/-2g, 4g, or 8g respectively.
  //accel.init(SCALE_4G); // Uncomment this out if you'd like
  //  3. Initialize with FULL-SCALE and DATA RATE setting. If you
  //     want control over how fast your accelerometer produces
  //     data use one of the following options in the second param:
  //     ODR_800, ODR_400, ODR_200, ODR_100, ODR_50, ODR_12,
  //     ODR_6, or ODR_1.
  //     Sets to 800, 400, 200, 100, 50, 12.5, 6.25, or 1.56 Hz.
  //accel.init(SCALE_8G, ODR_6);
}

// The loop function will simply check for new data from the
//  accelerometer and print it out if it's available.
void loop()
{
  // Use the accel.available() function to wait for new data
  //  from the accelerometer.
  if (accel.available())
  {
    // First, use accel.read() to read the new variables:
    accel.read();
   
    // accel.read() will update two sets of variables.
    // * int's x, y, and z will store the signed 12-bit values
    //   read out of the accelerometer.
    // * floats cx, cy, and cz will store the calculated
    //   acceleration from those 12-bit values. These variables
    //   are in units of g's.
    // Check the two function declarations below for an example
    // of how to use these variables.
    printCalculatedAccels();
    //printAccels(); // Uncomment to print digital readings
   
    // The library also supports the portrait/landscape detection
    //  of the MMA8452Q. Check out this function declaration for
    //  an example of how to use that.
    printOrientation();
   
    Serial.println(); // Print new line every time.
  }
}

// The function demonstrates how to use the accel.x, accel.y and
//  accel.z variables.
// Before using these variables you must call the accel.read()
//  function!
void printAccels()
{
  Serial.print(accel.x, 3);
  Serial.print("\t");
  Serial.print(accel.y, 3);
  Serial.print("\t");
  Serial.print(accel.z, 3);
  Serial.print("\t");
}

// This function demonstrates how to use the accel.cx, accel.cy,
//  and accel.cz variables.
// Before using these variables you must call the accel.read()
//  function!
void printCalculatedAccels()
{
  Serial.print(accel.cx, 3);
  Serial.print("\t");
  Serial.print(accel.cy, 3);
  Serial.print("\t");
  Serial.print(accel.cz, 3);
  Serial.print("\t");
}

// This function demonstrates how to use the accel.readPL()
// function, which reads the portrait/landscape status of the
// sensor.
void printOrientation()
{
  // accel.readPL() will return a byte containing information
  // about the orientation of the sensor. It will be either
  // PORTRAIT_U, PORTRAIT_D, LANDSCAPE_R, LANDSCAPE_L, or
  // LOCKOUT.
  byte pl = accel.readPL();
  switch (pl)
  {
  case PORTRAIT_U:
    Serial.print("Portrait Up");
    break;
  case PORTRAIT_D:
    Serial.print("Portrait Down");
    break;
  case LANDSCAPE_R:
    Serial.print("Landscape Right");
    break;
  case LANDSCAPE_L:
    Serial.print("Landscape Left");
    break;
  case LOCKOUT:
    Serial.print("Flat");
    break;
  }
}

And it just showed nothing :

1z97hh.png


This is how I hooked it up:

11kxgdu.jpg


hurozl.jpg


*If you are wondering - I used two pairs of resistors (220 & 100 Ω each) because I didn't have 330 Ω resistors.

Am I doing something wrong? because I am pretty hopeless......

My post might be too long...I'm sorry :oops:
and if something is wrong with my post (not according to the forum rules or something) - please say and ill change it!

Thanks in advance for everyone,
Tom
 

davenn

Moderator
hi there
welcome to EP :)

okay so I tried measuring the "sensitivity" (I still have no idea what it means). I pointed the Z axis straight down:
It shows -6000 (approximately) when I point the Z axis straight down......

OK you need to understand the use of the accelerometer, as per the datasheet ......

Clipboard01.jpg

any deviation from this will result in oddball results .... this is correct orientation of the chip
ie., you cannot turn it upside down and expect correct output results



I tried to understand what the values represent but I just didn't understand it . what is "Gain"?

in what context ? I skimmed the datasheet and didn't see anything specific



Dave
 
First of all thank you for helping me :)

any deviation from this will result in oddball results .... this is correct orientation of the chip
ie., you cannot turn it upside down and expect correct output results

deviation from what? I thought that the sensor should be able to produce outputs that matches every positioning (360 degrees for every axis).........
Oh and about the picture - I thought that It should detect the values of the acceleration in every position :eek:

in what context ? I skimmed the datasheet and didn't see anything specific

I read the part about sensitivity because someone said that this is how ill understand the meaning of the output values, and I didn't :(
So I asked here......

It says there :
Sensitivity describes the gain of the sensor and can be determined e.g. by applying 1 g acceleration to it. As the sensor can measure DC accelerations this can be done easily by pointing the axis of interest towards the center of the earth, noting the output value, rotating the sensor by 180 degrees (pointing to the sky) and noting the output value again. By doing so, ±1 g acceleration is applied to the sensor. Subtracting the larger output value from the smaller one, and dividing the result by 2, leads to the actual sensitivity of the sensor. This value changes very little over temperature and also time. The sensitivity tolerance describes the range of Sensitivities of a large population of sensors.

I don't understand what "gain" means here..... and moreover, they said I should note the values when the sensor is pointing towards the earth and the opposite (rotating by 180 degrees) and then the difference of the two values divided by 2 should be the "sensitivity" (which I still don't understand what it represents), But the fact is that I get '6000' and '-6000' and I have no idea how to move forward from there.........

Tom
 
With the device level and the top of the device pointing up. only the Z axis will be responsive and give you 1g. If you turn it upside down you get -1g. The x and Y axis are not responsive so will output 0g. Nothings perfect so there is always some offsetting that needs to be done, normally in software.
Adam
 
With the device level and the top of the device pointing up. only the Z axis will be responsive and give you 1g. If you turn it upside down you get -1g. The x and Y axis are not responsive so will output 0g. Nothings perfect so there is always some offsetting that needs to be done, normally in software.
Adam

I get it - the values won't be accurate, but How can I measure the sensitivity? I mean, the values seem a bit high for 1g - 6000? I read that normal sensitivity is about 430 mV/g (I still don't understand what it represents). Furthermore, I'm not sure what the code that I use is doing - the values of an axis, for example, the Z axis - What do they represent? the voltage (mV) that the sensor is transmiting to the Arduino?
Tom
 
Sorry Tom,
I have no idea about coding. I just thought it explained a little about sensitivity and gain.
But gain can be thought of like an amplifier. If the signal is very weak and you add gain, you might have more chance of measuring it.

Martin
 
Sorry Tom,
I have no idea about coding. I just thought it explained a little about sensitivity and gain.
But gain can be thought of like an amplifier. If the signal is very weak and you add gain, you might have more chance of measuring it.

Martin

Oh well thanks anyway :)
I am not strong with electronics so ill try my best to understand these terms by reading what you posted!
 
How do "mythbusters" throw "Buster" from a crane without deviation? The poor crash dummy falls in every way possible.
And breaks up in every way possible...
I want to know a little about this too..:)

Martin
 
Hi Honey Bun,
I mean, the mythbusters put accelerometers into 'Buster', their crash test dummy...
They drop it from anything! and can read everything!. Time, speed, G force etc without it pointing either way...I mean it falls head over heels, left and right but they get the details..

Martin
 

davenn

Moderator
Hi Honey Bun,
I mean, the mythbusters put accelerometers into 'Buster', their crash test dummy...
They drop it from anything! and can read everything!. Time, speed, G force etc without it pointing either way...I mean it falls head over heels, left and right but they get the details..

Martin

the force is only being measured at the time of impact
Also, there are a number of different types of accelerometers
the ones like that shown above are generally designed to be used in a level right side up orientation within a small variation

cant find anything specific in the datasheet one way or another for that particular device :)
 
Top