Accelerometer Showing All Zeros

I’m trying to get the accelerometer to work using Java, but I’m having some trouble. I’m wiring it with I2C and using the “ADXL345_I2C” class. When I try to print out the x, y, and z values using “getAcceleration()”, it just prints out zeros for everything.

I’ve gone over the wiring a bunch of times and it all looks correct to me. We also checked to voltage on the pins and it seems to change when we shake the accelerometer, so I don’t think it’s broken. Our java and crio are both up to date (as of today). I’ve never used I2C before, so there might be something obvious I’m missing. Any help would be appreciated.

We seem to be having the same problem. We will continue to research it, if we resolve it we will report back.

Did you wire it correctly? We had the saem problem with our gyro, but it turned out it the pwm was not supposed to be in the digi-sidecar.

Good luck!

You have the wires going to the special pins on the digital sidecar? There are two sets of four, and you want the set closer to the edge.

I know it doesn’t add much, but our team had this same problem last year. We followed the diagram as best we could, and even asked on CD. I guess we can look forward to having the same problem this year, too :slight_smile:

Are you using the flat ribbon db37 cable included in this years KoP, or the previous round one?

As promised, we resolved it by following ggorsuch’s recommendation. Apparently the older round cable doesn’t work for this purpose. Also, be sure to follow the directions here to make sure your flat cable is “built” correctly. Again, thanks ggorsuch for your help on this issue.

It is weird that it doesn’t work with the old cable. We had the same problem. It has worked in previous years. It must have to do with the different slot the dio module goes in.

we were following that a week ago and we broke our cable… so do we really need to order another one?

The sensor manual says

Note: The ADXL345 starts in a power saving mode. You must turn it on by writing 0x08 to POWER_CTL
(0x2D) before it will do anything interesting.

so how would someone go about doing this?

I’m just going off the javadocs, as I’ve never used accelerometers.
But the “write” method of the I2C class seems useful.

Does the built-in ADXL345_I2C class do this automatically when the constructor is called, or do we have to do something else, like use the I2C class?

It does it for you; take a peak at the ADXL345_I2C source code and you can see it right there.

m_i2c.write(kPowerCtlRegister, kPowerCtl_Measure);

this is what we are using for the code:

ADXL345_I2C acll= new ADXL345_I2C(2,ADXL345_I2C.DataFormat_Range.k8G);
public void teleopPeriodic()
		hi1 = acll.getAcceleration(ADXL345_I2C.Axes.kX);
		hi2 = acll.getAcceleration(ADXL345_I2C.Axes.kY);
		hi3 = acll.getAcceleration(ADXL345_I2C.Axes.kZ);
                disp(1, "" + hi1 + "                        ");
		disp(2, "" + hi2 + "                        ");
		disp(3, "" + hi3 + "                        ");

disp is a custom method we made to output to the DS LCD
but this gives us just all 0

We also have the accelerometers plugged into the the 2 sets of 4 pins next to the “phone jack”.

We also have the accelerometers plugged into the the 2 sets of 4 pins next to the “phone jack”.

You are using more than one accelerometer?

no just one, we tried both sets of 4 pins and both showed 0.

Which physical slot of the cRio is the DIO module in.
By looking at your code it is in either slot 6 of 8 slot cRIO, or slot 4 of 4 slot cRIO.

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.

/* 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() {
        System.out.println("Acceleration = " + Accelerometer.getAcceleration(ADXL345_I2C.Axes.kX));

Sorry I didn’t respond before, I forgot to check this thread. We’re still having problems. The cable we got in the kit was broken, and we tried to fix it but ended up breaking it more. We have a different ribbon cable that was bought last year, but that doesn’t seem to fix the issue.

Actually, sorry, we got it to work. I replaced the round cable with a ribbon cable and moved the pwm’s to the outside set of I2C ports. I think moving it to the outside is what actually fixed it, but I did both. Thanks everyone for your help!