Connecting Teensy 3.5 to BC127 breakout from Sparkfun

Status
Not open for further replies.

4bdu1

Member
Hello all, I tried to connect the BC127 bluetooth breakout module from sparkfun to my teensy 3.5 but it seems it's not connected properly. I keep getting timeout response when I try to test using the Sparkfun bluetooth library code. Please any help on which pins to connect to and to what?

Currently I connected the ground to ground, V_bat to power and RX,TX to pin 3 and 2 respectively but I keep getting -2 as response which indicated a timeout error. Meaning its either not powered, not connected correctly or a wrong baud rate is set. Any help on what I might be doing wrong? Thank you

Code:
#include <SparkFunbc127.h>
#include <SoftwareSerial.h>

SoftwareSerial swPort(3,2);  // RX, TX
BC127 BTModu(&swPort);

void setup()
{
  Serial.begin(9600);
  Serial.println("Hello world!");
  swPort.begin(9600);
}

void loop()
{
  Serial.print("Restore result: "); Serial.println(BTModu.restore());
  Serial.print("Write result: "); Serial.println(BTModu.writeConfig());
  Serial.print("Reset result: "); Serial.println(BTModu.reset());
  BTClassicTesting();
  while(1);
}

void addrTest()
{
  String address;
  Serial.print("Address result: "); Serial.println(BTModu.addressQuery(address));
  Serial.println(address);
}

void BLETesting()
{
  int connectionResult = 0;
  Serial.print("BLE result: "); Serial.println(BTModu.BLECentral());
  BTModu.writeConfig();
  BTModu.reset();
  Serial.print("BLE scan result: "); Serial.println(BTModu.BLEScan(10));
  String address;
  for (char i = 0; i < 5; i++)
  {
    if (BTModu.getAddress(i, address))
    {
      if (address.startsWith("20FABB"))
      {
        Serial.print("BC127 found at index "); Serial.println(i);
        Serial.print("Connect result: ");
        connectionResult = BTModu.connect(address, BC127::BLE);
        Serial.println(connectionResult);
        break;
      }
    }
  }
  if (connectionResult == 0) Serial.println("No BC127 modules found!");
  else
  {
    if (connectionResult == 1)
    {
      swPort.println("Hello, world!");
      swPort.flush();
    }
    else Serial.println("Failure!");
  } 
}

void baudTest()
{
  Serial.println(BTModu.setBaudRate(BC127::s19200bps));
  swPort.begin(19200);
  Serial.println(BTModu.setBaudRate(BC127::s19200bps));
}

void BTClassicTesting()
{
  int connectionResult = 0;
  Serial.print("Inquiry result: "); Serial.println(BTModu.inquiry(10));
  String address;
  for (byte i = 0; i < 5; i++)
  {
    if (BTModu.getAddress(i, address))
    {
      Serial.print("BT device found at address ");
      Serial.println(address);
      if (address.startsWith("20FABB"))
      {
        Serial.print("BC127 found at index "); Serial.println(i);
        Serial.print("Connect result: ");
        connectionResult = BTModu.connect(address, BC127::SPP);
        Serial.println(connectionResult);
        break;
      }
    }
  }
  if (connectionResult == 0) Serial.println("No BC127 modules found!");
  else
  {
    if (connectionResult == 1)
    {
      Serial.print("Entering data mode...");
      if (BTModu.enterDataMode()) 
      {
        Serial.println("OK!");
        swPort.println("Hello, world!");
        swPort.flush();
        delay(500);
        Serial.print("Exiting data mode...");
        if (BTModu.exitDataMode()) Serial.println("OK!");
        else Serial.println("Failure!");
      }
      else Serial.println("Failure!");
    }
  } 
}
 
My connections are:
pin 3 to TX on BC127 breakout
pin 2 to RX on BC127 breakout
GND to GND on BC127 breakout
Vin to VBAT on BC127 breakout

I'm powering my teensy using my laptop via USB cable. Any help? Thank you.
 
Why are you using the slow and clumsy bit-banging software serial library on a Teensy 3.5 which has more than enough hardware UARTs? Software serial was written as a crutch for the asthmatic Arduino UNO because it had not enough ports...
 
Why are you using the slow and clumsy bit-banging software serial library on a Teensy 3.5 which has more than enough hardware UARTs? Software serial was written as a crutch for the asthmatic Arduino UNO because it had not enough ports...

A bit new to teensy. Any suggestion on how to revise my connections?
 
A bit new to teensy. Any suggestion on how to revise my connections?

This is what I have now :
pin 10 to RX on BC127 breakout
pin 9 to TX on BC127 breakout
GND to GND on BC127 breakout
Vin to VBAT on BC127 breakout

Code:
#include <SparkFunbc127.h>

BC127 BTModu(&Serial);

void setup()
{
  Serial.begin(9600);
  Serial.println("Hello world!");
}

void loop()
{
  Serial.println(BTModu.restore());
  Serial.println(BTModu.writeConfig());
  Serial.println(BTModu.reset());
  BTClassicTesting();
  addrTest();
  while(1);
}

