Wire_begin() blocking Blynk USB connection

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.

https://learn.sparkfun.com/tutorials/sparkfun-pulse-oximeter-and-heart-rate-monitor-hookup-guide?_ga=2.76956117.174678905.1610825303-271600742.1604118033#example-1-config-bpm-mode-1

#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.

Does this code work for you, exactly as it stands?

What is this all about?..

Do you have an FTDI adapter connected to pins 2 & 3?
If not, why are you including all of the debug code?

Pete.

Yes the code works for me without Wire.Begin(), but the sensor does not get initialized. With the wire_begin(), the sensor works, but it hangs with different loopcount values. I have also tested the code without Blynk and it works fine displaying correct values on my LCD setup… I took all that code out to debug where this is getting stuck.

I removed the #define SUCCESS statements and it has the same issue. I had them there sometime ago for a different issue, which got fixed with the newer version of the library. Please ignore this.

I am not using FTDI adapters; I used the sample code as is. If you suggest, I can trying commenting this out, if that will resolve the issue here.

Thanks.

A better solution would be to obtain an FTDI adapter and use it, or better still use a board with WiFi connectivity to free-up your serial port for debugging.

So are you using a physical LCD as well as a Blynk LCD widget?

Pete.

Thanks Pete. I haven’t used FTDI adapter; can u send me links or info on how to procced here.

I don’t have a WiFi/shield board working - that’s my next project, and will take sometime. I was hoping this is a known issue and easily resolvable, if somebody has already encountered this.

I had physical LCDs connected and it displays the correct values. This code is stripped down to only have Blynk interface code and also has LCDs defined - but not displaying values because of the sensor initialization issue and that I tracked down to this Wire.Begin() blocking function call.

  1. buy one of these…

https://www.ebay.co.uk/itm/USB-TTL-Serial-Adapter-CH340-FTDI-CP2102-PL2303-ESP-Flashing-Arduino-Gift-2020-/310931472288?_trksid=p2349624.m46890.l49292

  1. connect Rx to pin 3, Tx to pin 2 and GND to GND.

  2. plug the FTDI into your serial port, install CH340 drivers if necessary, a new COM port will appear in Device Manager

  3. open the UDE, select the new COM port, open your serial monitor and set the baud rate to 9600.

Don’t use a WiFi shield, buy a NodeMCU.

I’m confused by this statement. You could have a conflict between a physical LCD and your oximeter, but your answer about LCDs, and your code is ambiguous.

Pete.

On the LCD comment, let me try again:

  • the attached in this thread does not have physical LCD; it is using Blynk LCDs; I took away the physical LCD code.
  • my original code (w/o blynk code) has physical LCDs along with Pulse Oximeter and several other censors and they all work fine on the physical LCD. These LCD and the sensors work on I2C bus and there is no conflict.

Hope this answers your other question.