Our team is having the same problem. We have the Accelerometer wired up correctly to the I2C slot, and the Digital Module is in cRIO slot 2. The ode should be working but we still get all 0's. I'll post our code below, maybe that may be the issue.
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.ADXL345_I2C;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Victor;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class RobotTemplate extends IterativeRobot {
Victor leftVict, rightVict;
Joystick leftJoy, rightJoy;
Driver robot;
ADXL345_I2C Accelerometer;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
System.out.println("Call init method");
Accelerometer = new ADXL345_I2C(1,ADXL345_I2C.DataFormat_Range.k2G);
// leftVict = new Victor(1);
// rightVict = new Victor(2);
//
// leftJoy = new Joystick(1);
// rightJoy = new Joystick(2);
//
// robot = new Driver(leftJoy, rightJoy, leftVict, rightVict);
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
// robot.drive();
//vict.set(leftJoy.getAxis(Joystick.AxisType.kY));
//jag.set(leftJoy.getAxis(Joystick.AxisType.kY));
System.out.println("Acceleration = " + Accelerometer.getAcceleration(ADXL345_I2C.Axes.kX));
}
}
}