Advertisement
pleasedontcode

"Sensor Display" rev_01

Jun 10th, 2024
321
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 Display"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-10 18:02:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a heart rate and SpO2 monitoring system */
  21.     /* using the MAX30100 sensor. The system should */
  22.     /* initialize the sensor, read data continuously, and */
  23.     /* display the results on a I2C oled display */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Wire.h>
  28. #include <MAX30100_PulseOximeter.h>  // https://github.com/gabriel-milan/Arduino-MAX30100
  29. #include <Adafruit_GFX.h>
  30. #include <Adafruit_SSD1306.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t SENSOR_MAX30100_INT_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF I2C PINS *****/
  40. const uint8_t SENSOR_MAX30100_I2C_PIN_SDA_A4 = A4;
  41. const uint8_t SENSOR_MAX30100_I2C_PIN_SCL_A5 = A5;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. PulseOximeter pox;  // Create an instance of the PulseOximeter class
  45. Adafruit_SSD1306 display(128, 64, &Wire);  // Create an instance of the OLED display class
  46.  
  47. void setup(void)
  48. {
  49.     // put your setup code here, to run once:
  50.     pinMode(SENSOR_MAX30100_INT_PIN_D2, INPUT_PULLUP);
  51.  
  52.     Serial.begin(115200);
  53.  
  54.     // Initialize the PulseOximeter
  55.     if (!pox.begin()) {
  56.         Serial.println("FAILED: Unable to initialize the PulseOximeter");
  57.         for (;;);  // Halt the program
  58.     } else {
  59.         Serial.println("PulseOximeter initialized successfully");
  60.     }
  61.  
  62.     // Set the IR LED current
  63.     pox.setIRLedCurrent(MAX30100_LED_CURR_50MA);
  64.  
  65.     // Initialize the OLED display
  66.     if (!display.begin(SSD1306_I2C_ADDRESS, SENSOR_MAX30100_I2C_PIN_SDA_A4, SENSOR_MAX30100_I2C_PIN_SCL_A5)) {
  67.         Serial.println("SSD1306 allocation failed");
  68.         for (;;);  // Halt the program
  69.     }
  70.     display.display();
  71.     delay(2000);  // Pause for 2 seconds
  72.  
  73.     // Clear the buffer
  74.     display.clearDisplay();
  75.     display.setTextSize(1);
  76.     display.setTextColor(SSD1306_WHITE);
  77.     display.setCursor(0, 0);
  78.     display.print("PulseOximeter initialized");
  79.     display.display();
  80.     delay(2000);  // Pause for 2 seconds
  81. }
  82.  
  83. void loop(void)
  84. {
  85.     // put your main code here, to run repeatedly:
  86.     pox.update();
  87.  
  88.     // Get the heart rate and SpO2 values
  89.     float heartRate = pox.getHeartRate();
  90.     uint8_t spO2 = pox.getSpO2();
  91.  
  92.     // Print the heart rate and SpO2 values to the Serial Monitor
  93.     Serial.print("Heart rate: ");
  94.     Serial.print(heartRate);
  95.     Serial.print(" bpm / SpO2: ");
  96.     Serial.print(spO2);
  97.     Serial.println(" %");
  98.  
  99.     // Display the heart rate and SpO2 values on the OLED display
  100.     display.clearDisplay();
  101.     display.setCursor(0, 0);
  102.     display.print("Heart rate: ");
  103.     display.print(heartRate);
  104.     display.print(" bpm");
  105.     display.setCursor(0, 16);
  106.     display.print("SpO2: ");
  107.     display.print(spO2);
  108.     display.print(" %");
  109.     display.display();
  110.  
  111.     delay(1000);  // Wait for 1 second before the next update
  112. }
  113.  
  114. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement