oxullo / Arduino-MAX30100

Arduino library for MAX30100, integrated oximeter and heart rate sensor
GNU General Public License v3.0
190 stars 134 forks source link

dont work max30100 with thingspeak iot #52

Closed ahmedsahlani closed 5 years ago

ahmedsahlani commented 6 years ago

I am trying to use the MAX30100_Minimal code and add to it to connect to ThingSpeak, an IoT platform. I added the same lines of code that I have used for previous i2c sensors to send data to Thingspeak, but for some reason when I add them to the MAX30100 code the serial monitor begins displaying values of 0 for beats for minute and SpO2 percentage. The temperature continues to read correctly, so I do not know what the problem is?

the code is

include

include

include

include "MAX30100_PulseOximeter.h"

PulseOximeter pox;

// Wi-Fi Settings const char ssid = "F7"; // your wireless network name (SSID) const char password = "ab "; // your Wi-Fi network password

WiFiClient client;

// ThingSpeak Settings const int channelID = ; String writeAPIKey = "I"; // write API key for your ThingSpeak Channel const char* server = "api.thingspeak.com";

void setup() { pox.begin(); Serial.begin(115200); WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) { delay(500); } }

void loop() { if (client.connect(server, 80)) {

pox.update();

// Construct API request body
String body = "field1=";
       body += String(pox.getHeartRate());

Serial.print("heartrate");
Serial.println(pox.getHeartRate()); 

client.println("POST /update HTTP/1.1");
client.println("Host: api.thingspeak.com");
client.println("User-Agent: ESP8266 (nothans)/1.0");
client.println("Connection: close");
client.println("X-THINGSPEAKAPIKEY: " + writeAPIKey);
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: " + String(body.length()));
client.println("");
client.print(body);

} client.stop();

// wait and then post again delay(10); }

izabellelima commented 6 years ago

Hello, I have this same problem, did you get an answer about this topic?

Marinamyat24 commented 6 years ago

I also have the same problem and I am now adjusting the delay between max30100 and thingspeak. If you get some good news, I would love to hear that.

oxullo commented 5 years ago

This issue is similar to #49 and unfortunately has no simple solution. With version 1.2.0 this behavior should had been mitigated, but you must ensure that you're calling MAX30100.update() (or the higher level PulseOximeter::update()) "fast" enough in order to read the samples produced in the FIFO. If other libraries are blocking for longer than 16*sampling period (being 16 the number of samples the FIFO can store) then you must either fix the blocking libraries or reduce the sampling frequency of the pulse oximeter. Note that the higher level interface is calibrated for 100Hz sampling frequency, which means that changing it might impact in the overall reading performances.

PraisySam commented 3 years ago

Hello, I have this same problem with ESP8622, did you get correct reading? Please share code

safekeeper-developer commented 2 years ago

Hello, is MAX30100 will work at ThingSpeak? Thank you!

Praadnya commented 1 year ago

I am having the same problem. I'm using MAX30100,MLX90614,DHT11 sensors. The setonbeatdetected callback function does not get called. On the serial monitor the values of bpm and spo2 are always 0 only if the data is being sent to the thingspeak database. Individually it gives readings.

Praadnya commented 1 year ago

include

include

include "DHT.h"

include "MAX30100_PulseOximeter.h"

include "Adafruit_MLX90614.h"

include "secrets.h"

include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros

define SECRET_SSID "XXXXX"

define SECRET_PASS "XXXX"

define SECRET_CH_ID XXXX

define SECRET_WRITE_APIKEY "XXXX"

define DHT11PIN 16

char ssid[] = SECRET_SSID; // your network SSID (name) char pass[] = SECRET_PASS; // your network password int keyIndex = 0; // your network key Index number (needed only for WEP) WiFiClient client;

unsigned long myChannelNumber = SECRET_CH_ID; const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

// Initialize our values PulseOximeter pox; Adafruit_MLX90614 mlx = Adafruit_MLX90614(); DHT dht(DHT11PIN, DHT11);

void onBeatDetected() { Serial.println("Beat!"); }

void setup() { Serial.begin(9600); //Initialize serial while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo native USB port only } // if (!pox.begin()) // { // Serial.println("FAILED"); // for(;;); // } // else // { // Serial.println("SUCCESS"); // pox.setOnBeatDetectedCallback(onBeatDetected); // } dht.begin(); mlx.begin(); pinMode(19,OUTPUT);

WiFi.mode(WIFI_STA);
ThingSpeak.begin(client); // Initialize ThingSpeak

pox.setOnBeatDetectedCallback(onBeatDetected);

pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA); }

void loop() {

// Connect or reconnect to WiFi if(WiFi.status() != WL_CONNECTED){ Serial.print("Attempting to connect to SSID: "); Serial.println(SECRET_SSID); while(WiFi.status() != WL_CONNECTED){ WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network Serial.print("."); delay(5000);
} Serial.println("\nConnected."); } pox.setOnBeatDetectedCallback(onBeatDetected); pox.update(); // MAX30100 float bpm = pox.getHeartRate(); float spo2 = pox.getSpO2();

// MLX90614 float btemp = mlx.readObjectTempF();

// DHT11 float humi = dht.readHumidity(); float temp = dht.readTemperature();

Serial.print("Heart rate: "); Serial.print(bpm); Serial.println(" bpm"); Serial.print("SpO2: "); Serial.print(spo2); Serial.println(" %");

Serial.print("Body Temperature: "); Serial.print(btemp); Serial.println(" F");

Serial.print("Humidity: "); Serial.print(humi); Serial.println(" %"); Serial.print("Temperature: "); Serial.print(temp); Serial.println(" C");

// set the fields with the values ThingSpeak.setField(1, bpm); ThingSpeak.setField(2, spo2); ThingSpeak.setField(3, btemp); ThingSpeak.setField(4, humi); ThingSpeak.setField(5, temp);

// write to the ThingSpeak channel int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); if(x == 200){ Serial.println("Channel update successful."); } else{ Serial.println("Problem updating channel. HTTP error code " + String(x)); }

// change the values // pox.update();

delay(20000); // Wait 20 seconds to update the channel again }

This is my code for the above mentioned problem

Ramshask commented 1 year ago

Facing the same problem with Max30100 any solutions??

ElvisAns commented 11 months ago

Facing the same issue on ESP8266

Ramshask commented 11 months ago

Facing the same issue on ESP8266

Try to power the max sensor from some other source and not from the esp, Check if your max sensor is working properly individually.

ElvisAns commented 11 months ago

Thanks @Ramshask , by the way i just came to a conclusion that the sensor itself have several issue. I finally got it working by completely remove the sensor from the fingertip i designed then i just observed i am getting random values (Real heartbeat cant fluctuate like that; in one sec it jump from 20BPM to 111BPM for example). Also i have observed that sometimes i am putting my finger straight on top of the sensor and i get nada then i move the finger in some random position i get a value, but i am sure they really random values... I am wondering if Is there any stable sensor that i can use for production? Like in hospital environment?

Ramshask commented 11 months ago

Yes i guess as its an optical sensor it has some issues with where you are placing your finger. I tried using the gy - max 30100 it was much better for my application. (https://www.flyrobo.in/gy-max30102-pulse-oximeter-heart-rate-sensor-development-board)

ElvisAns commented 11 months ago

Yes i guess as its an optical sensor it has some issues with where you are placing your finger. I tried using the gy - max 30100 it was much better for my application. (https://www.flyrobo.in/gy-max30102-pulse-oximeter-heart-rate-sensor-development-board)

Thank you, i will look into that