Transmit Data to nRFConnect or Similar App


#1

Hello All,

   I have been using the Blend Micro and am obtaining data from a Pulse Sensor.

I am looking to show that data in real time on my iPhone. Eventually, I would like to plot the data, but would be happy with displaying the values to a serial monitor.

I do not know how to transmit the data and unsure of my BLE implementation is correct.

Can the community give me some pointers?

Thank you in advance.

Code is as follows:

#include <RBL_nRF8001.h>
#include <RBL_services.h>

#include <SPI.h>
#include <EEPROM.h>
#include <boards.h>

/*  Pulse Sensor Wrist Band

----------------------  Notes ----------------------  ---------------------- 
This code:
1) Blinks an LED to User's Live Heartbeat 
2) Fades an LED to User's Live HeartBeat
3) Determines BPM
4) Prints All of the Above to Serial
5) Turns on a Red or Green LED to indicate range of heart beat

Wants:
1) To output the serial monitor to a RPi and plot using Python
2) Output via bluetooth and print to cellphone via Android app

 ----------------------       ----------------------  ----------------------
*/

//  Variables
int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 12;                // pin to blink led at each beat
int fadePin = 10;                  // pin to do fancy classy fading blink at each beat
int fadeRate = 5;                 // used to fade LED on with PWM on fadePin

int redLEDPin = 9;               // used to turn on the Red LED
int greenLEDPin = 13;              // used to turn on the Green LED

unsigned char buf[16] = {0};
unsigned char len = 0;

// Volatile Variables, used in the interrupt service routine!
volatile int BPM;                   // int that holds raw Analog in 0. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded! 
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat". 
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.

// Regards Serial OutPut  -- Set This Up to your needs
static boolean serialVisual = false;   // Set to 'false' by Default.  Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse 


void setup(){

  ble_begin();

  pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!
  pinMode(fadePin,OUTPUT);          // pin that will fade to your heartbeat!

  pinMode(redLEDPin, OUTPUT);       // pin to be used to set the off indicator when HR is above a certain level
  pinMode(greenLEDPin, OUTPUT);      // pin to be used to set the on indicator when HR is below a certain level
  
  Serial.begin(115200);             // we agree to talk fast!
  delay(500);
  interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS 
  
   // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE, 
   // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
//   analogReference(EXTERNAL);   


}




//  Where the Magic Happens
void loop(){
  
    serialOutput();       
    
  if (QS == true){     // A Heartbeat Was Found
                       // BPM and IBI have been Determined
                       // Quantified Self "QS" true when arduino finds a heartbeat
        fadeRate = 255;         // Makes the LED Fade Effect Happen
                                // Set 'fadeRate' Variable to 255 to fade LED with pulse
        serialOutputWhenBeatHappens();   // A Beat Happened, Output that to serial.     
        QS = false;                      // reset the Quantified Self flag for next time    
  }
     
  ledFadeToBeat();                      // Makes the LED Fade Effect Happen 
  delay(40);                             //  take a break


  if (BPM >= 80){

      digitalWrite(redLEDPin, HIGH);
}
  else {

      digitalWrite(redLEDPin, LOW);

}

  if (BPM <= 72){

      digitalWrite(greenLEDPin, HIGH);
}

 else{

      digitalWrite(greenLEDPin, LOW);
   
 }

 Serial.print(BPM);
 Serial.print(",");
 //delay(500);

 if ( ble_connected() )
  {
    ble_write(BPM);
  }

 ble_do_events();


}







void ledFadeToBeat(){
    fadeRate -= 25;                          //  set LED fade value. 15 was used before, changes for more graduations
    fadeRate = constrain(fadeRate,0,255);   //  keep LED fade value from going into negative numbers!
    analogWrite(fadePin,fadeRate);          //  fade LED
  }

#2

Hi @jameshayek:

What kind of the Pulse Sensor you have ?Do you have datasheet or reference? It should have the formula to calculate the Pulse . In other hand ,I think it should have serial Apps which can display the data as plot since I’ve used one but it’s Chinese .


#3

Jackson, thank you for taking time to respond! @jackson

I got the pulse sensor from http://pulsesensor.com/

I used the Hello World example and tried to implement the transmition of data to the BLEController app for iPhone. As of right now, I am getting special characters and not the two or three digit integers the Micro is outputting to the serial monitor.

The code I have used is as follows:

  ble_begin();

if ( ble_connected() )
  {
    ble_write(BPM);
  }

 ble_do_events();


}

#4

@jameshayek: please try to put
if ( ble_connected() )
{
ble_write(BPM);
}
ble_do_events();
into loop function


SimpleChat Duo BLE Write in Particle IDE
#5

@jackson It is, it is in the void loop function.

When checking the values on the BLE app for iPhone, I see charachters such as H and other non numberic numbers.

I am not sure why actual interger values aren’t being sent.