|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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);
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? |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
Re: ADXL345_I2C Help
Quote:
Quite positive, the board and the I2C spare outputs on the digital sidecar are labelled. An accelerometer example VI also depicts a wiring diagram. |
|
#4
|
|||
|
|||
|
Re: ADXL345_I2C Help
Quote:
-Joe |
|
#5
|
|||
|
|||
|
Re: ADXL345_I2C Help
They are.
|
|
#6
|
|||
|
|||
|
Re: ADXL345_I2C Help
Quote:
|
|
#7
|
||||
|
||||
|
Re: ADXL345_I2C Help
Quote:
|
|
#8
|
|||
|
|||
|
Re: ADXL345_I2C Help
Quote:
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);
|
|
#9
|
|||
|
|||
|
Re: ADXL345_I2C Help
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 |
|
#10
|
|||
|
|||
|
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 Last edited by Dutch8az : 01-20-2011 at 12:05 AM. |
|
#11
|
|||
|
|||
|
Re: Power
Great attention to detail, however the WPI Library already does this.
|
|
#12
|
|||
|
|||
|
Re: ADXL345_I2C Help
Have you tried looking at the lines with a logic analyzer or a scope yet?
|
|
#13
|
|||
|
|||
|
Re: ADXL345_I2C Help
Not yet, I haven't had a chance to bring in my USB logic analyzer yet.
|
|
#14
|
|||
|
|||
|
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);
|
|
#15
|
||||
|
||||
|
Re: ADXL345_I2C Help
Did you ever resolve this issue?
TIA, Mike |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|