Heart sensor to Mariabd

Anyone knows how to connect my Arduino code to a Raspberry pi MySQL >

#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <MySQL_Encrypt_Sha1.h>
#include <MySQL_Packet.h>

#include <MySQL_Generic.h>
#include <MySQL_Generic.hpp>

#define USE_ARDUINO_INTERRUPTS true //--> Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> //--> Includes the PulseSensorPlayground Library. 
#include <LiquidCrystal.h> //--> Includes the LiquidCrystal Library.

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //--> Initialize LiquidCrystal with "lcd". lcd(RS,E,D4,D5,D6,D7).


const int PulseWire = A0; //--> PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED_3 = 13; //--> LED to detect when the heart is beating. The LED is connected to PIN 3 on the Arduino UNO.
int Threshold = 550; //--> Determine which Signal to "count as a beat" and which to ignore.
                    

//----------------------------------------Draw "Heart" on LCD.
/*
                     heart4 heart5
                       ===   ===
                             
              = 00011 11000 00011 11000 =                      11 11       11 11   
               00111 11100 00111 11100                      111 111     111 111  
               01111 11110 01111 11110                     1111 1111   1111 1111 
               11111 11111 11111 11111                    11111 11111 11111 11111
      heart3   11111 11111 11111 11111   heart6           11111 11111 11111 11111
               11111 11111 11111 11111                    11111 11111 11111 11111
               11111 11111 11111 11111                    11111 11111 11111 11111
              = 01111 11111 11111 11110 =                    1111 11111 11111 1111 
                                               ------->
              = 00011 11111 11111 11000 =                      11 11111 11111 11   
               00001 11111 11111 10000                        1 11111 11111 1    
               00000 11111 11111 00000                          11111 11111      
      heart2   00000 11111 11111 00000   heart7                 11111 11111      
               00000 01111 11110 00000                           1111 1111       
               00000 00111 11100 00000                            111 111        
               00000 00011 11000 00000                             11 11         
              = 00000 00001 10000 00000 =                             1 1           
                             
                       ===   ===
                     heart1 heart8

*/

byte heart1[8] = {B11111, B11111, B11111, B11111, B01111, B00111, B00011, B00001};
byte heart2[8] = {B00011, B00001, B00000, B00000, B00000, B00000, B00000, B00000};
byte heart3[8] = {B00011, B00111, B01111, B11111, B11111, B11111, B11111, B01111};
byte heart4[8] = {B11000, B11100, B11110, B11111, B11111, B11111, B11111, B11111};
byte heart5[8] = {B00011, B00111, B01111, B11111, B11111, B11111, B11111, B11111};
byte heart6[8] = {B11000, B11100, B11110, B11111, B11111, B11111, B11111, B11110};
byte heart7[8] = {B11000, B10000, B00000, B00000, B00000, B00000, B00000, B00000};
byte heart8[8] = {B11111, B11111, B11111, B11111, B11110, B11100, B11000, B10000};
//----------------------------------------

int Instructions_view = 500; //--> Variable for waiting time to display instructions on LCD.
                               
PulseSensorPlayground pulseSensor; //--> Creates an instance of the PulseSensorPlayground object called "pulseSensor"


void setup() {   
  Serial.begin(9600);//--> Set's up Serial Communication at certain speed.
  lcd.begin(16, 2); //--> Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
  
  
  lcd.createChar(1, heart1);
  lcd.createChar(2, heart2);
  lcd.createChar(3, heart3);
  lcd.createChar(4, heart4);
  lcd.createChar(5, heart5);
  lcd.createChar(6, heart6);
  lcd.createChar(7, heart7);
  lcd.createChar(8, heart8);
  
 
  
  lcd.setCursor(0,0);
  lcd.print("Heart Beat/Pulse"); 
  lcd.setCursor(0,1);
  lcd.print(" Monitoring EIF ");
  delay(2000);

 
  pulseSensor.analogInput(PulseWire);   
  pulseSensor.blinkOnPulse(LED_3); //--> auto-magically blink Arduino's LED with heartbeat.
  pulseSensor.setThreshold(Threshold);   
 

 
  if (pulseSensor.begin()) {
    Serial.println("We created a pulseSensor Object !"); //--> This prints one time at Arduino power-up,  or on Arduino reset.  
  }
  

  delay(2000);
  lcd.clear();
}



