Arduastur

// Defines for the bits, to be able to change // between bit number and binary definition.// By using the bit number, programming the sensor // is like programming the AVR microcontroller.// But instead of using "(1<<X)", or "_BV(X)", // the Arduino "bit(X)" is used.#define MPU6050_D0 0#define MPU6050_D1 1#define MPU6050_D2 2#define MPU6050_D3 3#define MPU6050_D4 4#define MPU6050_D5 5#define MPU6050_D6 6#define MPU6050_D7 7

// CONFIG Register// DLPF is Digital Low Pass Filter for both gyro and accelerometers.// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_DLPF_CFG0 MPU6050_D0#define MPU6050_DLPF_CFG1 MPU6050_D1#define MPU6050_DLPF_CFG2 MPU6050_D2#define MPU6050_EXT_SYNC_SET0 MPU6050_D3#define MPU6050_EXT_SYNC_SET1 MPU6050_D4#define MPU6050_EXT_SYNC_SET2 MPU6050_D5

// Alternative names for the combined definitions// This name uses the bandwidth (Hz) for the accelometer,// for the gyro the bandwidth is almost the same.#define MPU6050_DLPF_260HZ MPU6050_DLPF_CFG_0#define MPU6050_DLPF_184HZ MPU6050_DLPF_CFG_1#define MPU6050_DLPF_94HZ MPU6050_DLPF_CFG_2#define MPU6050_DLPF_44HZ MPU6050_DLPF_CFG_3#define MPU6050_DLPF_21HZ MPU6050_DLPF_CFG_4#define MPU6050_DLPF_10HZ MPU6050_DLPF_CFG_5#define MPU6050_DLPF_5HZ MPU6050_DLPF_CFG_6#define MPU6050_DLPF_RESERVED MPU6050_DLPF_CFG_7

// GYRO_CONFIG Register// The XG_ST, YG_ST, ZG_ST are bits for selftest.// The FS_SEL sets the range for the gyro.// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_FS_SEL0 MPU6050_D3#define MPU6050_FS_SEL1 MPU6050_D4#define MPU6050_ZG_ST MPU6050_D5#define MPU6050_YG_ST MPU6050_D6#define MPU6050_XG_ST MPU6050_D7

// ACCEL_CONFIG Register// The XA_ST, YA_ST, ZA_ST are bits for selftest.// The AFS_SEL sets the range for the accelerometer.// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_ACCEL_HPF0 MPU6050_D0#define MPU6050_ACCEL_HPF1 MPU6050_D1#define MPU6050_ACCEL_HPF2 MPU6050_D2#define MPU6050_AFS_SEL0 MPU6050_D3#define MPU6050_AFS_SEL1 MPU6050_D4#define MPU6050_ZA_ST MPU6050_D5#define MPU6050_YA_ST MPU6050_D6#define MPU6050_XA_ST MPU6050_D7

// Alternative names for the combined definitions// The name uses the full scale range for the accelerometer.#define MPU6050_AFS_SEL_2G MPU6050_AFS_SEL_0#define MPU6050_AFS_SEL_4G MPU6050_AFS_SEL_1#define MPU6050_AFS_SEL_8G MPU6050_AFS_SEL_2#define MPU6050_AFS_SEL_16G MPU6050_AFS_SEL_3

// FIFO_EN Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_SLV0_FIFO_EN MPU6050_D0#define MPU6050_SLV1_FIFO_EN MPU6050_D1#define MPU6050_SLV2_FIFO_EN MPU6050_D2#define MPU6050_ACCEL_FIFO_EN MPU6050_D3#define MPU6050_ZG_FIFO_EN MPU6050_D4#define MPU6050_YG_FIFO_EN MPU6050_D5#define MPU6050_XG_FIFO_EN MPU6050_D6#define MPU6050_TEMP_FIFO_EN MPU6050_D7

// I2C_MST_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_MST_CLK0 MPU6050_D0#define MPU6050_I2C_MST_CLK1 MPU6050_D1#define MPU6050_I2C_MST_CLK2 MPU6050_D2#define MPU6050_I2C_MST_CLK3 MPU6050_D3#define MPU6050_I2C_MST_P_NSR MPU6050_D4#define MPU6050_SLV_3_FIFO_EN MPU6050_D5#define MPU6050_WAIT_FOR_ES MPU6050_D6#define MPU6050_MULT_MST_EN MPU6050_D7

Arduastur

// I2C_SLV0_ADDR Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV0_RW MPU6050_D7