void addrTest()
{
  String address;
  Serial.print("Address result: "); Serial.println(BTModu.addressQuery(address));
  Serial.println(address);
}


void baudTest()
{
  Serial.println(BTModu.setBaudRate(BC127::s19200bps));
  Serial.println(BTModu.setBaudRate(BC127::s19200bps));
}

void BTClassicTesting()
{
  int connectionResult = 0;
  Serial.print("Inquiry result: "); Serial.println(BTModu.inquiry(10));
  String address;
  for (byte i = 0; i < 5; i++)
  {
    if (BTModu.getAddress(i, address))
    {
      Serial.print("BT device found at address 1");
      Serial.println(address+"here");
      if (address.startsWith("20FABB"))
      {
        Serial.print("BC127 found at index "); Serial.println(i);
        Serial.print("Connect result: ");
        connectionResult = BTModu.connect(address, BC127::SPP);
        Serial.println(connectionResult);
        break;
      }
    }
  }
  if (connectionResult == 0) Serial.println("No BC127 modules found!");
  else
  {
    if (connectionResult == 1)
    {
      Serial.print("Entering data mode...");
      if (BTModu.enterDataMode()) 
      {
        Serial.println("OK!");
        delay(500);
        Serial.print("Exiting data mode...");
        if (BTModu.exitDataMode()) Serial.println("OK!");
        else Serial.println("Failure!");
      }
      else Serial.println("Failure!");
    }
  } 
}
 
The first hardware Serial port Serial 1 goes to Pin0(RX) and pin1(TX). These would be cross-connected: pin0 to TX of the BC127 and pin1 to the RX.

In your code, you would drop the lines
Code:
#include <SoftwareSerial.h>SoftwareSerial swPort(3,2);  // RX, TX
and replace the following one with
Code:
BC127 BTModu(&Serial1);

In your code in post #5 you do BC127 BTModu(&Serial); but Serial (without number) is the virtual serial port which is only mapped to the USB port. Using one of the native hardware serial ports invokes always having a number, i.e. Serial1
 
The first hardware Serial port Serial 1 goes to Pin0(RX) and pin1(TX). These would be cross-connected: pin0 to TX of the BC127 and pin1 to the RX.

In your code, you would drop the lines
Code:
#include <SoftwareSerial.h>SoftwareSerial swPort(3,2);  // RX, TX
and replace the following one with
Code:
BC127 BTModu(&Serial1);

In your code in post #5 you do BC127 BTModu(&Serial); but Serial (without number) is the virtual serial port which is only mapped to the USB port

I have done just that. This is the output I still get:

Code:
-2
-2
-2
Inquiry result: -2
BT device found at address 1here
BT device found at address 1here
BT device found at address 1here
BT device found at address 1here
BT device found at address 1here
No BC127 modules found!
Address result: -2

From this code
Code:
#include <SparkFunbc127.h>

BC127 BTModu(&Serial1);

void setup()
{
  Serial.begin(9600);
  Serial.println("Hello world!");
}

void loop()
{
  Serial.println(BTModu.restore());
  Serial.println(BTModu.writeConfig());
  Serial.println(BTModu.reset());
  BTClassicTesting();
  addrTest();
  while(1);
}

void addrTest()
{
  String address;
  Serial.print("Address result: "); Serial.println(BTModu.addressQuery(address));
  Serial.println(address);
}


void baudTest()
{
  Serial.println(BTModu.setBaudRate(BC127::s19200bps));
  Serial.println(BTModu.setBaudRate(BC127::s19200bps));
}

void BTClassicTesting()
{
  int connectionResult = 0;
  Serial.print("Inquiry result: "); Serial.println(BTModu.inquiry(10));
  String address;
  for (byte i = 0; i < 5; i++)
  {
    if (BTModu.getAddress(i, address))
    {
      Serial.print("BT device found at address 1");
      Serial.println(address+"here");
      if (address.startsWith("20FABB"))
      {
        Serial.print("BC127 found at index "); Serial.println(i);
        Serial.print("Connect result: ");
        connectionResult = BTModu.connect(address, BC127::SPP);
        Serial.println(connectionResult);
        break;
      }
    }
  }
  if (connectionResult == 0) Serial.println("No BC127 modules found!");
  else
  {
    if (connectionResult == 1)
    {
      Serial.print("Entering data mode...");
      if (BTModu.enterDataMode()) 
      {
        Serial.println("OK!");
        delay(500);
        Serial.print("Exiting data mode...");
        if (BTModu.exitDataMode()) Serial.println("OK!");
        else Serial.println("Failure!");
      }
      else Serial.println("Failure!");
    }
  } 
}
 
At least, we can be sure now that the Teensy hardware side is ok. If this didn't yet help, you should look at the code of Sparkfun's BC127 library... Is it written or at least approved for use with Teensy3.x or does it perhaps have Arduino specific old fashioned 8bit AVR CPU code inside?
 
At least, we can be sure now that the Teensy hardware side is ok. If this didn't yet help, you should look at the code of Sparkfun's BC127 library... Is it written or at least approved for use with Teensy3.x or does it perhaps have Arduino specific old fashioned 8bit AVR CPU code inside?

