View Single Post
  #2   Spotlight this post!  
Unread 07-03-2010, 04:46
mikets's Avatar
mikets mikets is offline
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