Hello everyone! I have been trying to get the ADXL345 accelerometer working. I have it connected to the I2C spare outputs. Here is my code:
Code:
#include "WPILib.h"
class MyRobot : public IterativeRobot {
ADXL345_I2C myAccel;
DriverStationLCD *driverStation;
public:
MyRobot():
myAccel(4, ADXL345_I2C::kRange_2G)
{
driverStation = DriverStationLCD::GetInstance();
}
void TeleopInit() {
GetWatchdog().SetEnabled(true);
driverStation->Clear();
}
void TeleopPeriodic() {
GetWatchdog().Feed();
char xAccelChar[100];
char yAccelChar[100];
sprintf(xAccelChar, "Accel X: %f", myAccel.GetAcceleration(ADXL345_I2C::kAxis_X));
sprintf(yAccelChar, "Accel Y: %f", myAccel.GetAcceleration(ADXL345_I2C::kAxis_Y));
driverStation->Clear();
driverStation->PrintfLine(DriverStationLCD::kUser_Line1, xAccelChar);
driverStation->PrintfLine(DriverStationLCD::kUser_Line2, yAccelChar);
driverStation->UpdateLCD();
}
};
START_ROBOT_CLASS(MyRobot);
When I run this program, the display on the driver station reads:
Accel X: 0.00000
Accel Y: 0.00000
No matter how much the accelerometer is moved around, these values do not change. Does anyone have any ideas as to what I can do to make the accelerometer work?