ICM-20602 Breakout Boardの使い方(Arduino)

ICM-20602 Breakout BoardのArduino使用例です.

配線例

サンプルプログラム

#include <Wire.h>

#define CONFIG 0x1A
#define ACCEL_XOUT_H 0x3B
#define GYRO_XOUT_H 0x43
#define PWR_MGMT_1 0x6B
#define WHO_AM_I 0x75

float accel[3], gyro[3];
int addr = 0b1101001;

void setup() {
  Serial.begin(9600);

  Wire.begin();

  Wire.beginTransmission(addr);
  Wire.write(CONFIG);
  Wire.write(0x00);
  Wire.endTransmission();

  Wire.beginTransmission(addr);
  Wire.write(PWR_MGMT_1);
  Wire.write(0x01);
  Wire.endTransmission();

  Wire.beginTransmission(addr);
  Wire.write(WHO_AM_I);
  Wire.endTransmission();
  Wire.requestFrom(addr, 1);
  if (Wire.read() == 0x12) {
    Serial.println("OK");
  } else  {
    Serial.println("NG");
  }
}

void loop() {

  Wire.beginTransmission(addr);
  Wire.write(ACCEL_XOUT_H);
  Wire.endTransmission();
  Wire.requestFrom(addr, 6);
  accel[0] = (int)(Wire.read() << 8 | Wire.read()) / 16384.0;
  accel[1] = (int)(Wire.read() << 8 | Wire.read()) / 16384.0;
  accel[2] = (int)(Wire.read() << 8 | Wire.read()) / 16384.0;

  Serial.print("ax:");
  Serial.print(accel[0]);
  Serial.print(",");
  Serial.print("ay:");
  Serial.print(accel[1]);
  Serial.print(",");
  Serial.print("az:");
  Serial.print(accel[2]);
  Serial.print(",");

  Wire.beginTransmission(addr);
  Wire.write(GYRO_XOUT_H);
  Wire.endTransmission();
  Wire.requestFrom(addr, 6);
  gyro[0] = (int)(Wire.read() << 8 | Wire.read()) / 131.0;
  gyro[1] = (int)(Wire.read() << 8 | Wire.read()) / 131.0;
  gyro[2] = (int)(Wire.read() << 8 | Wire.read()) / 131.0;

  Serial.print("wx:");
  Serial.print(gyro[0]);
  Serial.print(",");
  Serial.print("wy:");
  Serial.print(gyro[1]);
  Serial.print(",");
  Serial.print("wz:");
  Serial.print(gyro[2]);
  Serial.println("");
}
お買い物カゴ