View Single Post
  #1   Spotlight this post!  
Unread 01-13-2011, 08:36 PM
ProgrammerMike7 ProgrammerMike7 is offline
Registered User
AKA: Mike
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Canada
Posts: 13
ProgrammerMike7 will become famous soon enoughProgrammerMike7 will become famous soon enough
ADXL345_I2C Help

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?
__________________
Wait (-1)
Reply With Quote