Go to Post I want my students to learn passion. I want them to care so much about what they are doing that they infect other people with it... be that FRC or anything else. - marshall [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 06-03-2010, 21:46
nedrobotics's Avatar
nedrobotics nedrobotics is offline
Scott Jewell - Team 1584
AKA: Fleet Admiral Jewell
FRC #1584 (Nederland Pirates)
Team Role: Mentor
 
Join Date: Dec 2009
Rookie Year: 2004
Location: Nederland, CO, USA
Posts: 5
nedrobotics is an unknown quantity at this point
C++ I2C Accelerometer - Can't send power

We have recently installed the 2010 Accelerometer (ADXL345) on our robot and have the new ADXL345 class code in Windriver. But whenever we try to read values from it, they all read 0. We believe this is because according to the FIRST Sensor Manual, “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.”

We are not sure how to write any values to the I2C class to turn on the accelerometer. We tried accessing the write function from the I2C class through the ADXL345_I2C class and using it within the main robot class, but then the code would not compile. What syntax would we use to write the value "0x08" to the POWER_CTL and turn on the accelerometer?
Reply With Quote
  #2   Spotlight this post!  
Unread 07-03-2010, 04:46
mikets's Avatar
mikets mikets is online now
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: C++ I2C Accelerometer - Can't send power

If you are using the ADXL345_I2C class, you should not have to deal with I2C. The class will take care of it for you. It will do the intialization for you provided that you give it the correct slot of your digital I/O module and correctly wire the accelerometer to the I2C port on the digital side car. Assuming your digital I/O module is in the default slot 4, your code should look something like this:
Code:
private:
    ADXL345_I2C *m_accel;
    ....

    ...
    // In your robot constructor.
    m_accel = new ADXL345_I2C(SensorBase::GetDefaultDigitalModule());
    ...

    // To read the accelerometer, you either read one of the axes or all axes at the same time.
    AllAxes accelData = m_accel->GetAccelerations();
    // or
    double xAxis = m_accel->GetAcceleration(kAxis_X);
Here is the source code for the ADXL345_I2C constructor. You can see that it is already doing the correct initialization for you.
Code:
ADXL345_I2C::ADXL345_I2C(UINT32 slot, ADXL345_I2C::DataFormat_Range range)
        : m_i2c (NULL)
{
        DigitalModule *module = DigitalModule::GetInstance(slot);
        m_i2c = module->GetI2C(kAddress);

        // Turn on the measurements
        // This is the line writing the value 0x8 to the PowerCtlRegister.
        m_i2c->Write(kPowerCtlRegister, kPowerCtl_Measure);
        // Specify the data format to read
        m_i2c->Write(kDataFormatRegister, kDataFormat_FullRes | (UINT8)range);
}
__________________

Last edited by mikets : 07-03-2010 at 04:54.
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 I2C Object/Class NerdGuy Java 32 12-02-2011 10:19
Help with 2010 Accelerometer & I2C wt200999 C/C++ 33 08-02-2010 15:16
i2c output virtuald Programming 16 18-01-2009 19:20
Help! Can't send files to NXT Brick via bluetooth Raptorace22 National Instruments LabVIEW and Data Acquisition 0 24-11-2008 16:39
I2C? John Gutmann Electrical 3 19-07-2005 22:52


All times are GMT -5. The time now is 02:48.

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