Good afternoon all,
I am attempting to print the value for SPO2 calculated within a library onto my serial monitor however all that is being returned is 0. I am using the cooking hacks eHealth shield 2.0, eHealth library v2.4 and IDE v1.0.6; my code is:
//Include eHealth library
#include <eHealth.h>
#include <eHealthDisplay.h>
int SPO2 = eHealth.getOxygenSaturation();
void readPulsioximeter();
void setup() {
Serial.begin(9600);
eHealth.initPulsioximeter();
//Attach the inttruptions for using the pulsioximeter.
attachInterrupt(6, readPulsioximeter, RISING);
}
void loop() {
Serial.print("SPO2 :\t");
Serial.println(SPO2);
printf("PRbpm : %d",eHealth.getBPM());
printf(" %%SPo2 : %d\n", eHealth.getOxygenSaturation());
printf("=============================");
digitalWrite(2,HIGH);
delay(5000);
}
void readPulsioximeter(){
cont ++;
if (cont == 500) { //Get only of one 50 measures to reduce the latency
eHealth.readPulsioximeter();
cont = 0;
}
}
Within the eHealth.h file I discovered the oxygen saturation value (SPO2) is stored as:
//! Returns the oxygen saturation in blood in percent.
/*!
\param void
\return int : The oxygen saturation value. Normal values betwen 95-99%
*/ int getOxygenSaturation(void);
How could I print this value when the function is void and therefore should return no value?
Regards.
int getOxygenSaturation(void);
Do you mean this function? That function returns an int and the void means that it takes no (input)
parameters.
If it had no return value it would be
void getOxygenSaturation(void);
int getOxygenSaturation(void);
The void here means that the function does not take any arguments, not that it does not return a value. The int means that the function promises to return an int.
How could I print this value
Call the function and print the value returned.
I think you're calling the getOxygenSaturation() function in the wrong place.
Up at the top of the sketch (assuming you still want SPO2 to be global) you just need something like this:
int SPO2;
Then add this line at the beginning of loop().
SPO2 = eHealth.getOxygenSaturation();
Thank you for the clarification between, void function and function(void).
Taking GypsumFantastic's advice the amended code is now:
#include <eHealth.h>
#include <eHealthDisplay.h>
int SPO2;
int cont = 0;
void readPulsioximeter();
void setup() {
Serial.begin(9600);
eHealth.initPulsioximeter();
//Attach the inttruptions for using the pulsioximeter.
attachInterrupt(6, readPulsioximeter, RISING);
}
void loop() {
SPO2 = eHealth.getOxygenSaturation();
Serial.print("SPO2 :\t");
Serial.println(SPO2);
printf("PRbpm : %d",eHealth.getBPM());
printf(" %%SPo2 : %d\n", eHealth.getOxygenSaturation());
printf("=============================");
digitalWrite(2,HIGH);
delay(2000);
}
void readPulsioximeter(){
cont ++;
if (cont == 500) { //Get only of one 50 measures to reduce the latency
eHealth.readPulsioximeter();
cont = 0;
}
}
This unfortunately still returns zero, is it possible that I am somehow clearing the result, or worse yet the function itself is clearing the result before I pull it onto my sketch?
printf? What's that doing there?
printf has now been removed, came written in the code supplied by cooking hacks for the pulse oximeter.
OK, there's not much that can go wrong between reading the oximeter into the variable, then 2 lines later int he code, printing the variable out.
So now I think you need to troubleshoot your wiring connections.