Hello all, I'm trying to find a simple way to get the x, y, and z data off of this accelerometer, I have tried a couple examples but for some reason they didn't work, so I need a lightweight way to be able to get them, ideally as variables. I also need to use the SPI method, as I2C won't be available for my use.
However, when I try and check/upload the code, I get these errors:
C:\Users\XOIIO\Desktop\arduino-1.0.5\libraries\ADXL345\ADXL345.cpp: In member function 'void ADXL345::Write(int, int)':
C:\Users\XOIIO\Desktop\arduino-1.0.5\libraries\ADXL345\ADXL345.cpp:137: error: 'class TwoWire' has no member named 'send'
C:\Users\XOIIO\Desktop\arduino-1.0.5\libraries\ADXL345\ADXL345.cpp:138: error: 'class TwoWire' has no member named 'send'
C:\Users\XOIIO\Desktop\arduino-1.0.5\libraries\ADXL345\ADXL345.cpp: In member function 'uint8_t* ADXL345::Read(int, int)':
C:\Users\XOIIO\Desktop\arduino-1.0.5\libraries\ADXL345\ADXL345.cpp:145: error: 'class TwoWire' has no member named 'send'
C:\Users\XOIIO\Desktop\arduino-1.0.5\libraries\ADXL345\ADXL345.cpp:156: error: 'class TwoWire' has no member named 'receive'
I'm not sure what they mean but I'll try googling around, although I really have no clue :~
// Include the Wire library so we can start using I2C.
#include <Wire.h>
// Include the Love Electronics ADXL345 library so we can use the accelerometer.
#include <ADXL345.h>
// Declare a global instance of the accelerometer.
ADXL345 accel;
// Set up a pin we are going to use to indicate our status using an LED.
int statusPin = 2; // I'm using digital pin 2.
void setup()
{
// Begin by setting up the Serial Port so we can output our results.
Serial.begin(9600);
// Start the I2C Wire library so we can use I2C to talk to the accelerometer.
Wire.begin();
// Ready an LED to indicate our status.
pinMode(statusPin, OUTPUT);
// Create an instance of the accelerometer on the default address (0x1D)
accel = ADXL345();
// Check that the accelerometer is infact connected.
if(accel.EnsureConnected())
{
Serial.println("Connected to ADXL345.");
digitalWrite(statusPin, HIGH); // If we are connected, light our status LED.
}
else
{
Serial.println("Could not connect to ADXL345.");
digitalWrite(statusPin, 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();
}
void loop()
{
if(accel.IsConnected) // If we are connected to the accelerometer.
{
// Read the raw data from the accelerometer.
AccelerometerRaw raw = accel.ReadRawAxis();
//This data can be accessed like so:
int xAxisRawData = raw.XAxis;
// Read the *scaled* data from the accelerometer (this does it's own read from the accelerometer
// so you don't have to ReadRawAxis before you use this method).
// This useful method gives you the value in G thanks to the Love Electronics library.
AccelerometerScaled scaled = accel.ReadScaledAxis();
// This data can be accessed like so:
float xAxisGs = scaled.XAxis;
// We output our received data.
Output(raw, scaled);
}
}
// Output the data down the serial port.
void Output(AccelerometerRaw raw, AccelerometerScaled scaled)
{
// Tell us about the raw values coming from the accelerometer.
Serial.print("Raw:\t");
Serial.print(raw.XAxis);
Serial.print(" ");
Serial.print(raw.YAxis);
Serial.print(" ");
Serial.print(raw.ZAxis);
// Tell us about the this data, but scale it into useful units (G).
Serial.print(" \tScaled:\t");
Serial.print(scaled.XAxis);
Serial.print("G ");
Serial.print(scaled.YAxis);
Serial.print("G ");
Serial.print(scaled.ZAxis);
Serial.println("G");
}