Hi,
I have an an ADXL345 which is connected to my Arduino Leonardo (it's not the version from Sparkfun, so the wiring is a little bit different):
I am not sure whether I have soldered it correctly, since it only returns the values 0, 0, 0 with this code:
/**
* @file readADXL345.ino
* @author Nico
* @date 29-10-2013
* @version 1.0
* @mainPage
* Simple sketch for reading the ADXL345 interface board and displaying raw data on the Serial output
*/
/**
* SVN version control. do not remove
* $Revision$
* $Date$
* $Author$
*/
#ifdef __IN_ECLIPSE__
#include "readADXL345.h"
#endif
#include <ADXL345.h>
#include <Wire.h>
//
// pin definitions
//
#define CS 10 // chip select for SD card
#define ADXL345_WORKS 13 // led on indicates ADXL exists
//
// other definitions
//
#define DELAY_PER_MEASUREMENT 1000L // one measurement per second
//
// card definitions
//
// ADXL345 Card
// pin 1 = GND Connect to GND row
// pin 2 = VCC Connect to 5V
// pin 3 = CS Not Connected
// pin 4 = INT1 Not Connected
// pin 5 = INT2 Not Connected
// pin 6 = SDO Not Connected
// pin 7 = SDA Connect to A4
// pin 8 = SCK Connect to A5
//
// ADXL345 accelerometer
//
ADXL345 accel(0x53); // accelerometer instance
AccelerometerRaw rawData; // structure with the raw (=int) data from ADXL345
//
// global variables
//
/**
* @name readADXL345()
* @return uint8_t value of the sensor
* Reads the sensor returns the value where Bit 0 = Z, Bit 1 = Y, Bit2 = X
* The value represents the plan that is lying down. This is determined by
* reading the raw sensor data and determining which value is largest. If negative it is 0
* else it is a 1
*/
void readADXL345(){
//
// read the raw dat from the accelerometer
//
rawData = accel.ReadRawAxis();
}
/**
* @name setup()
* initializes the sketch once by power on or Reset
*/
void setup()
{
//
// define IO pins if required
//
pinMode(CS, OUTPUT); // SD card select
pinMode(ADXL345_WORKS, OUTPUT); // If lit, ADXL345 is connected
//
// Check that the accelerometer is in fact connected.
//
if(accel.EnsureConnected()){
digitalWrite(ADXL345_WORKS, HIGH); // If we are connected, light our status LED.
} else {
digitalWrite(ADXL345_WORKS, LOW); // If we are not connected, turn our LED off.
}
//
// Set the range of the accelerometer to a maximum of 2G.
//
accel.SetRange(2, true);
//
// Tell the accelerometer to start taking measurements.
//
accel.EnableMeasurements();
//
// open Serial
//
Serial.begin(9600);
//Turning on the ADXL345
digitalWrite(ADXL345, 0x2D, 0);
digitalWrite(ADXL345, 0x2D, 16);
digitalWrite(ADXL345, 0x2D, 8);
}
/**
* @name loop()
* loop functions is called continuously
*/
void loop()
{
//
// read the data
//
readADXL345(); // read the raw data from the ADXL345
//
// display the data on the Serial
//
Serial.print(rawData.XAxis);
Serial.print(" | ");
Serial.print(rawData.YAxis);
Serial.print(" | ");
Serial.println(rawData.ZAxis);
//
// delay some time
//
delay(DELAY_PER_MEASUREMENT);
}
That's why I ran the I2C scanner sketch, which states that there are no devices found. Does this mean that there is something wrong with my wiring/soldering? Or does the problem lie in my code?