Advertisement
pleasedontcode

"MPU6050 Initialization" rev_11

Jun 23rd, 2024
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "MPU6050 Initialization"
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-06-23 12:01:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* read gyroscope at maximum rate and show on serial. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /********* User code review feedback **********
  25. #### Feedback 1 ####
  26. - change serial to 56700.
  27. #### Feedback 2 ####
  28. - 1
  29. #### Feedback 3 ####
  30. - change serial to 115000.
  31. #### Feedback 4 ####
  32. - tf
  33. #### Feedback 5 ####
  34. - do not change nothing.
  35. ********* User code review feedback **********/
  36.  
  37. /****** DEFINITION OF LIBRARIES *****/
  38. #include <Wire.h>
  39. #include <MPU6050.h>  //https://github.com/electroniccats/mpu6050
  40.  
  41. /****** FUNCTION PROTOTYPES *****/
  42. void setup(void);
  43. void loop(void);
  44.  
  45. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  46. const uint8_t sensor_MPU6050_Interrupt_PIN_D2 = 2;
  47.  
  48. /***** DEFINITION OF I2C PINS *****/
  49. const uint8_t sensor_MPU6050_I2C_PIN_SDA_A4 = A4;
  50. const uint8_t sensor_MPU6050_I2C_PIN_SCL_A5 = A5;
  51. const uint8_t sensor_MPU6050_I2C_SLAVE_ADDRESS = 104;
  52.  
  53. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  54. MPU6050 accelgyro(sensor_MPU6050_I2C_SLAVE_ADDRESS); // Initialize MPU6050 with the specified I2C address
  55.  
  56. void setup(void) {
  57.     // put your setup code here, to run once:
  58.     Wire.begin(sensor_MPU6050_I2C_PIN_SDA_A4, sensor_MPU6050_I2C_PIN_SCL_A5); // Initialize I2C communication
  59.     Serial.begin(115200); // Initialize serial communication with the specified baud rate
  60.     Serial.println("Initializing I2C devices...");
  61.  
  62.     accelgyro.initialize(); // Initialize MPU6050
  63.     Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
  64.  
  65.     pinMode(sensor_MPU6050_Interrupt_PIN_D2, INPUT); // Set interrupt pin as input
  66. }
  67.  
  68. void loop(void) {
  69.     // put your main code here, to run repeatedly:
  70.     int16_t ax, ay, az;
  71.     int16_t gx, gy, gz;
  72.  
  73.     // Read accelerometer and gyroscope data
  74.     accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  75.  
  76.     // Print the data to the Serial Monitor
  77.     Serial.print("a/g:\t");
  78.     Serial.print(ax); Serial.print("\t");
  79.     Serial.print(ay); Serial.print("\t");
  80.     Serial.print(az); Serial.print("\t");
  81.     Serial.print(gx); Serial.print("\t");
  82.     Serial.print(gy); Serial.print("\t");
  83.     Serial.println(gz);
  84.  
  85.     // Removed delay to read gyroscope at maximum rate
  86. }
  87.  
  88. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement