|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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? |
|
#2
|
||||
|
||||
|
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);
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |