#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int ecgPin = 4; // GPIO4 where the ECG signal is input
void setup() {
Serial.begin(115200);
pinMode(ecgPin, INPUT);
// Initialize the OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
}
void loop() {
// Array to hold ECG samples for displaying
int ecgValues[SCREEN_WIDTH];
// Read ECG signal from custom chip and store values
for (int i = 0; i < SCREEN_WIDTH; i++) {
int ecgSignal = analogRead(ecgPin); // Capture ECG signal from GPIO4
ecgValues[i] = map(ecgSignal, 0, 4095, 0, SCREEN_HEIGHT); // Scale to screen height
delay(10); // Small delay for smoother waveform (tune this based on your signal speed)
}
// Clear the display
display.clearDisplay();
// Draw ECG waveform
for (int i = 1; i < SCREEN_WIDTH; i++) {
display.drawLine(i - 1, ecgValues[i - 1], i, ecgValues[i], SSD1306_WHITE);
}
// Display BPM (Optional)
display.setCursor(0, 0);
display.print("ECG Signal");
// Update the display with new data
display.display();
delay(10); // Small delay before next loop
}
Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1