Hello Everyone,
I am making a sleep monitoring IoT system for which I am using a microphone amplifier, accelerometer and a Pulse Oximeter. All the sensors work properly after I tested them individually but when I combine all the sensors together, I am only managing to get the readings of the accelerometer and the microphone amplifier, the pulse oximeter is not producing any readings.
Pasting the code below:-
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 1000
PulseOximeter pox;
uint32_t tsLastReport = 0;
int ADXL345 = 0x53;
int X_out, Y_out, Z_out;
const int sampleWindow = 50;
unsigned int sample;
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(9600);
Serial.print("Initializing pulse oximeter..");
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
Wire.begin();
Wire.beginTransmission(ADXL345);
Wire.write(0x2D);
Wire.write(8);
Wire.endTransmission();
delay(10);
}
void loop()
{
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
tsLastReport = millis();
}
Wire.beginTransmission(ADXL345);
Wire.write(0x32);
Wire.endTransmission(false);
Wire.requestFrom(ADXL345, 6, true);
X_out = ( Wire.read() | Wire.read() << 8);
Y_out = ( Wire.read() | Wire.read() << 8);
Z_out = ( Wire.read() | Wire.read() << 8);
Serial.print(X_out);
Serial.print(" ");
Serial.print(Y_out);
Serial.print(" ");
Serial.println(Z_out);
delay(100);
unsigned long startMillis= millis();
unsigned int peakToPeak = 0;
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(A0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // To find the max sample
}
else if (sample < signalMin)
{
signalMin = sample; // To find the min sample
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 5.0) / 1024; // convert to volts
Serial.print("loudness : ");
Serial.println(volts);
delay(1000);
}
I haven't used arduino before so I am a complete newbie, so any help provided by you'll would be of great help to me.
Thanks
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 1000
PulseOximeter pox;
uint32_t tsLastReport = 0;
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(9600);
Serial.print("Initializing pulse oximeter..");
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop()
{
// Make sure to call update as fast as possible
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
tsLastReport = millis();
}
}
This is the pulse oximeter code i used. MAX30100 works properly here but as soon as the program gets longer it doesn't seem to work.
You may be right about it needing to update itself faster. Do you have any idea on how I should go about this?
from spamming you serial output with a crap-ton of printing.
Wrap those lines in a similar mechanism to make the print only as often as you need or want… then your loop will run at top speed, and all the actions will be governed by the millis()/"lastTime" logic.
Look at the code fragment I put up top here in this post, study it to see how it works.
It is a straight ahead technigue widely used, well worth getting your head around.
Bark if you need help, but it should be within you grasp.