For reference, using the MPU-6050 that I had from another board (beta backer sensor board for the DigiX??)... shoving it into a breadboard ,and wiring it to first the Arduino (3v3,GND,SDA and SCL only), and it worked just fine on the Arduino. Moved the MPU-6050 and code over to the Oak, and nothing was happening when I was using Particle variables. Used publish messages instead and it started talking sense. (Using Oaks VCC & Ground, SCL 2 and SDA 0). I had my USB to Serial adapter handy too, so I looked at the Serial messages the Oak was sending, and it was happily posting the same output the Arduino had been.
So for that accelerometer at least, I2C/Wire works without any changes. I don't know what the go with the Particle variables was... they just didn't appear to be registering. They did one time, not not since. When I check with curl, I get this:
{
"id": "d957040018c7df4293f7837d",
"name": "Oak3",
"last_app": null,
"last_ip_address": "58.96.45.108",
"last_heard": "2016-03-20T05:41:23.397Z",
"product_id": 82,
"connected": true,
"platform_id": 82,
"cellular": false,
"status": "normal",
"variables": {},
"functions": []
}
Anyway, some code is attached below which works. As I don't know a better way yet to detect the Oak core, I cheated and used #ifdefs that looks for the header file. So this code should be Oak & Arduino specific. It delays for 5 seconds between updates to honour the "1 event/sec" rate stated in the Particle docs (although it could have been reduced to 3 seconds!)
// Orginal code was : MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
#ifdef Oak_h
char szAcX[8] = "0";
char szAcY[8] = "0";
char szAcZ[8] = "0";
char szInfo[16];
#endif
void setup()
{
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
#ifdef Oak_h
Particle.variable("x_val", szAcX);
Particle.variable("y_val", szAcY);
Particle.variable("z_val", szAcZ);
delay(5000); //allow time for particle to register variables (or not!)
#endif
}
void loop()
{
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers
AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
#ifdef Oak_h
sprintf(szInfo, "%i", AcX);
Particle.publish("AcX", szInfo);
memcpy( szAcX, szInfo, 8 );
sprintf(szInfo, "%i", AcY);
Particle.publish("AcY", szInfo);
memcpy( szAcY, szInfo, 8 );
sprintf(szInfo, "%i", AcZ);
Particle.publish("AcZ", szInfo);
memcpy( szAcZ, szInfo, 8 );
delay(5000);
#else
delay(500);
#endif
}