General Arduino

SEN0344 Code Issue with Bluetooth

userHead ShashankS 2022-05-14 02:02:56 428 Views0 Replies

Hey, I'm trying to use the library and code along with the HC-05 bluetooth module. When I don't import the module I get the HR and SPO2 values.

As soon as I import the SoftwareSerial library, I don't get any output at all.

 

Here's the code: 

#include <DFRobot_MAX30102.h>

DFRobot_MAX30102 particleSensor;

#include <SoftwareSerial.h>

SoftwareSerial EEBlue(2,3);

 

/*Macro definition options in sensor configurationsampleAverage: SAMPLEAVG_1 SAMPLEAVG_2 SAMPLEAVG_4              SAMPLEAVG_8 SAMPLEAVG_16 SAMPLEAVG_32ledMode:       MODE_REDONLY  MODE_RED_IR  MODE_MULTILEDsampleRate:    PULSEWIDTH_69 PULSEWIDTH_118 PULSEWIDTH_215 PULSEWIDTH_411pulseWidth:    SAMPLERATE_50 SAMPLERATE_100 SAMPLERATE_200 SAMPLERATE_400              SAMPLERATE_800 SAMPLERATE_1000 SAMPLERATE_1600 SAMPLERATE_3200adcRange:      ADCRANGE_2048 ADCRANGE_4096 ADCRANGE_8192 ADCRANGE_16384*/void setup(){ //Init serial Serial.begin(115200); /*!  *@brief Init sensor   *@param pWire IIC bus pointer object and construction device, can both pass or not pass parameters (Wire in default)  *@param i2cAddr Chip IIC address (0x57 in default)  *@return true or false  */ while (!particleSensor.begin()) {   Serial.println("MAX30102 was not found");   delay(1000); }

 /*!  *@brief Use macro definition to configure sensor   *@param ledBrightness LED brightness, default value: 0x1F(6.4mA), Range: 0~255(0=Off, 255=50mA)  *@param sampleAverage Average multiple samples then draw once, reduce data throughput, default 4 samples average  *@param ledMode LED mode, default to use red light and IR at the same time   *@param sampleRate Sampling rate, default 400 samples every second   *@param pulseWidth Pulse width: the longer the pulse width, the wider the detection range. Default to be Max range  *@param adcRange ADC Measurement Range, default 4096 (nA), 15.63(pA) per LSB  */ particleSensor.sensorConfiguration(/*ledBrightness=*/90, /*sampleAverage=*/SAMPLEAVG_4, \                       /*ledMode=*/MODE_MULTILED, /sampleRate=/SAMPLERATE_100, \                       /*pulseWidth=*/PULSEWIDTH_411, /*adcRange=*/ADCRANGE_16384);}

int32_t SPO2; //SPO2int8_t SPO2Valid; //Flag to display if SPO2 calculation is validint32_t heartRate; //Heart-rateint8_t heartRateValid; //Flag to display if heart-rate calculation is valid

void loop(){ Serial.println(F("Wait about four seconds")); particleSensor.heartrateAndOxygenSaturation(/**SPO2=*/&SPO2, /**SPO2Valid=*/&SPO2Valid, /**heartRate=*/&heartRate, /**heartRateValid=*/&heartRateValid); //Print result  Serial.print(F("heartRate=")); Serial.print(heartRate, DEC); Serial.print(F(", heartRateValid=")); Serial.print(heartRateValid, DEC); Serial.print(F("; SPO2=")); Serial.print(SPO2, DEC); Serial.print(F(", SPO2Valid=")); Serial.println(SPO2Valid, DEC);

 

     String str = "HR=" + String(heartRate);     int str_len = str.length()+1;      char char_array[str_len];     str.toCharArray(char_array, str_len);     Serial.print(char_array[str_len-1]);     EEBlue.write(char_array,str_len);

}