Acceleration Data from Arduino Uno

Hello,

I currently have an LIS3DH accelerometer chip soldered to an evaluation board and the evaluation board is connected to an Arduino Uno. Here’s the code I used to get acceleration data:

#include <Wire.h> //I2C Arduino Library 


#define address 0x19 //I2C 7bit address 


void setup(){ 
  //Initialize Serial and I2C communications 
  Serial.begin(9600); 
  Wire.begin(); 
   
  //Put into the correct operating mode 
  Wire.beginTransmission(address); //open communication with 
  Wire.write(0x20);  
  Wire.write(0x27);  
  Wire.endTransmission(); 
}     


void loop(){ 
   
  int x,y,z,a,b,c; //triple axis data 


  Wire.beginTransmission(address); 
  Wire.write(0xA8); 
  Wire.endTransmission(); 
//Read data from each axis 
  Wire.requestFrom(address, 6); 
  if(6<=Wire.available()){ 
     x = (int)Wire.read();  
    x |= (int)Wire.read()<<8;  
    y = (int)Wire.read();         // Note change in operator on this and next three statements
    y |= (int)Wire.read()<<8;     
    z = (int)Wire.read(); 
    z |= (int)Wire.read()<<8;
  } 
   
  //Print out values of each axis 
  Serial.print(" "); 
  Serial.print(x); 
  Serial.print(" "); 
  Serial.print(y); 
  Serial.print(" "); 
  Serial.println(z); 

  delay(450);
}

Everything works great, but I was wondering if anyone knew how to introduce an offset into the x, y, and z axes. Also, is there a way I can graph the data directly from the Arduino sketch? I’m looking to get 3 graphs, one for each axis, but I have no clue how to do it, any help would be greatly appreciated.

For an offset, can't you just use basic arithmetic to add or subtract some value from the x,y,z values returned?

As for graphing it... what do you want to graph to show up on? I assume you want it on an LCD or something? That's very do-able - I'd recommend a black and white LCD, not color.

Thanks for responding. I don't know why I didn't think to just use basic arithmetic for offset, good call on that.

All I'm looking to do for the graphs is simply graph the acceleration data output, I'll probably convert it into g's and then graph it, but do you know the code for something like that? I just want to send the data into my laptop and graph it there, I tried using LabVIEW but it ended up being a real pain to get everything working. I'm just looking for a basic graph, nothing too fancy.

For something quick and dirty, you could Serial.print() the axis information in CSV format, open in excel and graph from there. Not the most sophisticated way, but it gets you a graph without any additional hardware.

Though I'm guessing it defeats the purpose having a uno flung about collecting g force data while connected to a PC haha, so maybe log to an SD card?

For graphing have a look at my EzScrn demo - which shows the graphs in a browser.

You may also be interested in this RemoteXY project which links an Arduino to an Android phone.

...R

tammytam:
For something quick and dirty, you could Serial.print() the axis information in CSV format, open in excel and graph from there. Not the most sophisticated way, but it gets you a graph without any additional hardware.

Though I’m guessing it defeats the purpose having a uno flung about collecting g force data while connected to a PC haha, so maybe log to an SD card?

That’s a great idea, I found a very simple way to send the data into Matlab so I’m going to try that first. I need to digitally filter the data anyway and it will be much easier it Matlab. But, if it doesn’t end up working well I’ll definitely try the excel method. Thanks for taking the time to respond, have a wonderful day.