// I2C_SLV0_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV0_LEN0 MPU6050_D0#define MPU6050_I2C_SLV0_LEN1 MPU6050_D1#define MPU6050_I2C_SLV0_LEN2 MPU6050_D2#define MPU6050_I2C_SLV0_LEN3 MPU6050_D3#define MPU6050_I2C_SLV0_GRP MPU6050_D4#define MPU6050_I2C_SLV0_REG_DIS MPU6050_D5#define MPU6050_I2C_SLV0_BYTE_SW MPU6050_D6#define MPU6050_I2C_SLV0_EN MPU6050_D7// A mask for the length#define MPU6050_I2C_SLV0_LEN_MASK 0x0F

// I2C_SLV1_ADDR Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV1_RW MPU6050_D7

// I2C_SLV1_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV1_LEN0 MPU6050_D0#define MPU6050_I2C_SLV1_LEN1 MPU6050_D1#define MPU6050_I2C_SLV1_LEN2 MPU6050_D2#define MPU6050_I2C_SLV1_LEN3 MPU6050_D3#define MPU6050_I2C_SLV1_GRP MPU6050_D4#define MPU6050_I2C_SLV1_REG_DIS MPU6050_D5#define MPU6050_I2C_SLV1_BYTE_SW MPU6050_D6#define MPU6050_I2C_SLV1_EN MPU6050_D7

// A mask for the length#define MPU6050_I2C_SLV1_LEN_MASK 0x0F

// I2C_SLV2_ADDR Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV2_RW MPU6050_D7

// I2C_SLV2_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV2_LEN0 MPU6050_D0#define MPU6050_I2C_SLV2_LEN1 MPU6050_D1#define MPU6050_I2C_SLV2_LEN2 MPU6050_D2#define MPU6050_I2C_SLV2_LEN3 MPU6050_D3#define MPU6050_I2C_SLV2_GRP MPU6050_D4#define MPU6050_I2C_SLV2_REG_DIS MPU6050_D5#define MPU6050_I2C_SLV2_BYTE_SW MPU6050_D6#define MPU6050_I2C_SLV2_EN MPU6050_D7

// A mask for the length#define MPU6050_I2C_SLV2_LEN_MASK 0x0F

// I2C_SLV3_ADDR Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV3_RW MPU6050_D7

// I2C_SLV3_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV3_LEN0 MPU6050_D0#define MPU6050_I2C_SLV3_LEN1 MPU6050_D1#define MPU6050_I2C_SLV3_LEN2 MPU6050_D2#define MPU6050_I2C_SLV3_LEN3 MPU6050_D3#define MPU6050_I2C_SLV3_GRP MPU6050_D4#define MPU6050_I2C_SLV3_REG_DIS MPU6050_D5#define MPU6050_I2C_SLV3_BYTE_SW MPU6050_D6#define MPU6050_I2C_SLV3_EN MPU6050_D7

// A mask for the length#define MPU6050_I2C_SLV3_LEN_MASK 0x0F

// I2C_SLV4_ADDR Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV4_RW MPU6050_D7

// I2C_SLV4_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_MST_DLY0 MPU6050_D0#define MPU6050_I2C_MST_DLY1 MPU6050_D1#define MPU6050_I2C_MST_DLY2 MPU6050_D2#define MPU6050_I2C_MST_DLY3 MPU6050_D3#define MPU6050_I2C_MST_DLY4 MPU6050_D4#define MPU6050_I2C_SLV4_REG_DIS MPU6050_D5#define MPU6050_I2C_SLV4_INT_EN MPU6050_D6#define MPU6050_I2C_SLV4_EN MPU6050_D7

// A mask for the delay#define MPU6050_I2C_MST_DLY_MASK 0x1F

// I2C_MST_STATUS Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV0_NACK MPU6050_D0#define MPU6050_I2C_SLV1_NACK MPU6050_D1#define MPU6050_I2C_SLV2_NACK MPU6050_D2#define MPU6050_I2C_SLV3_NACK MPU6050_D3#define MPU6050_I2C_SLV4_NACK MPU6050_D4#define MPU6050_I2C_LOST_ARB MPU6050_D5#define MPU6050_I2C_SLV4_DONE MPU6050_D6#define MPU6050_PASS_THROUGH MPU6050_D7

// I2C_PIN_CFG Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_CLKOUT_EN MPU6050_D0#define MPU6050_I2C_BYPASS_EN MPU6050_D1#define MPU6050_FSYNC_INT_EN MPU6050_D2#define MPU6050_FSYNC_INT_LEVEL MPU6050_D3#define MPU6050_INT_RD_CLEAR MPU6050_D4#define MPU6050_LATCH_INT_EN MPU6050_D5#define MPU6050_INT_OPEN MPU6050_D6#define MPU6050_INT_LEVEL MPU6050_D7

