Go to Post It's not about the numbers, it's what you can do with them. - AlecMataloni [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-01-2011, 20:36
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
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?
__________________
Wait (-1)
Reply With Quote
  #2   Spotlight this post!  
Unread 14-01-2011, 02:35
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 14-01-2011, 17:52
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: ADXL345_I2C Help

Quote:
Originally Posted by jhersh View Post
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 View Post
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 15-01-2011, 11:35
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: ADXL345_I2C Help

Quote:
Originally Posted by ProgrammerMike7 View Post
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.
__________________
Robots never, ever, ever, ever break -- The Robot Repairman (Backyardigans)
Reply With Quote
  #5   Spotlight this post!  
Unread 16-01-2011, 15:33
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: ADXL345_I2C Help

Quote:
Originally Posted by basicxman View Post
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
Reply With Quote
  #6   Spotlight this post!  
Unread 16-01-2011, 17:00
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

Quote:
Originally Posted by jhersh View Post
While they are labeled, I want to verify that you are connected to the 4 pins closest to the NXT RJ connector.
They are.
__________________
Wait (-1)
Reply With Quote
  #7   Spotlight this post!  
Unread 16-01-2011, 18:43
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: ADXL345_I2C Help

Quote:
Originally Posted by ProgrammerMike7 View Post
Quote:
Originally Posted by jhersh View Post
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.
Reply With Quote
  #8   Spotlight this post!  
Unread 16-01-2011, 21:05
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: ADXL345_I2C Help

Quote:
Originally Posted by ProgrammerMike7 View Post
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);
Reply With Quote
  #9   Spotlight this post!  
Unread 17-01-2011, 15:56
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
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
Attached Thumbnails
Click image for larger version

Name:	2011-01-17 15.47.58.jpg
Views:	139
Size:	141.7 KB
ID:	9717  
Reply With Quote
  #10   Spotlight this post!  
Unread 20-01-2011, 00:01
Dutch8az Dutch8az is offline
Registered User
FRC #2827
 
Join Date: Jan 2011
Location: Coronado
Posts: 2
Dutch8az is an unknown quantity at this point
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 : 20-01-2011 at 00:05.
Reply With Quote
  #11   Spotlight this post!  
Unread 20-01-2011, 13:19
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: Power

Quote:
Originally Posted by Dutch8az View Post
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.
Reply With Quote
  #12   Spotlight this post!  
Unread 20-01-2011, 13:27
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: ADXL345_I2C Help

Have you tried looking at the lines with a logic analyzer or a scope yet?
Reply With Quote
  #13   Spotlight this post!  
Unread 20-01-2011, 13:28
basicxman basicxman is offline
Emily Horsman
FRC #2200 (MMRambotics)
Team Role: Programmer
 
Join Date: Oct 2007
Rookie Year: 2007
Location: Burlington, Ontario
Posts: 971
basicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant futurebasicxman has a brilliant future
Send a message via AIM to basicxman Send a message via MSN to basicxman Send a message via Yahoo to basicxman
Re: ADXL345_I2C Help

Quote:
Originally Posted by jhersh View Post
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.
Reply With Quote
  #14   Spotlight this post!  
Unread 26-01-2011, 18:12
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
  #15   Spotlight this post!  
Unread 18-02-2012, 15:53
taichichuan's Avatar
taichichuan taichichuan is offline
Software Mentor
AKA: Mike Anderson
FRC #0116 (Epsilon Delta)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Herndon, VA
Posts: 328
taichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud oftaichichuan has much to be proud of
Send a message via AIM to taichichuan
Re: ADXL345_I2C Help

Did you ever resolve this issue?

TIA,

Mike
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 04:12.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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