Codey OnlineArduino- & ESP32-Komponentenbibliothek › Accelerometer and Gyroscope I2C MPU-6050
Accelerometer and Gyroscope I2C MPU-6050
Sensoren

Accelerometer and Gyroscope I2C MPU-6050

Der MPU-6050 ist ein Inertialsensor, der einen 3-Achsen-Beschleunigungssensor und ein 3-Achsen-Gyroskop für die Messung von Bewegung und Lage kombiniert. Er kommuniziert über die I2C-Schnittstelle mit SDA und SCL (mit Adressauswahl über AD0) und kann einen Interrupt-Ausgang (INT) für ereignisgesteuerte Messungen bereitstellen. Verwende VCC und GND für die Versorgung und verbinde die I2C-Leitungen mit den entsprechenden Arduino/ESP32-I2C-Pins.

Breite: 21.2 mm

Pinbelegung — Accelerometer and Gyroscope I2C MPU-6050

Pin Signal Beschreibung
INT interrupt Interrupt output from MPU-6050 for data-ready or motion events.
AD0 digital I2C address select input; low=0x68, high=0x69.
XCL SCL Auxiliary I2C clock for external sensors connected through MPU-6050.
XDA SDA Auxiliary I2C data for external sensors connected through MPU-6050.
SDA SDA Main I2C data line to the host microcontroller.
SCL SCL Main I2C clock line from the host microcontroller.
GND ground Ground reference for power and I2C signals.
VCC power Module power input, typically 3.3V to 5V depending on board regulator.

Beispielschaltplan — Accelerometer and Gyroscope I2C MPU-6050

Von Nach Kabel
board:5V x1:VCC red
board:GND x1:GND black
board:SDA x1:SDA green
board:SCL x1:SCL blue

Arduino-Beispielcode — Accelerometer and Gyroscope I2C MPU-6050

Dieses Beispiel wurde für das arduino-uno geschrieben und kompiliergeprüft. Codey Online passt es für jedes andere unterstützte Board an.

#include <Wire.h>

const uint8_t MPU_ADDR = 0x68; // AD0 low on the module
const uint8_t PWR_MGMT_1 = 0x6B;
const uint8_t ACCEL_XOUT_H = 0x3B;

void writeRegister(uint8_t reg, uint8_t value) {
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(reg);
  Wire.write(value);
  Wire.endTransmission(true);
}

void readBytes(uint8_t reg, uint8_t count, uint8_t *buffer) {
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(reg);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_ADDR, count, true);
  for (uint8_t i = 0; i < count && Wire.available(); i++) {
    buffer[i] = Wire.read();
  }
}

int16_t toInt16(uint8_t highByte, uint8_t lowByte) {
  return (int16_t)((highByte << 8) | lowByte);
}

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  Wire.begin();
  Wire.setClock(400000);

  // Wake up the MPU-6050 because it starts in sleep mode.
  writeRegister(PWR_MGMT_1, 0x00);
  delay(100);

  Serial.println("MPU-6050 accelerometer + gyroscope demo");
  Serial.println("Reading raw acceleration and gyroscope data...");
}

void loop() {
  uint8_t raw[14];
  readBytes(ACCEL_XOUT_H, 14, raw);

  int16_t accelX = toInt16(raw[0], raw[1]);
  int16_t accelY = toInt16(raw[2], raw[3]);
  int16_t accelZ = toInt16(raw[4], raw[5]);
  int16_t tempRaw = toInt16(raw[6], raw[7]);
  int16_t gyroX = toInt16(raw[8], raw[9]);
  int16_t gyroY = toInt16(raw[10], raw[11]);
  int16_t gyroZ = toInt16(raw[12], raw[13]);

  float tempC = (tempRaw / 340.0) + 36.53;

  Serial.print("Accel [LSB] X:");
  Serial.print(accelX);
  Serial.print(" Y:");
  Serial.print(accelY);
  Serial.print(" Z:");
  Serial.print(accelZ);

  Serial.print("  Gyro [LSB] X:");
  Serial.print(gyroX);
  Serial.print(" Y:");
  Serial.print(gyroY);
  Serial.print(" Z:");
  Serial.print(gyroZ);

  Serial.print("  Temp:");
  Serial.print(tempC, 2);
  Serial.println(" C");

  delay(500);
}

Ähnliche Komponenten

18650 Battery Shield with USB-C Charger and 5V Boost Converter

18650 Battery Shield with USB-C Charger and 5V Boost Converter

2.4 inch OLED Display I2C 3.3V

2.4 inch OLED Display I2C 3.3V

3.5 inch TFT LCD Shield

3.5 inch TFT LCD Shield

50kg Load Cell Weight Sensor

50kg Load Cell Weight Sensor

Bau dein Arduino- oder ESP32-Projekt mit AI

Beschreib einfach, was du bauen willst. Codey Online schreibt den Code, zeichnet den Schaltplan, kompiliert alles und flasht dein Board direkt aus dem Browser.

Kostenlos starten