Advertisement
pleasedontcode

**Sensor Data** rev_09

Nov 28th, 2024
58
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: **Sensor Data**
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-29 00:00:24
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The project must implement the LM35 sensor for */
  21.     /* continuous temperature monitoring, with readings */
  22.     /* taken from analog pin A0. The setup should include */
  23.     /* necessary error handling for sensor malfunctions. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.     /* read gyroscope and accelerometer and print on */
  26.     /* serial. */
  27. /****** END SYSTEM REQUIREMENTS *****/
  28.  
  29. /* START CODE */
  30.  
  31. /****** DEFINITION OF LIBRARIES *****/
  32. #include <Wire.h>
  33. #include <LM35.h>   //https://github.com/wilmouths/LM35
  34. #include <BMI160Gen.h>  //https://github.com/EmotiBit/EmotiBit_BMI160
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39.  
  40. /***** DEFINITION OF ANALOG INPUT PINS *****/
  41. const uint8_t temp_LM35_Vout_PIN_A0 = A0;
  42.  
  43. /***** DEFINITION OF I2C PINS *****/
  44. const uint8_t accelerometer_BMI160_I2C_PIN_SDA_A4 = A4;
  45. const uint8_t accelerometer_BMI160_I2C_PIN_SCL_A5 = A5;
  46. const uint8_t accelerometer_BMI160_I2C_SLAVE_ADDRESS = 104;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. LM35 lm35(temp_LM35_Vout_PIN_A0); // Create LM35 object
  50. // Removed the definition of BMI160 object here
  51. // BMI160GenClass BMI160; // This line has been removed
  52.  
  53. void setup(void)
  54. {
  55.     // Initialize serial communication
  56.     Serial.begin(9600);
  57.    
  58.     // Initialize LM35 temperature sensor
  59.     pinMode(temp_LM35_Vout_PIN_A0, INPUT);
  60.    
  61.     // Initialize BMI160 sensor
  62.     if (!BMI160.begin(BMI160GenClass::I2C_MODE, Wire, accelerometer_BMI160_I2C_SLAVE_ADDRESS)) {
  63.         Serial.println("BMI160 initialization failed!");
  64.         while (1); // Halt if initialization fails
  65.     }
  66. }
  67.  
  68. void loop(void)
  69. {
  70.     // Read temperature from LM35
  71.     double temperature = lm35.getTemp(); // Get temperature in Celsius
  72.     Serial.print("Temperature: ");
  73.     Serial.print(temperature);
  74.     Serial.println(" °C");
  75.    
  76.     // Read gyroscope and accelerometer data from BMI160
  77.     int16_t ax, ay, az; // Accelerometer data
  78.     int16_t gx, gy, gz; // Gyroscope data
  79.    
  80.     BMI160.readAccelerometer(ax, ay, az);
  81.     BMI160.readGyro(gx, gy, gz); // Updated to use readGyro instead of readGyroscope
  82.    
  83.     // Print accelerometer data
  84.     Serial.print("Accelerometer: ");
  85.     Serial.print(" ax: "); Serial.print(ax);
  86.     Serial.print(", ay: "); Serial.print(ay);
  87.     Serial.print(", az: "); Serial.println(az);
  88.    
  89.     // Print gyroscope data
  90.     Serial.print("Gyroscope: ");
  91.     Serial.print(" gx: "); Serial.print(gx);
  92.     Serial.print(", gy: "); Serial.print(gy);
  93.     Serial.print(", gz: "); Serial.println(gz);
  94.    
  95.     // Delay before the next reading
  96.     delay(1000); // Delay for 1 second
  97. }
  98.  
  99. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement