Hi there.
I am new in programming, I need some help for you guys.
My project is actually a heart rate device that will transfer data to monitor display in a car.
So, I got the coding from internet resources and some from the examples coding in Arduino software.
For a project I'm working on, I need to send data from one Arduino to another using HC-05 bluetooth modules. Here is what I'm trying to accomplish:
Arduino 1 -> Bluetooth 1 -> (wirelessly) Bluetooth 2 -> Arduino 2
So the first thing I did was configure one module as a master and one as a slave and then paired them
Here is my code that transmits data from Arduino 1, the master arduino:
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <U8g2lib.h>
#include <SoftwareSerial.h>
SoftwareSerial HC05 (10,11);
#define REPORTING_PERIOD_MS 10000
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
PulseOximeter pox;
int state = 0;
int temppin = A1; //<---------This is the PIN the LM53 (Temperature Sensor)
float temp = 0;
int Buzz = A2; //<---------This is the PIN for (HYDZ BUZZER)
uint32_t tsLastReport = 0;
void onBeatDetected()
{
u8g2.println("Beat!");
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
HC05.begin(9600);
u8g2.begin();
Serial.print("Initializing pulse oximeter..");
pinMode(Buzz, OUTPUT);
digitalWrite (Buzz, LOW); //(No sound at starting)
if(!pox.begin()) {
u8g2.println("FAILED");
Serial.println("FAILED");
for (;;);
} else {
u8g2.println("SUCCESS");
Serial.println("SUCCESS");
}
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop()
{
temp = analogRead(temppin);
temp = temp * 0.43528125;
pox.update();
if(HC05.available() > 0)
{
state = HC05.read(); // Reads the data from the serial port
u8g2.write(state);
Serial.println(state);
}
if (millis() - tsLastReport > REPORTING_PERIOD_MS)
{
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
Serial.print("TEMPERATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_helvB08_tr);
u8g2.setCursor(2, 8);
u8g2.print("Heart rate:");
u8g2.setCursor(64, 8);
u8g2.print(pox.getHeartRate());
u8g2.print(" Bpm");
u8g2.setCursor(2,19);
u8g2.print("SpO2: ");
u8g2.setCursor(64,19);
u8g2.print(pox.getSpO2());
u8g2.print("%");
u8g2.setCursor(2, 30);
u8g2.print("Temp:");
u8g2.setCursor(64, 30);
u8g2.print(temp);
u8g2.print("C");
u8g2.println();
u8g2.sendBuffer();
HC05.print(pox.getHeartRate());
HC05.print("x");
HC05.print(pox.getSpO2());
HC05.print("x");
HC05.print(temp);
tsLastReport = millis();
if ( temp > 50 || ((pox.getSpO2() < 94) && !((pox.getSpO2() < 25))) || (pox.getHeartRate() > 100) || ((pox.getHeartRate() < 50) && !((pox.getHeartRate() < 39))) )
{
digitalWrite(Buzz, HIGH); // Sound ON
}
else
{
digitalWrite (Buzz, LOW); // NO Sound
}
}
}
Here is the code I have on the slave Arduino:
#include "MAX30100_PulseOximeter.h"
#include <SoftwareSerial.h>
SoftwareSerial HC05 (10,11);
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
PulseOximeter pox;
int state = 0;
float temp = 0;
int Buzz = A2;
uint32_t tsLastReport = 0;
void setup(void) {
Serial.begin(9600);
HC05.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is ");
Serial.print(tft.width());
Serial.print("x");
Serial.println(tft.height());
tft.reset();
delay(500);
uint16_t identifier = tft.readID();
identifier=0x9341;
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
//return;
}
tft.begin(0x8357);
tft.setRotation(3);
tft.fillScreen(BLACK);
tft.setCursor(0, 30);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println("Heart Beat");
tft.setCursor(0, 70);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println("Rate :");
tft.setCursor(210, 70);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println("bpm");
tft.setCursor(0, 130);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println("SPO2 :");
tft.setCursor(180, 130);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.println("%");
tft.setCursor(0, 180);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.print("Temp :");
tft.setCursor(210, 180);
tft.setTextColor(RED);
tft.setTextSize(3);
tft.print("C");
}//void setup
void loop(void) {
if(HC05.available()){
state = HC05.read();
tft.write(state);
Serial.println(state);
}
tft.setRotation(3);
testText();
Serial.println();
delay(1000);
}
unsigned long testText() {
tft.setCursor(130, 70);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println(pox.getHeartRate());
tft.setCursor(130, 130);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println(pox.getSpO2());
tft.setCursor(130, 180);
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println(temp);
}
However it doesn't work. The slave Arduino doesn't receive anything.
I hope you guys can understand what I am trying to explain.
I'd really appreciate some help.