Hi - I have stripped my code down to bare minimum to debug the issue. I am trying to display Pulse Oximeter sensor values on my iOS device using USB connection. The sensor is using I2C protocol.
Wire.begin() function in setup code that is causing this. If I comment this out, the loopcount works fine without interruption. With the Wire-begin(), loopcount seems to hang at different times. However, I need this Wire.begin() function for the Pulse Oximeter sensor to work properly (wire protocol to act as master on I2C bus). I have attached the short version of the code for reference. Is there any workaround to make this function non-blocking for Blynk usage?
I am also sharing the link below for the SparkFun sensor I am using - you can see the reference code they have that is using Wire.begin() function in their setup code.
#define BLYNK_PRINT DebugSerial
#define SUCCESS SparkFun_Bio_Sensor_Hub_Library_SUCCESS //The problem is that both libraries are polluting the namespace
//with a generic and common name `SUCCESS`l was giving compilation error
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#undef SUCCESS
#include <Wire.h>
#define NUMBER_OF_DISPLAYS 5
// No other Address options.
#define DEF_ADDR 0x55
#define OXYGEN_LEVEL_TRIGGER 90 //Change this to value to any value you want to trigger inhaler use for low oxygen level
// Reset pin, MFIO pin (for pulse oximeter sensor)
const int resPin = 4;
const int mfioPin = 5;
unsigned long delayStart = 0; // the time the delay started
bool oxygen_low=false; // true if still waiting for delay to finish
unsigned long clocktime;
//debug
int loopcount = 0;
// Takes address, reset pin, and MFIO pin.
SparkFun_Bio_Sensor_Hub bioHub(resPin, mfioPin);
bioData body;
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
char auth[] = "xxx";
BlynkTimer timer;
WidgetLCD lcd(V4);
WidgetLCD lcd_title(V7);
BLYNK_CONNECTED() {
lcd_title.clear();
lcd_title.print(0, 0, " WELCOME TO");
lcd_title.print(0, 1, " xxxxx");
}
void sendSensor() {
bioHub.configBpm(MODE_ONE);
body = bioHub.readBpm();
Blynk.virtualWrite(V2, body.status);
Blynk.virtualWrite(V3, body.confidence);
Blynk.virtualWrite(V11, oxygen_low);
loopcount++;
Blynk.virtualWrite(V10, loopcount);
if (body.status == 3 && body.confidence > 90) {
Blynk.setProperty(V1, "color", "#43d3ba");
lcd.clear();
lcd.print(0, 0, "Oximeter: Finger");
lcd.print(0, 1, "Detected");
Blynk.virtualWrite(V0, body.heartRate);
Blynk.virtualWrite(V1, body.oxygen);
Blynk.email(, "Subject: Message", "Hey - Check this out");
}
else {
lcd.clear();
lcd.print(0, 0, "Oximeter: Finger");
lcd.print(3, 1, "Not Detected");
}
}
void setup(){
DebugSerial.begin(9600);
Serial.begin(9600);
// Wire.begin();
int result = bioHub.begin();
Blynk.begin(Serial, auth);
timer.setInterval(1000L, sendSensor);
}
void loop(){
Blynk.run();
timer.run();
}
Thanks in advance.