View Single Post
  #8   Spotlight this post!  
Unread 01-16-2011, 09:05 PM
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: ADXL345_I2C Help

Quote:
Originally Posted by ProgrammerMike7 View Post
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?
I'm not quite sure what to tell you. I tried both the program above and a program I had laying around, and both worked just fine. It makes me tend to think that you either really do have a wiring/hardware issue or perhaps you have some software that is not updated.

Here's the other application I tried which also works on my system:

Code:
#include "WPILib.h"

class TestADXL345_I2C : public SimpleRobot
{
	ADXL345_I2C acc;

public:
	TestADXL345_I2C(void)
		: acc (4, ADXL345_I2C::kRange_2G)
	{
	}

	void RobotMain(void)
	{
		while (true)
		{
			printf("x=%f  y=%f  z=%f\n",
				acc.GetAcceleration(ADXL345_I2C::kAxis_X),
				acc.GetAcceleration(ADXL345_I2C::kAxis_Y),
				acc.GetAcceleration(ADXL345_I2C::kAxis_Z));
			Wait(1.0);
		}
	}
};

START_ROBOT_CLASS(TestADXL345_I2C);
Reply With Quote