Arduino to Excel with PLX-DAQ

Hi there,

Firstly I would like to mention that I am a very novice Arduino user! I have bought a Maxim30102 Pulse Oximetry Module (included in the MaxRefDes117 board)

I have hooked it up to arduino and it works fine in serial monitor.

However I would like to be able to record the results on excel and then plot them.
I have googled it a good bit but I am still having issues.
I have added the following to my void setup

Serial.begin(9600);
Serial.println("CLEARDATA"); 
Serial.println("LABEL,Time, Timer, Red, IR, HR, HRvalid, SPO2, SPO2 valid"); 
Serial.println("RESETTIMER"); //resets timer to 0
}

These columns do show up in the excel which I am happy that this part is correct.

I included the following in void setup

Serial.print("DATA,TIME,TIMER,"); /
Serial.print(aun_red_buffer[i], DEC);
Serial.print(aun_ir_buffer[i], DEC);
Serial.print(n_heart_rate, DEC);
Serial.print(ch_hr_valid, DEC);
Serial.print(n_spo2, DEC);
Serial.println(ch_spo2_valid, DEC); 
delay(1000);

When I click into PLX-DAQ with this I, the first time and timer cells are filled, the first "Red" cell is 0 and there is nothing else.

Any help would be greatly appreciated

Are you using an old copy of excel? I believe it only works with 2003 and below.

Your data values should be in the program loop and not in the set up as you stated, the data values should each be separated with a comma. Try the following in the main loop.

Serial.print("DATA,TIME,TIMER,"); 
Serial.print(aun_red_buffer[i], DEC);
Serial.print(",");
Serial.print(aun_ir_buffer[i], DEC);
Serial.print(",");
Serial.print(n_heart_rate, DEC);
Serial.print(",");
Serial.print(ch_hr_valid, DEC);
Serial.print(",");
Serial.print(n_spo2, DEC);
Serial.print(",");
Serial.println(ch_spo2_valid, DEC); 
delay(1000);

Thanks for your help guys, but still having a few issues

Sumguy, I edited the code as you suggested, now with PLX-DAQ I am getting 0 for all my cells in the first row (except time and timer) and it isn't starting into the second row for me?

I have included my full code here

*/
#include <Arduino.h>
#include "algorithm.h"
#include "max30102.h"

#define MAX_BRIGHTNESS 255

#if defined(ARDUINO_AVR_UNO)
//Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format
//To solve this problem, 16-bit MSB of the sampled data will be truncated.  Samples become 16-bit data.
uint16_t aun_ir_buffer[100]; //infrared LED sensor data
uint16_t aun_red_buffer[100];  //red LED sensor data
#else
uint32_t aun_ir_buffer[100]; //infrared LED sensor data
uint32_t aun_red_buffer[100];  //red LED sensor data
#endif
int32_t n_ir_buffer_length; //data length
int32_t n_spo2;  //SPO2 value
int8_t ch_spo2_valid;  //indicator to show if the SPO2 calculation is valid
int32_t n_heart_rate; //heart rate value
int8_t  ch_hr_valid;  //indicator to show if the heart rate calculation is valid
uint8_t uch_dummy;


// the setup routine runs once when you press reset:
void setup() {

  maxim_max30102_reset(); //resets the MAX30102
  // initialize serial communication at 115200 bits per second:
  Serial.begin(9600);
  pinMode(10, INPUT);  //pin D10 connects to the interrupt output pin of the MAX30102
  delay(1000);
  maxim_max30102_read_reg(REG_INTR_STATUS_1,&uch_dummy);  //Reads/clears the interrupt status register
  
  uch_dummy=Serial.read();
  maxim_max30102_init();  //initialize the MAX30102

  Serial.println("CLEARDATA"); //clears up any data left from previous projects
  Serial.println("LABEL,Time,Timer,Red,IR,HR,HRvalid,SPO2,SPvalid"); //always write LABEL, so excel knows the next things will be the names of the columns (instead of Acolumn you could write Time for instance)
  Serial.println("RESETTIMER"); //resets timer to 0
}


