I wrote and uploaded my code to the Arduino and accelerometer using the [http://arduino.cc/hu/Main/Software Arduino 1.0 IDE] on Ubuntu 11.04. Help for getting the integrated development environment running on Ubuntu can be found [http://arduino.cc/playground/Linux/Ubuntu here]. The language is very similar to C.

I wrote and uploaded my code to the Arduino and accelerometer using the [http://arduino.cc/hu/Main/Software Arduino 1.0 IDE] on Ubuntu 11.04. Help for getting the integrated development environment running on Ubuntu can be found [http://arduino.cc/playground/Linux/Ubuntu here]. The language is very similar to C.

−

====ADXL345 and Arduino 1.0 IDE====

+

==== ====

+

To write code for the ADXL in Arduino 1.0, one needs to have a library containing a .cpp and a .h file. The library is inserted into the libraries folder in the Arduino 1.0 directory. Essentially, a library contains subroutines one may find useful in writing their code and helps a programmer interface with a device, without having to worry about all the details.

+

I used an [http://code.google.com/p/adxl345driver/downloads/list ADXL 345 library] that I found on a bildr tutorial.

+

====Code====

+

<source lang ="c">

+

//Arduino 1.0+ Only!

+

//Arduino 1.0+ Only!

+

+

#include <Wire.h>

+

#include <ADXL345.h>

+

+

ADXL345 adxl; //variable adxl is an instance of the ADXL345 library

+

int x,y,z;

+

float Gx, Gy, Gz;

+

int count=0;

+

+

void setup(){

+

Serial.begin(9600);

+

adxl.powerOn();

+

adxl.setRangeSetting(2); //G sensing range from -2g to +2g

+

+

//set activity/ inactivity thresholds (0-255)

+

adxl.setActivityThreshold(75); //62.5mg per increment

+

adxl.setInactivityThreshold(75); //62.5mg per increment

+

adxl.setTimeInactivity(6); // how many seconds of no activity is inactive?

Circuit

I connected the ADXL to the Arduino using a relatively simple circuit. I used the circuit setup from a bildr tutorial. The accelerometer came mounted on a breakout board, with holes where pins could go. I had to solder pins onto the breakout board

Arduino 3.3 v is connected to ADXL VCC and CS

Arduino ground is connected to ADXL ground

Arduino Analog In 4 (A4) is connected to ADXL SDA

Arduino Analog In 5 (A5) is connected to ADXL SCL

Development Environment

I wrote and uploaded my code to the Arduino and accelerometer using the Arduino 1.0 IDE on Ubuntu 11.04. Help for getting the integrated development environment running on Ubuntu can be found here. The language is very similar to C.

To write code for the ADXL in Arduino 1.0, one needs to have a library containing a .cpp and a .h file. The library is inserted into the libraries folder in the Arduino 1.0 directory. Essentially, a library contains subroutines one may find useful in writing their code and helps a programmer interface with a device, without having to worry about all the details.

//To see current register values of ADXL345
//printAllRegister();
Scale();
Output();
//getInterruptSource clears all triggered actions after returning value
//so do not call again until you need to recheck for triggered actions
byte interrupts = adxl.getInterruptSource();