// INT_ENABLE Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_DATA_RDY_EN MPU6050_D0#define MPU6050_I2C_MST_INT_EN MPU6050_D3#define MPU6050_FIFO_OFLOW_EN MPU6050_D4#define MPU6050_ZMOT_EN MPU6050_D5#define MPU6050_MOT_EN MPU6050_D6#define MPU6050_FF_EN MPU6050_D7

// INT_STATUS Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_DATA_RDY_INT MPU6050_D0#define MPU6050_I2C_MST_INT MPU6050_D3#define MPU6050_FIFO_OFLOW_INT MPU6050_D4#define MPU6050_ZMOT_INT MPU6050_D5#define MPU6050_MOT_INT MPU6050_D6#define MPU6050_FF_INT MPU6050_D7

// MOT_DETECT_STATUS Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_MOT_ZRMOT MPU6050_D0#define MPU6050_MOT_ZPOS MPU6050_D2#define MPU6050_MOT_ZNEG MPU6050_D3#define MPU6050_MOT_YPOS MPU6050_D4#define MPU6050_MOT_YNEG MPU6050_D5#define MPU6050_MOT_XPOS MPU6050_D6#define MPU6050_MOT_XNEG MPU6050_D7

// IC2_MST_DELAY_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_I2C_SLV0_DLY_EN MPU6050_D0#define MPU6050_I2C_SLV1_DLY_EN MPU6050_D1#define MPU6050_I2C_SLV2_DLY_EN MPU6050_D2#define MPU6050_I2C_SLV3_DLY_EN MPU6050_D3#define MPU6050_I2C_SLV4_DLY_EN MPU6050_D4#define MPU6050_DELAY_ES_SHADOW MPU6050_D7

// SIGNAL_PATH_RESET Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_TEMP_RESET MPU6050_D0#define MPU6050_ACCEL_RESET MPU6050_D1#define MPU6050_GYRO_RESET MPU6050_D2

// MOT_DETECT_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_MOT_COUNT0 MPU6050_D0#define MPU6050_MOT_COUNT1 MPU6050_D1#define MPU6050_FF_COUNT0 MPU6050_D2#define MPU6050_FF_COUNT1 MPU6050_D3#define MPU6050_ACCEL_ON_DELAY0 MPU6050_D4#define MPU6050_ACCEL_ON_DELAY1 MPU6050_D5

// USER_CTRL Register// These are the names for the bits.// Use these only with the bit() macro.#define MPU6050_SIG_COND_RESET MPU6050_D0#define MPU6050_I2C_MST_RESET MPU6050_D1#define MPU6050_FIFO_RESET MPU6050_D2#define MPU6050_I2C_IF_DIS MPU6050_D4 // must be 0 for MPU-6050#define MPU6050_I2C_MST_EN MPU6050_D5#define MPU6050_FIFO_EN MPU6050_D6

// According to the datasheet, the 'sleep' bit // should read a '1'. But I read a '0'. // That bit has to be cleared, since the sensor // is in sleep mode at power-up. Even if the // bit reads '0'. error = MPU6050_read (MPU6050_PWR_MGMT_2, &c, 1); Serial.print(F("PWR_MGMT_2 : ")); Serial.print(c,HEX); Serial.print(F(", error = ")); Serial.println(error,DEC);

// --------------------------------------------------------// MPU6050_read//// This is a common function to read multiple bytes // from an I2C device.//// It uses the boolean parameter for Wire.endTransMission()// to be able to hold or release the I2C-bus. // This is implemented in Arduino 1.0.1.//// Only this function is used to read. // There is no function for a single byte.//int MPU6050_read(int start, uint8_t *buffer, int size){ int i, n, error;

// --------------------------------------------------------// MPU6050_write//// This is a common function to write multiple bytes to an I2C device.//// If only a single register is written,// use the function MPU_6050_write_reg().//// Parameters:// start : Start address, use a define for the register// pData : A pointer to the data to write.// size : The number of bytes to write.//// If only a single register is written, a pointer// to the data has to be used, and the size is// a single byte:// int data = 0; // the data to write// MPU6050_write (MPU6050_PWR_MGMT_1, &c, 1);//int MPU6050_write(int start, const uint8_t *pData, int size){ int n, error;

// --------------------------------------------------------// MPU6050_write_reg//// An extra function to write a single register.// It is just a wrapper around the MPU_6050_write()// function, and it is only a convenient function// to make it easier to write a single register.//int MPU6050_write_reg(int reg, uint8_t data){ int error;