Go to Post Think of the build season as kiddie bowling. Mentors should be the bumpers and your mom who lines you up and gives you advice. - Joe Matt [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 Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 14-01-2010, 12:07
wt200999's Avatar
wt200999 wt200999 is online now
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 323
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Help with 2010 Accelerometer & I2C

I am trying to implement the kit accelerometer, and I started by basing it off of the HiTechncCompass class from last years code. (I can't find the newest version, but I doubt that class has changed). The problem I am having is when I try to initialize the I2C in my robot constructor, the constructor does not finish and the robot stops responding. The console output from the serial port also does not give me any errors either. Here is the class I started, with simple functions just to see what I can get out of it:

I2CAccel.h
Code:
#ifndef __I2CACCEL__
#define __I2CACCEL__

#include "SensorBase.h"

class I2C;

class I2CAccel : public SensorBase
{
	public:
		I2CAccel(UINT32 ModuleSlot);
		~I2CAccel();
		float Get();
		
	private:
		static const kAddress = 0x3A;
		static const kReadAddress = 0x3B;
		static const kPowerSaving = 0x08;
		static const kPowerCtrl = 0x2D;
		
		I2C* m_i2c;
};

#endif
I2CAccel.cpp
Code:
#include "I2CAccel.h"
#include "DigitalModule.h"
#include "I2C.h"

I2CAccel::I2CAccel(UINT32 slot)
	: m_i2c (NULL)
{
        //Somewhere on these 3 lines it fails...
	DigitalModule *module = DigitalModule::GetInstance(slot);
	m_i2c = module->GetI2C(kAddress);
	
	m_i2c->Write(kPowerSaving,kPowerCtrl);
}

I2CAccel::~I2CAccel()
{
	delete m_i2c;
	m_i2c = NULL;
}

float I2CAccel::Get()
{
	UINT16 value;
	m_i2c->Read(kReadAddress, sizeof(value), (UINT8 *)&value);

	return (float)value;
}
I was wondering if anyone else has gotten theirs working?
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
Reply With Quote
  #2   Spotlight this post!  
Unread 15-01-2010, 12:33
bcieslak
 
Posts: n/a
Re: Help with 2010 Accelerometer & I2C

I am working on the same project with my team and play to modify the compass code to get me started. I am hoping the I2C code is good so I can concentrate on the accelerometer.

At first glance of the data sheet for the adxl345 it appears we will need to add more code that just the read of one register. Data is in 3 different registers at addresses 0x32 to 0x37 in a two's complement format so I would guess that returning a float from the read is the wrong choice. The compass may return a float but not the accelerometer. (this is what if get from the data sheet anyway).

We will probably have to trigger a sampling of some sort before the read.

I am not sure how the chip select is getting set or what the address is on the acclerometer. I'll start by assuming the chip is always selected and the address is zero (0).

As far as your code goes the only address I recognized is the power control register, not sure where you got the other ones. there not on my data sheet.


I'll keep you posted on what I find this weekend. And look forward to what others have to say.

Brian
Reply With Quote
  #3   Spotlight this post!  
Unread 15-01-2010, 13:21
bcieslak
 
Posts: n/a
Re: Help with 2010 Accelerometer & I2C

I had a little more time to dig into the data sheet and can see where you got address 3a and 3b from. It is the result of adding the r/w bit to the 7 bit address. From looking at the I2C code I wonder if it twittles that read write bit for you. I wonder if the address they are really looking for there is 0x1D.

If you want to work this out off line my email address is k9wis@yahoo.com

Brian
Reply With Quote
  #4   Spotlight this post!  
Unread 15-01-2010, 15:56
bcieslak
 
Posts: n/a
Re: Help with 2010 Accelerometer & I2C

One last thing...Don't try to turn on the measurement bit in the constructor.

There may be other objects associated with the I2C stuff that hasn't been constructed yet. Create an init method where you do the write and call it after you are sure all the construcing is done, like the first part of your main loop.

Brian

Reply With Quote
  #5   Spotlight this post!  
Unread 15-01-2010, 20:43
wt200999's Avatar
wt200999 wt200999 is online now
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 323
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Re: Help with 2010 Accelerometer & I2C

Yeah the address given in the Sensor Guide says 0x3A, and I figure its all in 8bit for the WPI Function, so the 0x1D wouldn't work with that but 0x3A would?? I really don't know I2C or WPI's implementation of it, so I don't really know. I'm going to keep playing with it tonight.

I also just found the register map, didn't see it in the datasheet when I worked on it last, don' know how I missed it.

The biggest issue I am having now is whenever I call the read or write function the robot freezes up, and my console output shows nothing. This is both when I try to perform a read or a write....
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
Reply With Quote
  #6   Spotlight this post!  
Unread 17-01-2010, 22:53
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Help with 2010 Accelerometer & I2C

Any luck so far? It would be awesome if you got this working.
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 17-01-2010, 23:18
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: Help with 2010 Accelerometer & I2C

Quote:
Originally Posted by bcieslak View Post
I had a little more time to dig into the data sheet and can see where you got address 3a and 3b from. It is the result of adding the r/w bit to the 7 bit address. From looking at the I2C code I wonder if it twittles that read write bit for you. I wonder if the address they are really looking for there is 0x1D.
The I2C library takes the 8-bit version of the address (i.e. 0x3A). It does automatically set the R/W bit.
Reply With Quote
  #8   Spotlight this post!  
Unread 17-01-2010, 23:20
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: Help with 2010 Accelerometer & I2C

The easiest approach would be to port the LabVIEW example called "ADXL345 I2C Accelerometer".
Reply With Quote
  #9   Spotlight this post!  
Unread 18-01-2010, 09:20
bcieslak
 
Posts: n/a
Re: Help with 2010 Accelerometer & I2C

Quote:
Originally Posted by jhersh View Post
The easiest approach would be to port the LabVIEW example called "ADXL345 I2C Accelerometer".
I am still new to this environment that FIRST has set up for us so please excuse my ingnorance....Where do I find the labview example for I2C. Right now I am set up to write C++ code using the WPI library and the windriver tools..I have no experience with labview..not even sure I have it installed..

Brian
Reply With Quote
  #10   Spotlight this post!  
Unread 18-01-2010, 09:50
whytheheckme's Avatar
whytheheckme whytheheckme is offline
Registered User
AKA: Jacob Komar
no team
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Providence, RI
Posts: 1,320
whytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond reputewhytheheckme has a reputation beyond repute
Send a message via ICQ to whytheheckme Send a message via AIM to whytheheckme Send a message via MSN to whytheheckme Send a message via Yahoo to whytheheckme
Re: Help with 2010 Accelerometer & I2C

Quote:
Originally Posted by wt200999 View Post
(I can't find the newest version, but I doubt that class has changed)
If I remember correctly, last year's class was slightly broken. I could be wrong, but you might consider finding the newer one.

Jacob
Reply With Quote
  #11   Spotlight this post!  
Unread 18-01-2010, 15:57
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: Help with 2010 Accelerometer & I2C

Quote:
Originally Posted by bcieslak View Post
I am still new to this environment that FIRST has set up for us so please excuse my ingnorance....Where do I find the labview example for I2C. Right now I am set up to write C++ code using the WPI library and the windriver tools..I have no experience with labview..not even sure I have it installed..

Brian
Naturally you need LabVIEW installed. Just run it from the start menu and in the getting started window that pops up on the bottom right there is a short list of examples... click on more examples and look for ADXL345 I2C Accelerometer.
Reply With Quote
  #12   Spotlight this post!  
Unread 20-01-2010, 02:06
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: Help with 2010 Accelerometer & I2C

Quote:
Originally Posted by wt200999 View Post
The biggest issue I am having now is whenever I call the read or write function the robot freezes up, and my console output shows nothing. This is both when I try to perform a read or a write....
I did find an issue with the initial release of the I2C for this year. The bug was introduced since last year. See details here: http://firstforge.wpi.edu/sf/go/artf1144

This bug would prevent the accelerometer from working.
Reply With Quote
  #13   Spotlight this post!  
Unread 22-01-2010, 09:58
bcieslak
 
Posts: n/a
Smile Re: Help with 2010 Accelerometer & I2C

Yippeee!! everything is finally working....We re imaged the Crio, made sure 'ALL' the updates were applied to the driver station and the development laptop, compiled then downloaded the BuiltinDefaultCode.out file.

Then we added Joe's accelerometer code and fixed the I2C.cpp file. and all still worked.

We had some problems with the IterativeDemo but I we'll revisit that later. The BuiltinDefaultcode is what we will base our robot code on.

Thanks to all especially Joe Hersh for all the info and his patience..They don't pay you enough...Every one should send Joe a starbucks gift card so he can buy enough coffee to keep him awake when he sending those responses at 3 AM..

Brian C
Reply With Quote
  #14   Spotlight this post!  
Unread 22-01-2010, 14:07
JDM JDM is offline
programming lead; team executive;..
FRC #2199 (Robo-Lions)
Team Role: Programmer
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Eldersburg, Maryland
Posts: 34
JDM is on a distinguished road
Re: Help with 2010 Accelerometer & I2C

Quote:
Originally Posted by bcieslak View Post
Yippeee!! everything is finally working....We re imaged the Crio, made sure 'ALL' the updates were applied to the driver station and the development laptop, compiled then downloaded the BuiltinDefaultCode.out file.

Then we added Joe's accelerometer code and fixed the I2C.cpp file. and all still worked.
Would you mind posting all the code that got it working for you? Hopefully that should speed it up for everyone.

Thanks
Reply With Quote
  #15   Spotlight this post!  
Unread 22-01-2010, 15: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: Help with 2010 Accelerometer & I2C

Quote:
Originally Posted by JDM View Post
Would you mind posting all the code that got it working for you? Hopefully that should speed it up for everyone.
Here's the discussion where I posted the initial support: http://decibel.ni.com/content/thread/5634

It will be officially included and supported in the next C++ update.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
2010 Accelerometer Documentation? JDM Sensors 13 18-01-2010 12:42
Accelerometer Help? elbuo Programming 16 19-01-2009 13:01
accelerometer help!! wildcats Electrical 2 18-01-2009 15:51
Accelerometer Help! Questions4mQ202 Electrical 4 15-01-2009 19:44
Accelerometer help Red Mage Programming 3 30-01-2008 18:49


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

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