I have read in the forums about people saying they have used it with the teensy and it works.
 
What about trying to initialize the Teensy's Serial port with the same baud rate which you want to use with the BC127 afterwards?
Add Serial1.begin(19200) in setup()

The lots of -2 errors you are seeing are timeouts which could be caused by non matching baud rates.
 
Code:
BC127 BTModu(&Serial1);

void setup()
{
  Serial1.begin(19200);
}

void loop()
{
  Serial.println(BTModu.restore());
  Serial.println(BTModu.writeConfig());
  Serial.println(BTModu.reset());
  BTClassicTesting();
  addrTest();
  while(1);
}

Still getting the same output:
Code:
-2
-2
-2
Inquiry result: -2
BT device found at address 1here
BT device found at address 1here
BT device found at address 1here
BT device found at address 1here
BT device found at address 1here
No BC127 modules found!
Address result: -2
 
Ok, I have no BC127 here and no time to dig into the Sparkfun BC127 library code and documentation. Don't they have simple example code ? And a support forum ? Since, in my opinion, everything is correct and fine from your Teensy Serial side. But I can not guarantee that the BC127 commands which your code sends or requests are appropriate or not.
 
The default baud rate for the BC127 is 9600.

The sketch in post #7 has:
Code:
Serial.begin(9600);
Whereas the sketch in post #11 has:
Code:
Serial1.begin(19200);

The responses all seem to timeout, indicating a comm problem. This could be a baud rate mismatch or a hookup problem.

Try:
Code:
Serial1.begin(9600);

Hopefully the module will respond as it should be defaulted to 9600 as well. I didn't dig into the Sparkfun docs enough to see if VBat is the correct hookup for 3.3v or if there's a difference between the 2 Tx/Rx pairs on the BC127.
 
The default baud rate for the BC127 is 9600.

The sketch in post #7 has:
Code:
Serial.begin(9600);
Whereas the sketch in post #11 has:
Code:
Serial1.begin(19200);

The responses all seem to timeout, indicating a comm problem. This could be a baud rate mismatch or a hookup problem.

Try:
Code:
Serial1.begin(9600);

Hopefully the module will respond as it should be defaulted to 9600 as well. I didn't dig into the Sparkfun docs enough to see if VBat is the correct hookup for 3.3v or if there's a difference between the 2 Tx/Rx pairs on the BC127.

After changing the baud rate to 9600 nothing gets printed out to the serial monitor. This is the code I'm using:

Code:
#include <SparkFunbc127.h>

BC127 BTModu(&Serial1);

void setup()
{
  Serial1.begin(9600);
}

void loop()
{
  Serial.println(BTModu.restore());
  Serial.println(BTModu.writeConfig());
  Serial.println(BTModu.reset());
  BTClassicTesting();
  addrTest();
  while(1);
}

Is there a need to change the Serial.println lines to Serial1.println?
 
Adding the code below to setup() I get results.

Code:
#include <SparkFunbc127.h>

BC127 BTModu(&Serial1);

void setup()
{
  Serial1.begin(9600);
  BTModu.exitDataMode();
}

void loop()
{
  Serial.print("Restore result: "); Serial.println(BTModu.restore());
  Serial.print("Write result: "); Serial.println(BTModu.writeConfig());
  Serial.print("Reset result: "); Serial.println(BTModu.reset());
  addrTest();
  Serial.println(BTModu.inquiry(10));
  while(1);
}

void addrTest()
{
  String address;
  Serial.print("Address result: "); Serial.println(BTModu.addressQuery(address));
  Serial.println(address);
}
\


Results
Code:
1
Restore result: 1
Write result: 1
Reset result: 1
Address result: 1
20FABB09071F

I think the inquiry command is what's taking time.
 
Last edited:
Adding the code below to setup() I get results.

Code:
#include <SparkFunbc127.h>

BC127 BTModu(&Serial1);

void setup()
{
  Serial1.begin(9600);
  BTModu.exitDataMode();
}

void loop()
{
  Serial.print("Restore result: "); Serial.println(BTModu.restore());
  Serial.print("Write result: "); Serial.println(BTModu.writeConfig());
  Serial.print("Reset result: "); Serial.println(BTModu.reset());
  addrTest();
  Serial.println(BTModu.inquiry(10));
  while(1);
}

void addrTest()
{
  String address;
  Serial.print("Address result: "); Serial.println(BTModu.addressQuery(address));
  Serial.println(address);
}
\

I think the inquiry command is what's taking time.


I am able to get the address after you suggested to add the addrTest( ). But when I am using the address obtained from addrTest( ) to connect to the bluetooth module using connectionResult = BTModu.connect(address, BC127::SPP); I get connection result as -2. Where you able to connect to the module? Were you successful in using the module? If yes, please post your findings.
 
I'm having the same problems!

Hi! I'm using the same hardware and am also having communication problems. I tried your last posted code and only get -2 results. Which version of Melody is your BC127 using?
 
Status
Not open for further replies.
Back
Top