Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   ADXL345_I2C Help (http://www.chiefdelphi.com/forums/showthread.php?t=89065)

ProgrammerMike7 01-13-2011 08:36 PM

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?

jhersh 01-14-2011 02:35 AM

Re: ADXL345_I2C Help
 
Are you getting any errors on the diagnostics tab of the driver station or on the Console?

Are you sure of your wiring? Make sure clk and data are not swapped.

basicxman 01-14-2011 05:52 PM

Re: ADXL345_I2C Help
 
Quote:

Originally Posted by jhersh (Post 999731)
Are you getting any errors on the diagnostics tab
of the driver station or on the Console?

Nothing; although the I2C class has many assertions, none seem to be failing (or at least communicating a failure). The ADXL345_I2C class has no assertions besides the ones from I2C calls.

Quote:

Originally Posted by jhersh (Post 999731)
Are you sure of your wiring? Make sure clk and data are not swapped.

Quite positive, the board and the I2C spare outputs on the digital sidecar are labelled. An accelerometer example VI also depicts a wiring diagram.

gvarndell 01-15-2011 11:35 AM

Re: ADXL345_I2C Help
 
Quote:

Originally Posted by ProgrammerMike7 (Post 999486)
Hello everyone! I have been trying to get the ADXL345 accelerometer working. I have it connected to the I2C spare outputs.

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 would start by putting a scope on the I2C pins to see if they're being diddled.

jhersh 01-16-2011 03:33 PM

Re: ADXL345_I2C Help
 
Quote:

Originally Posted by basicxman (Post 1000125)
Quite positive, the board and the I2C spare outputs on the digital sidecar are labelled. An accelerometer example VI also depicts a wiring diagram.

While they are labeled, I want to verify that you are connected to the 4 pins closest to the NXT RJ connector. The 4 pins farther from it are low-speed digital output lines (that are not supported by WPILib).

-Joe

ProgrammerMike7 01-16-2011 05:00 PM

Re: ADXL345_I2C Help
 
Quote:

Originally Posted by jhersh (Post 1001188)
While they are labeled, I want to verify that you are connected to the 4 pins closest to the NXT RJ connector.

They are.

basicxman 01-16-2011 06:43 PM

Re: ADXL345_I2C Help
 
Quote:

Originally Posted by ProgrammerMike7 (Post 1001274)
Quote:

Originally Posted by jhersh (Post 1001188)
While they are labeled, I want to verify that you are connected to the 4 pins closest to the NXT RJ connector. The 4 pins farther from it are low-speed digital output lines (that are not supported by WPILib).

-Joe

They are.

I believe Michael is correct, we have also tried different digital sidecars, including the one from our 2011 kit. Tomorrow we will post our full source code (updated), software versions, and a picture of our wiring setup.

jhersh 01-16-2011 09:05 PM

Re: ADXL345_I2C Help
 
Quote:

Originally Posted by ProgrammerMike7 (Post 999486)
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);


basicxman 01-17-2011 03:56 PM

Re: ADXL345_I2C Help
 
1 Attachment(s)
http://www.chiefdelphi.com/forums/at...d=129529771 6

Apologies for the poor quality of the image.

WindRiver Version: 3.0.1
WPILib Version: rev2242

Dutch8az 01-20-2011 12:01 AM

Power
 
I am definitely a beginner programmer but I thought that a file I read said that the accelerometer would start in power saving mode unless you wrote 0x08 to POWER_CTL (0x2D) and it would be unresponsive unless this was implemented
here's the file link:

http://usfirst.org/uploadedFiles/Rob...sor_Manual.pdf

sorry if im just imputting random info again I am really new to the coding world

basicxman 01-20-2011 01:19 PM

Re: Power
 
Quote:

Originally Posted by Dutch8az (Post 1004031)
I am definitely a beginner programmer but I thought that a file I read said that the accelerometer would start in power saving mode unless you wrote 0x08 to POWER_CTL (0x2D) and it would be unresponsive unless this was implemented

Great attention to detail, however the WPI Library already does this.

jhersh 01-20-2011 01:27 PM

Re: ADXL345_I2C Help
 
Have you tried looking at the lines with a logic analyzer or a scope yet?

basicxman 01-20-2011 01:28 PM

Re: ADXL345_I2C Help
 
Quote:

Originally Posted by jhersh (Post 1004307)
Have you tried looking at the lines with a logic analyzer or a scope yet?

Not yet, I haven't had a chance to bring in my USB logic analyzer yet.

ProgrammerMike7 01-26-2011 06:12 PM

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.

taichichuan 02-18-2012 03:53 PM

Re: ADXL345_I2C Help
 
Did you ever resolve this issue?

TIA,

Mike


All times are GMT -5. The time now is 03:54 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi