View Single Post
  #14   Spotlight this post!  
Unread 01-26-2011, 06:12 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
Re: ADXL345_I2C Help

We had last years ADXL345, so we wired that up and it works fine. However, we encounter another problem when having the HiTechnic Compass plugged into the NXT I2C port at the same time the accelerometer is plugged into the spare I2C port. They both work and display values when they are plugged in alone, however when they are both plugged in together, neither will update values and display 0.000000. We do not get any errors, they simply do not work. We also checked the compass and accelerometer source code to make sure that the compass and accelerometer had different addresses which they do (Accelerometer is 0x3A, and compass is 0x02). Here is the code with the Compass added.

Code:
#include "WPILib.h"

class MyRobot : public IterativeRobot {
	
	HiTechnicCompass myCompass;
	ADXL345_I2C myAccel;
	DriverStationLCD *driverStation;

	double xAccel, yAccel;
        double compassAngle;

public:
	MyRobot():
		myCompass(4),
		myAccel(4, ADXL345_I2C::kRange_2G)
	{
		driverStation = DriverStationLCD::GetInstance();

	}

	void TeleopInit() {
		GetWatchdog().SetEnabled(true);
		GetWatchdog().SetExpiration(0.5);
		driverStation->Clear();	
	}

	void TeleopPeriodic() {
		
		while(IsOperatorControl() && IsEnabled()) {
			GetWatchdog().Feed();
			
			char xAccelChar[100];
			char yAccelChar[100];
			char compassChar[100];
			char testChar[100];
			
			xAccel =  myAccel.GetAcceleration(ADXL345_I2C::kAxis_X);
			yAccel =  myAccel.GetAcceleration(ADXL345_I2C::kAxis_Y);
			
			compassAngle = myCompass.GetAngle();
			
			sprintf(xAccelChar, "Accel X: %f", xAccel);
			sprintf(yAccelChar, "Accel Y: %f", yAccel);
			sprintf(compassChar, "Compass: %f", compassAngle);
			
			driverStation->Clear();
			driverStation->PrintfLine(DriverStationLCD::kUser_Line1, xAccelChar);
			driverStation->PrintfLine(DriverStationLCD::kUser_Line2, yAccelChar);
			driverStation->PrintfLine(DriverStationLCD::kUser_Line3, compassChar);
			driverStation->UpdateLCD();
		}
	}
};
START_ROBOT_CLASS(MyRobot);
We would appreciate any advice that could fix this issue.
__________________
Wait (-1)
Reply With Quote