BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Serial print blcoked by Blynk.begin

Is there any way to use Serial.print in void loop? im making a smart terrarium with blynk and when the code Blynk.begin(SerialBLE, auth); is in setup my print is blocked, even when im connected vai BT with app print in void loop is still ‘blocked’ but print in any function of blynk works normally (BLYNK_WRITE(V20)). Im using hm-10 and i know blynk have some isse with this BT.
When i turn on #define BLYNK_PRINT Serial, serial stuck on Login timeout and Connecting… loop. But ofc bt is connected and works fine.

//#define BLYNK_PRINT Serial
  #define RedP 9 
  #define GrnP 10 
  #define BluP 11
  #include "RTClib.h"
  #include <Wire.h>
  RTC_DS1307 rtcc;
  #include <SoftwareSerial.h>
  SoftwareSerial SwSerial(2, 3); // RX, TX    
  #include <BlynkSimpleSerialBLE.h>
  int s = 61;
  char auth[] = "*********************";
  SoftwareSerial SerialBLE(2, 3); // RX, TX
  int rrr = 0;
  int ggg = 0;
  int bbb = 0;
  void setup()
  {
    analogWrite(RedP, rrr);  // Write to RED RGB pin.
    analogWrite(GrnP, ggg);  // Write to GREEN RGB pin.
    analogWrite(BluP, bbb);  // Write to BLUE RGB pin.
    
    Serial.begin(9600);
    SerialBLE.begin(9600);
    Blynk.begin(SerialBLE, auth);

  if (! rtcc.begin()) {
      Serial.println("Couldn't find RTC");
      Serial.flush();

    }
    if (! rtcc.isrunning()) {
      Serial.println("RTC is NOT running, let's set the time!");   
      rtcc.adjust(DateTime(F(__DATE__), F(__TIME__)));    
    } 

  }
  void loop()
  {
      DateTime noww = rtcc.now();
      if(noww.second() != s){
      Serial.print(noww.hour(), DEC);
      Serial.print(':');
      Serial.print(noww.minute(), DEC);
      Serial.print(':');
      Serial.print(noww.second(), DEC);
      Serial.println();
      s= noww.second();
      }
    Blynk.run();
    
  }
  BLYNK_WRITE(V20)  // RED slider
  {
    Serial.print(':');   //here works fine
    rrr = param.asInt(); 
    Blynk.virtualWrite(V23, rrr); 
    RGBprocess();  
  }
  BLYNK_WRITE(V21)  // GREEN slider
  {
    ggg = param.asInt();
    Blynk.virtualWrite(V24, ggg);  
    RGBprocess();  
  }
  BLYNK_WRITE(V22)  // BLUE slider
  {
    bbb = param.asInt(); 
    Blynk.virtualWrite(V25, bbb);  
    RGBprocess(); 
  }


  BLYNK_WRITE(V2)  // zeRGBa widget
  {
    rrr = param[0].asInt();
    ggg = param[1].asInt();
    bbb = param[2].asInt(); 
    Blynk.virtualWrite(V20, rrr); 
    Blynk.virtualWrite(V23, rrr);
    Blynk.virtualWrite(V21, ggg); 
    Blynk.virtualWrite(V24, ggg);  
    Blynk.virtualWrite(V22, bbb); 
    Blynk.virtualWrite(V25, bbb);  
    RGBprocess();
  }

  void RGBprocess()  
  {
    analogWrite(RedP, rrr); 
    analogWrite(GrnP, ggg);  
    analogWrite(BluP, bbb);  
    
  }

Can you explain what hardware you’re using, and how it’s all connected up?

You appear to be using a hardware RTC module and an unknown type of MCU in addition to the HM-10 that you’ve mentioned.

You are defining two software serial ports using the same physical pins…

Also, why are you using BLE to control your terrarium? Because you are using Blynk.begin, if the HM-10 can’t connect to your phone via BLE then the code won’t execute. I’d have expected you to design a system that will work regardless of whether or not it is connected to your phone or the Blynk server.

Pete.

1 Like

Im using Arduino Uno for now, with HM-10 and rtc 1307 + ofc some mosfets to control led strip. I said blynk debung “#define BLYNK_PRINT Serial” returns Login timeout and Connecting… loops BUT my phone can connect correctly by blynk app to the arduino via HM-10. So in brief: all except Serial.print in void loop() works correctly. And this is what i need to somehow fix cause i cant debug other functions i want to implement. It’s annoying to every time remove Blynk.begin(SerialBLE, auth); and test thing, and then again add it and again and again.

EDIT: Ok so the key was to change Blynk.begin with Blynk.config. Code is no more wating for BT connection.