Recording BPM into an Adafruit TFT ST7735 1.8 Display

Hi! I am working on a school project using a Pulse Sensor from pulsesensor.com and Adafruit TFT ST7735 1.8 LCD Display. The code works fine, but it only records my BPM when I perform a tapping movement, which gives an inaccurate BPM. I want this Pulse Sensor to record my BPM continuously as I hold it down instead of tapping it continuously. Is there anything that needs to change or add to this code? Thanks in advance!

Here's the code:

#include <Adafruit_GFX.h>  
#include <Adafruit_ST7735.h>  
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>

#define TFT_CS     10
#define TFT_RST    9
#define TFT_DC     8

const int PulseWire = 0;
const int LED13 = 13;
int Threshold = 550;

// Create display:
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
PulseSensorPlayground pulseSensor;


// Add a custom font
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSerifItalic9pt7b.h>
#include <Fonts/FreeMono9pt7b.h>


void setup() {
  Serial.begin(9600);

  pulseSensor.analogInput(PulseWire);
  pulseSensor.blinkOnPulse(LED13);
  pulseSensor.setThreshold(Threshold);

  if (pulseSensor.begin()) {
    Serial.println("Measuring your pulse....");
  }
  tft.initR(INITR_BLACKTAB);
  uint16_t time = millis();
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;
  Serial.println(time, DEC);
  delay(500);

  tft.fillScreen(ST7735_BLACK);  
  tft.setTextWrap(false);  
  tft.setRotation(3);
  tft.setCursor(25, 5);  
  tft.setTextColor(ST7735_WHITE);  
  tft.setTextSize(1);  
  tft.println("HELLO! WELCOME TO");  
  tft.setCursor(30, 15);  
  tft.setTextColor(ST7735_WHITE); 
  tft.setTextSize(1);  
  tft.println("SYIRAH'S CLINIC!");  
  tft.drawRect(20, 0, 115, 30, ST7735_WHITE);

  tft.setFont(&FreeSansBold9pt7b);  
  tft.setTextSize(0);  
  tft.setCursor(10, 55);
  tft.setTextColor(ST7735_BLUE);
  tft.println("Collecting data...");
  tft.setTextWrap(true);
  tft.setCursor(20, 95);
  tft.setTextColor(ST7735_YELLOW);
  tft.println("Please wait...");
  delay(3200);

  tft.setTextWrap(false);
  tft.setCursor (0, 0);
  tft.initR(INITR_BLACKTAB);
  tft.fillScreen(ST77XX_BLACK);
  tft.setRotation(3);
  tft.setFont(&FreeSansBold9pt7b);
  tft.setTextSize(0);
  tft.fillRect(0, 0, 70, 70, ST7735_RED);

  tft.setCursor(5, 40);
  tft.setTextColor(ST77XX_WHITE);
  tft.println("PULSE:");
  tft.setFont();

  tft.fillRect(0, 70, 70, 60, 0x237B);
  tft.setFont(&FreeSansBold9pt7b);
  tft.setTextSize(0);
  tft.setCursor(5, 105);
  tft.setTextColor(ST77XX_WHITE);
  tft.println("TEMP:");
  tft.drawLine(0, 70, 180, 70, ST7735_WHITE);
  tft.setFont();

}  // End of setup

void loop() {
  int myBPM = pulseSensor.getBeatsPerMinute();
  if (pulseSensor.sawStartOfBeat()) {            
    Serial.println("Heartbeat Detected "); 
    Serial.print("BPM: ");                       
    Serial.println(myBPM);
  }
  delay(20);

 
  tft.setCursor(83, 33);  
  tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
  tft.setTextSize(2);  
  tft.println(myBPM);  
  tft.setCursor(123, 33);  
  tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  
  tft.setTextSize(2);  
  tft.println("BPM");

}

Please provide details of the hardware that you are using. For instance, which pulse sensor device are you using ?

Hardware im using:

  • Arduino Uno
    -1.8 " Color TFT LCD Display with MicroSD Card Breakout ST7735
    -Pulse Sensor Amped (ID:1093)

My first piece of advice would be to take out all of the TFT related code and simply print to the Serial monitor in the first instance. The code will be smaller and easier to read and understand

Does the library come with any examples ?

okay, will try it out! Thank you! and yes the library comes with examples.