void loop() {
  int myBPM = pulseSensor.getBeatsPerMinute(); //--> Calls function on our pulseSensor object that returns BPM as an "int". "myBPM" hold this BPM value now.

 
  if (Instructions_view < 500) {
    Instructions_view++;
  }
  
  if (Instructions_view > 499) {
    lcd.setCursor(0,0);
    lcd.print("Put your finger ");
    lcd.setCursor(0,1);
    lcd.print(" on the sensor."); 
    delay(3000);
    lcd.clear();
    delay(500);
  }

 
  if (pulseSensor.sawStartOfBeat()) { //--> If test is "true", then the following conditions will be executed.
    Serial.println("  A HeartBeat Detected ! "); //--> Print a message "a heartbeat Detected".
    Serial.print("BPM: "); //--> Print phrase "BPM: " 
    Serial.println(myBPM); //--> Print the value inside of myBPM. 

   

    lcd.setCursor(1,1);
    lcd.write(byte(1));
    lcd.setCursor(0,1);
    lcd.write(byte(2));
    lcd.setCursor(0,0);
    lcd.write(byte(3));
    lcd.setCursor(1,0);
    lcd.write(byte(4));
    lcd.setCursor(2,0);
    lcd.write(byte(5));
    lcd.setCursor(3,0);
    lcd.write(byte(6));
    lcd.setCursor(3,1);
    lcd.write(byte(7));
    lcd.setCursor(2,1);
    lcd.write(byte(8));
 

   
    lcd.setCursor(5,0);
    lcd.print("Heart Rate");
    lcd.setCursor(5,1);
    lcd.print(": ");
    lcd.print(myBPM);
    lcd.print(" ");
    lcd.print("BPM     ");
  
    
    Instructions_view = 0; 
  }
 
  
  delay(20);// End of code
}

The last time I did such a thing I put a Python program in the middle. The Arduino sent data over the serial port to the Python program which then performed INSERTs to the database. That worked well. Each thing could be built up in isolation then connected together to form the final solution.

I haven't been able to test my code but this is my same code.

