safwan092

test code

May 5th, 2020
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Author         : Saga Kusuma Wijaya
  3.  * Date Created   : 20 July 2019
  4.  * Project        : Tutorial Arduino ATM
  5.  * Dedicated to   : emtronics
  6.  * Youtube        : https://www.youtube.com/channel/UCW4GRacd319Ml2cv-B9-uxg
  7.  * Instagram      : https://www.instagram.com/emtronics.official/
  8.  * Website        : https://emtronicsofficial.com
  9.  * Facebook      : https://www.facebook.com/emtronics.official/
  10.  * Email          : contact@emtronicsofficial.com
  11.  *
  12.  * Description    : This code is edited example from "MPU9250.h" library.
  13.  */
  14.  
  15. #include "MPU9250.h"
  16.  
  17. MPU9250 mpu = MPU9250();
  18.  
  19. int gyro_X, gyro_Y, gyro_Z;
  20.  
  21. void setup(void) {
  22.   Serial.begin(9600);
  23.   uint8_t temp = mpu.begin();
  24. }
  25.  
  26. void loop() {
  27.   //Accel
  28.   mpu.set_accel_range(RANGE_4G);
  29.   mpu.get_accel();
  30.   Serial.println(F("ACCELEROMETER"));
  31.   Serial.print("X: ");  Serial.print(mpu.x);
  32.   Serial.print("\tY: "); Serial.print(mpu.y);
  33.   Serial.print("\t\tZ: "); Serial.print(mpu.z);
  34.  
  35.  
  36.   mpu.get_accel_g();
  37.   Serial.print("\t\tX_g: "); Serial.print(mpu.x_g, 2);
  38.   Serial.print("\tY_g: "); Serial.print(mpu.y_g, 2);
  39.   Serial.print("\tZ_g: "); Serial.print(mpu.z_g, 2);  Serial.println(" G");
  40.   Serial.println('\n');
  41.  
  42.   //Gyro
  43.   mpu.set_gyro_range(RANGE_GYRO_250);
  44.   mpu.get_gyro();
  45.   gyro_X = mpu.gx;
  46.   gyro_Y = mpu.gy;
  47.   gyro_Z = mpu.gz;
  48.   Serial.println(F("GYROSCOPE"));
  49.   Serial.print("GX: ");  Serial.print(gyro_X);
  50.   Serial.print("\t\tGY: "); Serial.print(gyro_Y);
  51.   Serial.print("\t\tGZ: "); Serial.print(gyro_Z);
  52.  
  53.   mpu.get_gyro_d();
  54.   Serial.print("\t\tGX_g: "); Serial.print(mpu.gx_d, 2);
  55.   Serial.print("\tGY_g: "); Serial.print(mpu.gy_d, 2);
  56.   Serial.print("\tGZ_g: "); Serial.print(mpu.gz_d, 2); Serial.println(" º/s");
  57.   Serial.println('\n');
  58.  
  59.   //Mag
  60.   mpu.set_mag_scale(SCALE_14_BITS);
  61.   mpu.set_mag_speed(MAG_8_Hz);
  62.   if (!mpu.get_mag()) {
  63.     Serial.println(F("MAGNETOMETER"));
  64.     Serial.print("MX: ");  Serial.print(mpu.mx);
  65.     Serial.print("\t\tMY: "); Serial.print(mpu.my);
  66.     Serial.print("\t\tMZ: "); Serial.print(mpu.mz);
  67.  
  68.     mpu.get_mag_t();
  69.     Serial.print("\tMX_t: "); Serial.print(mpu.mx_t, 2);
  70.     Serial.print("\tMY_t: "); Serial.print(mpu.my_t, 2);
  71.     Serial.print("\tMZ_t: "); Serial.print(mpu.mz_t, 2); Serial.println(" uT");
  72.     Serial.println('\n');
  73.   }
  74.   else {
  75.     // |X|+|Y|+|Z| must be < 4912μT to sensor measure correctly
  76.     Serial.println("Overflow no magnetometro.");
  77.   }
  78.  
  79.   // Temp    
  80.   Serial.print("Temperature is ");  Serial.print((((float)mpu.get_temp()) / 333.87 + 21.0), 1);  Serial.println(" degrees C");
  81.   Serial.println();
  82.   delay(500);
  83.   Serial.println('\n');
  84.   Serial.println('\n');
  85. }
RAW Paste Data