Arduino to thingspeak , Stops reading Values

15 views (last 30 days)
Hello fellow programmers ,
I am trying to upload the findings of my max30100 sensor to thingspeak.
While i have a working example who is not connected on thingspeak , when i try and connect it to thing speak i get 0 readings for both Bpm and Spo2 .
My code is here and i believe it has to do something with me trying to pass a float value to thingspeak,
/*
Arduino-MAX30100 oximetry / heart rate integrated sensor library
Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Wire.h>
#include "ThingSpeak.h"
#include "MAX30100_PulseOximeter.h"
#include <WiFiNINA.h> /* wifi libaries to connect our device with BLYNK */
#include <BlynkSimpleWiFiNINA.h> /* libaries to connect our device with BLYNK */
#define BLYNK_PRINT Serial
#define REPORTING_PERIOD_MS 1000
#define BLYNK_MAX_SENDBYTES 256 // Default is 128
// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
PulseOximeter pox;
BlynkTimer timer;
WiFiClient client;
float spo2 = pox.getSpO2();
unsigned long myChannelNumber = ;
const char * myWriteAPIKey = "";
char auth[] = "";
// DONT STEAL THEM PLEASE
// xD
char ssid[] = "";
char pass[] = "";
uint32_t tsLastReport = 0;
//simple and smart function to ignore first readings which are false and then check if Heart rate or Spo2 levels are abnormal , we ll call it outside of the loop because the IoT server gonna get overflooded with DATA , so we ll call with interval Time
void sendMsg()
{
float h = pox.getHeartRate();
float o = pox.getSpO2();
if ( h >= 140)
{
Blynk.notify("Your BpM is Quite High,I am Sending Data To you Doctor ");
}
else if ( o<90 & o>80)
{
Blynk.notify("Your Spo2 is Quite Low,I am Sending Data To your Doctor ");
}
else if (h < 40)
{
Blynk.notify("Your BpM is Quite Low,I am Sending Data To you Doctor ");
}
else if (h==0 & o==0)
{
Blynk.notify("Place your finger to the sensor");
}
}
void wifi_connect(){
if(WiFi.status() != WL_CONNECTED)
{
Serial.print("Attempting to connect to 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.");
}
}
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
ThingSpeak.begin(client); //Initialize ThingSpeak
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");
}
// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
timer.setInterval(30000, sendMsg); //runs every half a min
timer.setInterval(1000, wifi_connect);
}
void loop()
{
Blynk.run();
timer.run();
float x= ThingSpeak.writeField(myChannelNumber, 1, spo2, myWriteAPIKey);
// Make sure to call update as fast as possible
pox.update();
// Asynchronously dump heart rate and oxidation levels to the serial
// For both, a value of 0 means "invalid"
if (millis() - tsLastReport > REPORTING_PERIOD_MS)
{
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");
{
// here what i did , is i am converting DIgital and ANALOG outputs to VIRTUAL so i can display them
Blynk.virtualWrite(5, pox.getHeartRate());
Blynk.virtualWrite(4, pox.getSpO2());
}
tsLastReport = millis();
}
}
It connects to Thingspeak , i just get 0 value for the spo2 ,but when i remove thingspeak code it works
  11 Comments
Vinod
Vinod on 22 Sep 2020
My guess is something about the pox library must be messing up interrupts and that interferes with the wifi connectivity used by ThingSpeak. A simple test will be run one test with the pox library code commented out but the ThingSpeak code in (send random numbers instead of real sensor data) and a separate run with the ThingSpeak code commented our and the pox library enabled. If each works independently, then you will have confirmed my hypothesis.
THEODOROS KOUKOUVES
THEODOROS KOUKOUVES on 22 Sep 2020
Its definetely Pox cuz they work seperately .
Thing is if you check documentation of max30100 ,there is no pox mention anywhere.
Will try and uppload it to my Works thingspeak with license and check again.

Sign in to comment.

Answers (1)

Lika Fitranto
Lika Fitranto on 30 Nov 2020
I tried coding above but an error like this happened. how can i fix it? please help me
C:\Users\asus\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp: In static member function 'static void SpiDrv::begin()':
C:\Users\asus\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp:87:24: error: 'PINS_COUNT' was not declared in this scope
if (SLAVERESET > PINS_COUNT) {
^
C:\Users\asus\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp:97:15: error: 'NINA_GPIO0' was not declared in this scope
pinMode(NINA_GPIO0, OUTPUT);
^
C:\Users\asus\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp: In static member function 'static int SpiDrv::available()':
C:\Users\asus\Documents\Arduino\libraries\WiFiNINA\src\utility\spi_drv.cpp:581:25: error: 'NINA_GPIO0' was not declared in this scope
return (digitalRead(NINA_GPIO0) != LOW);
^
exit status 1
Error compiling for board Generic ESP8266 Module.

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Write Data to Channel in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!