`#define USE_ARDUINO_INTERRUPTS true //--> Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> //--> Includes the PulseSensorPlayground Library. 
#include <LiquidCrystal.h> //--> Includes the LiquidCrystal Library.

#include <Ethernet.h>
#include <MySQL_Connection.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(10,0,1,35);  // IP of the MySQL *server* here
char user[] = "root";              // MySQL user login username
char password[] = "secret";        // MySQL user login password
char default_db = "test_arduino";

EthernetClient client;
MySQL_Connection conn((Client *)&client);

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //--> Initialize LiquidCrystal with "lcd". lcd(RS,E,D4,D5,D6,D7).


const int PulseWire = A0; //--> PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED_3 = 13; //--> LED to detect when the heart is beating. The LED is connected to PIN 3 on the Arduino UNO.
int Threshold = 550; //--> Determine which Signal to "count as a beat" and which to ignore.
                    

//----------------------------------------Draw "Heart" on LCD.
/*
                     heart4 heart5
                       ===   ===
                             
              = 00011 11000 00011 11000 =                      11 11       11 11   
               00111 11100 00111 11100                      111 111     111 111  
               01111 11110 01111 11110                     1111 1111   1111 1111 
               11111 11111 11111 11111                    11111 11111 11111 11111
      heart3   11111 11111 11111 11111   heart6           11111 11111 11111 11111
               11111 11111 11111 11111                    11111 11111 11111 11111
               11111 11111 11111 11111                    11111 11111 11111 11111
              = 01111 11111 11111 11110 =                    1111 11111 11111 1111 
                                               ------->
              = 00011 11111 11111 11000 =                      11 11111 11111 11   
               00001 11111 11111 10000                        1 11111 11111 1    
               00000 11111 11111 00000                          11111 11111      
      heart2   00000 11111 11111 00000   heart7                 11111 11111      
               00000 01111 11110 00000                           1111 1111       
               00000 00111 11100 00000                            111 111        
               00000 00011 11000 00000                             11 11         
              = 00000 00001 10000 00000 =                             1 1           
                             
                       ===   ===
                     heart1 heart8

*/

byte heart1[8] = {B11111, B11111, B11111, B11111, B01111, B00111, B00011, B00001};
byte heart2[8] = {B00011, B00001, B00000, B00000, B00000, B00000, B00000, B00000};
byte heart3[8] = {B00011, B00111, B01111, B11111, B11111, B11111, B11111, B01111};
byte heart4[8] = {B11000, B11100, B11110, B11111, B11111, B11111, B11111, B11111};
byte heart5[8] = {B00011, B00111, B01111, B11111, B11111, B11111, B11111, B11111};
byte heart6[8] = {B11000, B11100, B11110, B11111, B11111, B11111, B11111, B11110};
byte heart7[8] = {B11000, B10000, B00000, B00000, B00000, B00000, B00000, B00000};
byte heart8[8] = {B11111, B11111, B11111, B11111, B11110, B11100, B11000, B10000};
//----------------------------------------

int Instructions_view = 500; //--> Variable for waiting time to display instructions on LCD.
                               
PulseSensorPlayground pulseSensor; //--> Creates an instance of the PulseSensorPlayground object called

void setup() {
  Serial.begin(115200);
  while (!Serial); // wait for serial port to connect
  Ethernet.begin(mac_addr);
  Serial.println("Connecting...");
  if (conn.connect(server_addr, 3306, user, password, default_db)) {
    delay(1000);
    // You would add your code here to run a query once on startup.
    Serial.begin(9600);//--> Set's up Serial Communication at certain speed.
  lcd.begin(16, 2); //--> Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
  
  
  lcd.createChar(1, heart1);
  lcd.createChar(2, heart2);
  lcd.createChar(3, heart3);
  lcd.createChar(4, heart4);
  lcd.createChar(5, heart5);
  lcd.createChar(6, heart6);
  lcd.createChar(7, heart7);
  lcd.createChar(8, heart8);
  
 
  
  lcd.setCursor(0,0);
  lcd.print("Heart Beat/Pulse"); 
  lcd.setCursor(0,1);
  lcd.print(" Monitoring EIF ");
  delay(2000);

 
  pulseSensor.analogInput(PulseWire);   
  pulseSensor.blinkOnPulse(LED_3); //--> auto-magically blink Arduino's LED with heartbeat.
  pulseSensor.setThreshold(Threshold);   
 

 
  if (pulseSensor.begin()) {
    Serial.println("We created a pulseSensor Object !"); //--> This prints one time at Arduino power-up,  or on Arduino reset.  
  }
  

  delay(2000);
  lcd.clear();
}

  
  else
    Serial.println("Connection failed.");
  conn.close();
}


void loop() 
{
  int myBPM = pulseSensor.getBeatsPerMinute(); //--> Calls function on our pulseSensor object that returns BPM as an "int". "myBPM" hold this BPM value now.

 
  if (Instructions_view < 500) {
    Instructions_view++;
  }
  
  if (Instructions_view > 499) {
    lcd.setCursor(0,0);
    lcd.print("Put your finger ");
    lcd.setCursor(0,1);
    lcd.print(" on the sensor."); 
    delay(3000);
    lcd.clear();
    delay(500);
  }

 
  if (pulseSensor.sawStartOfBeat()) { //--> If test is "true", then the following conditions will be executed.
    Serial.println("  A HeartBeat Detected ! "); //--> Print a message "a heartbeat Detected".
    Serial.print("BPM: "); //--> Print phrase "BPM: " 
    Serial.println(myBPM); //--> Print the value inside of myBPM. 

   

    lcd.setCursor(1,1);
    lcd.write(byte(1));
    lcd.setCursor(0,1);
    lcd.write(byte(2));
    lcd.setCursor(0,0);
    lcd.write(byte(3));
    lcd.setCursor(1,0);
    lcd.write(byte(4));
    lcd.setCursor(2,0);
    lcd.write(byte(5));
    lcd.setCursor(3,0);
    lcd.write(byte(6));
    lcd.setCursor(3,1);
    lcd.write(byte(7));
    lcd.setCursor(2,1);
    lcd.write(byte(8));
 

   
    lcd.setCursor(5,0);
    lcd.print("Heart Rate");
    lcd.setCursor(5,1);
    lcd.print(": ");
    lcd.print(myBPM);
    lcd.print(" ");
    lcd.print("BPM     ");
  
    
    Instructions_view = 0; 
  }
 
  
  delay(20);// End of code
}
`

tested my code and it get "error class required connected server"

Post the full error (using code tags).

And just FYI, if you are the slightest concerned about security, do not use the MySQL root user when accessing your database.

I have 13 ESP32's sending their data to a MQTT Broker loaded up on the RPi. A Python program, Node-Red can be used, sends the data to a dB.

Hi,
not sure if resolved, but me 2 cents with an observation.....
I see commas within server IP address and not periods, not sure if intentional.