Troubles with bluetooth HC-06

Hello. I’m using Arduino Nano, with HC-06. I don’t have any shields. On my phone i have the latest version of app. Anroid, btw. Also in my project I have latest Blynk library. I’m not using any local servers or something else. So HC-06 works properly, i tried it in other project without Blynk. But when I’m using any code from example, i don’t receive anything from arduino. For example, i have code like this:


/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  Note: This only works on Android!
        iOS does not support Bluetooth 2.0 Serial Port Profile
        You may need to pair the module with your smartphone
        via Bluetooth settings. Default pairing password is 1234

  Feel free to apply it to any other example. It's simple!

  NOTE: Bluetooth support is in beta!

  You can send/receive any data using WidgetTerminal object.

  App project setup:
    Terminal widget attached to Virtual Pin V1
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "MyToken here, yes, i didn't forget to change it";

SoftwareSerial SerialBLE(10, 11); // RX, TX

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
    terminal.println("You said: 'Marco'") ;
    terminal.println("I said: 'Polo'") ;
  } else {

    // Send it back
    terminal.print("You said:");
    terminal.write(param.getBuffer(), param.getLength());
    terminal.println();
  }

  // Ensure everything is sent
  terminal.flush();
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type 'Marco' and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();
}

void loop()
{
  Blynk.run();
}



@NekoKeeper: I’d be supprised if this would work …

[...]
SoftwareSerial SwSerial(10, 11); // RX, TX
[...]    
SoftwareSerial SerialBLE(10, 11); // RX, TX
[...]
1 Like

Thx for help, I didn’t noticed that. I just copied that from example. But why is that in examples? Looks strange. So i deleted other things, but it still doesn’t work:

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  Note: This only works on Android!
        iOS does not support Bluetooth 2.0 Serial Port Profile
        You may need to pair the module with your smartphone
        via Bluetooth settings. Default pairing password is 1234

  Feel free to apply it to any other example. It's simple!

  NOTE: Bluetooth support is in beta!

  You can send/receive any data using WidgetTerminal object.

  App project setup:
    Terminal widget attached to Virtual Pin V1
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "authkey";

SoftwareSerial SerialBLE(10, 11); // RX, TX

// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);

// You can send commands from Terminal to your hardware. Just use
// the same Virtual Pin as your Terminal Widget
BLYNK_WRITE(V1)
{

  // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
  if (String("Marco") == param.asStr()) {
    terminal.println("You said: 'Marco'") ;
    terminal.println("I said: 'Polo'") ;
  } else {

    // Send it back
    terminal.print("You said:");
    terminal.write(param.getBuffer(), param.getLength());
    terminal.println();
  }

  // Ensure everything is sent
  terminal.flush();
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  // This will print Blynk Software version to the Terminal Widget when
  // your hardware gets connected to Blynk Server
  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println(F("-------------"));
  terminal.println(F("Type 'Marco' and get a reply, or type"));
  terminal.println(F("anything else and get it printed back."));
  terminal.flush();
}

void loop()
{
  Blynk.run();
}

Okey, I noticed that code from example is for BLE, but HC-06 doesn’t support it. I took code from that example:


And now it’s looks like that:

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

     *************************************************************
      Note: This only works on Android!
            iOS does not support Bluetooth 2.0 Serial Port Profile
            You may need to pair the module with your smartphone
            via Bluetooth settings. Default pairing password is 1234

      Feel free to apply it to any other example. It's simple!

      NOTE: Bluetooth support is in beta!

      You can send/receive any data using WidgetTerminal object.

      App project setup:
        Terminal widget attached to Virtual Pin V1
     *************************************************************/

    /* Comment this out to disable prints and save space */
    #define BLYNK_PRINT Serial


        
    #include <BlynkSimpleSerialBLE.h>
    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = "931cf63a5d0a4af1b4c5405f51e1caa3";


    // Attach virtual serial terminal to Virtual Pin V1
    WidgetTerminal terminal(V1);

    // You can send commands from Terminal to your hardware. Just use
    // the same Virtual Pin as your Terminal Widget
    BLYNK_WRITE(V1)
    {

      // if you type "Marco" into Terminal Widget - it will respond: "Polo:"
      if (String("Marco") == param.asStr()) {
        terminal.println("You said: 'Marco'") ;
        terminal.println("I said: 'Polo'") ;
      } else {

        // Send it back
        terminal.print("You said:");
        terminal.write(param.getBuffer(), param.getLength());
        terminal.println();
      }

      // Ensure everything is sent
      terminal.flush();
    }

    void setup()
    {
      // Debug console
      Serial.begin(9600);
      Blynk.begin(Serial, auth);

      Serial.println("Waiting for connections...");

      // This will print Blynk Software version to the Terminal Widget when
      // your hardware gets connected to Blynk Server
      terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
      terminal.println(F("-------------"));
      terminal.println(F("Type 'Marco' and get a reply, or type"));
      terminal.println(F("anything else and get it printed back."));
      terminal.flush();
    }

    void loop()
    {
      Blynk.run();
    }

But it still doesn’t work. Thats what it’s saying in terminal:

If I remember correctly the examples use the hardware serial for the bluetooth module and a softserial for debug. That is different from what you do.
The example that I’d use as a reference using HC06 is this:
https://github.com/blynkkk/blynk-library/blob/master/examples/Boards_Bluetooth/Serial_HC05_HC06/Serial_HC05_HC06.ino
One more thing: Where do I find this in your code?:

#define BLYNK_USE_DIRECT_CONNECT
1 Like

Thank you, now this works.

1 Like