Created
February 27, 2024 05:32
-
-
Save penpencool/57e928ffd87d2b03d907cbbccbc232c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ติดตั้งไลบารีที่นี่ https://github.com/sparkfun/SparkFun_MPU-9250-DMP_Arduino_Library/tree/master | |
| // VCC - 5V | |
| // GND - GND | |
| // SDA - A4 | |
| // SCL - A5 | |
| #include <Wire.h> | |
| #include <SparkFunMPU9250-DMP.h> | |
| MPU9250_DMP imu; | |
| void setup() { | |
| Serial.begin(115200); | |
| if (imu.begin() != INV_SUCCESS) { | |
| Serial.println("Unable to communicate with MPU-9250!"); | |
| while (1); | |
| } | |
| imu.setFullScaleAccelRange(MPU9250_ACCEL_RANGE_16G); | |
| imu.setFullScaleGyroRange(MPU9250_GYRO_RANGE_2000DPS); | |
| } | |
| void loop() { | |
| imu.update(); | |
| float ax, ay, az; | |
| imu.readAccelData(&ax, &ay, &az); | |
| Serial.print("Accelerometer: "); | |
| Serial.print("X = "); Serial.print(ax); Serial.print(" | "); | |
| Serial.print("Y = "); Serial.print(ay); Serial.print(" | "); | |
| Serial.print("Z = "); Serial.println(az); | |
| float gx, gy, gz; | |
| imu.readGyroData(&gx, &gy, &gz); | |
| Serial.print("Gyroscope: "); | |
| Serial.print("X = "); Serial.print(gx); Serial.print(" | "); | |
| Serial.print("Y = "); Serial.print(gy); Serial.print(" | "); | |
| Serial.print("Z = "); Serial.println(gz); | |
| float mx, my, mz; | |
| imu.readMagData(&mx, &my, &mz); | |
| Serial.print("Magnetometer: "); | |
| Serial.print("X = "); Serial.print(mx); Serial.print(" | "); | |
| Serial.print("Y = "); Serial.print(my); Serial.print(" | "); | |
| Serial.print("Z = "); Serial.println(mz); | |
| delay(1000); // Delay for 1 second | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment