For an Arduino project I am working on, I am trying to modify the SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 to support DSSCircuit's I2C Master Library (https://github.com/DSSCircuits/I2C-Master-Library). This is to combat the known issue of Arduino's Wire library to often get hung up while trying to run the EndTransmission function.
#include <FreeSixIMU.h>
#include <FIMU_ADXL345.h>
#include <FIMU_ITG3200.h>
#include <Wire.h>
#include <I2C.h>
int raw[6]; // x y z yaw pitch roll
// Set the FreeSixIMU object
FreeSixIMU sixDOF = FreeSixIMU();
void setup() {
Serial.begin(9600);
I2c.begin();
delay(100);
sixDOF.init(); //begin the IMU
delay(100);
}
void loop() {
sixDOF.getRawValues(raw);
Serial.print(raw[0]);
Serial.print(" x | ");
Serial.print(raw[1]);
Serial.print(" y | ");
Serial.print(raw[2]);
Serial.println(" z");
delay(100);
}
And I changed the selected IMU library functions as follows:
// Writes val to address register on device
void ADXL345::writeTo(byte address, byte val) {
I2c.write(address, val);
// send register address
}
// Reads num bytes starting from address register on device in to _buff array
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
I2c.read(address, (byte) num);
// sends address to read from
}
void ITG3200::writemem(uint8_t _addr, uint8_t _val) {
I2c.write(_addr, _val); // start transmission to device
}
void ITG3200::readmem(uint8_t _addr, uint8_t _nbytes, uint8_t __buff[]) {
I2c.read(_addr, _addr, _nbytes); // start transmission to device
}
And added the #include <I2C.h> statements to the headers files where applicable.
When running the example code, the serial output will not change values based on how I move the accelerometer, which makes me think I used the wrong slave address to read data from, or some other issue.
Please see PersonAGem's edit below. Using the wire library is known to have arbitrary hangups, and in this example PersonAGem lists the edits I should make to the other libraries I am using as well as gives me the code I should use in my .ino.
I ask a new question about this topic here.