// the loop routine runs over and over again forever:
void loop() {
  uint32_t un_min, un_max, un_prev_data, un_brightness;  //variables to calculate the on-board LED brightness that reflects the heartbeats
  int32_t i;
  float f_temp;
  
  un_brightness=0;
  un_min=0x3FFFF;
  un_max=0;
  
  n_ir_buffer_length=100;  //buffer length of 100 stores 4 seconds of samples running at 25sps

Serial.print("DATA,TIME,TIMER,"); 
Serial.print(aun_red_buffer[i], DEC);
Serial.print(",");
Serial.print(aun_ir_buffer[i], DEC);
Serial.print(",");
Serial.print(n_heart_rate, DEC);
Serial.print(",");
Serial.print(ch_hr_valid, DEC);
Serial.print(",");
Serial.print(n_spo2, DEC);
Serial.print(",");
Serial.println(ch_spo2_valid, DEC); 
delay(1000);



  //read the first 100 samples, and determine the signal range
  for(i=0;i<n_ir_buffer_length;i++)
  {
    while(digitalRead(10)==1);  //wait until the interrupt pin asserts
    maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));  //read from MAX30102 FIFO
    
    if(un_min>aun_red_buffer[i])
      un_min=aun_red_buffer[i];  //update signal min
    if(un_max<aun_red_buffer[i])
      un_max=aun_red_buffer[i];  //update signal max
    Serial.print(F("red="));
    Serial.print(aun_red_buffer[i], DEC);
    Serial.print(F(", ir="));
    Serial.println(aun_ir_buffer[i], DEC);
  }
  un_prev_data=aun_red_buffer[i];
  //calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
  maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_spo2, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); 

  //Continuously taking samples from MAX30102.  Heart rate and SpO2 are calculated every 1 second
  while(1)
  {
    i=0;
    un_min=0x3FFFF;
    un_max=0;

    //dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
    for(i=25;i<100;i++)
    {
      aun_red_buffer[i-25]=aun_red_buffer[i];
      aun_ir_buffer[i-25]=aun_ir_buffer[i];

      //update the signal min and max
      if(un_min>aun_red_buffer[i])
        un_min=aun_red_buffer[i];
      if(un_max<aun_red_buffer[i])
        un_max=aun_red_buffer[i];
    }

    //take 25 sets of samples before calculating the heart rate.
    for(i=75;i<100;i++)
    {
      un_prev_data=aun_red_buffer[i-1];
      while(digitalRead(10)==1);
      digitalWrite(9, !digitalRead(9));
      maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));

      //calculate the brightness of the LED
      if(aun_red_buffer[i]>un_prev_data)
      {
        f_temp=aun_red_buffer[i]-un_prev_data;
        f_temp/=(un_max-un_min);
        f_temp*=MAX_BRIGHTNESS;
        f_temp=un_brightness-f_temp;
        if(f_temp<0)
          un_brightness=0;
        else
          un_brightness=(int)f_temp;
      }
      else
      {
        f_temp=un_prev_data-aun_red_buffer[i];
        f_temp/=(un_max-un_min);
        f_temp*=MAX_BRIGHTNESS;
        un_brightness+=(int)f_temp;
        if(un_brightness>MAX_BRIGHTNESS)
          un_brightness=MAX_BRIGHTNESS;
      }


      //send samples and calculation result to terminal program through UART
      Serial.print(F("red="));
      Serial.print(aun_red_buffer[i], DEC);
      Serial.print(F(", ir="));
      Serial.print(aun_ir_buffer[i], DEC);
      
      Serial.print(F(", HR="));
      Serial.print(n_heart_rate, DEC);
      
      Serial.print(F(", HRvalid="));
      Serial.print(ch_hr_valid, DEC);
      
      Serial.print(F(", SPO2="));
      Serial.print(n_spo2, DEC);

      Serial.print(F(", SPO2Valid="));
      Serial.println(ch_spo2_valid, DEC);
    }
    maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_spo2, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); 
  }
}

Any help would be much appreciated