Trouble porting Adafruit nRF51 to Teensy 3.1

Status
Not open for further replies.

vegasjake

New member
I am attempting to get an adafruit board, the bluefruit LE UART working with my Teensy 3.1. I'm using Arduino IDE 1.6.4 and Teensyduino 1.23. I am using the library located here. This is able to be replicated on multiple computers.

When attempting to run any of their example sketches (such as this one)
Code:
/*!
    @file     bleuart_datamode.ino
    @author   hathach, ktown (Adafruit Industries)
    
    This demo will show you how to initialize the module in COMMAND mode then
    send data in DATA mode, uses the MODE pin
*/

#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#include <SoftwareSerial.h>

#include "Adafruit_BLE.h"
#include "Adafruit_BLE_HWSPI.h"
#include "Adafruit_BluefruitLE_UART.h"

// If you are using Software Serial....
// The following macros declare the pins used for SW serial, you should
// use these pins if you are connecting the UART Friend to an UNO
#define BLUEFRUIT_SWUART_RXD_PIN        9    // Required for software serial!
#define BLUEFRUIT_SWUART_TXD_PIN        10   // Required for software serial!
#define BLUEFRUIT_UART_CTS_PIN          11   // Required for software serial!
#define BLUEFRUIT_UART_RTS_PIN          -1   // Optional, set to -1 if unused

// If you are using Hardware Serial
// The following macros declare the Serial port you are using. Uncomment this
// line if you are connecting the BLE to Leonardo/Micro or Flora
//#define BLUEFRUIT_HWSERIAL_NAME           Serial1

// Other recommended pins!
#define BLUEFRUIT_UART_MODE_PIN         12   // Optional but recommended, set to -1 if unused

// Sketch Settings
#define BUFSIZE                         128   // Read buffer size for incoming data
#define VERBOSE_MODE                    true  // Enables full debug output is 'true'

/* Create the bluefruit object, either software serial... */

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);

Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
                      BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);

/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
//Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);


// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}


/**************************************************************************/
/*!
    @brief  Sets up the HW an the BLE module (this function is called
            automatically on startup)
*/
/**************************************************************************/
void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Adafruit Bluefruit Command <-> Data Mode Example"));
  Serial.println(F("------------------------------------------------"));

  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));
  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  /* Perform a factory reset to make sure everything is in a known state */
  Serial.print(F("Performing a factory reset: "));
  if (! ble.factoryReset() ){
       error(F("Couldn't factory reset"));
  }

  /* Disable command echo from Bluefruit */
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  ble.info();

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in UART mode"));
  Serial.println(F("Then Enter characters to send to Bluefruit"));
  Serial.println();
  
  ble.verbose(false);  // debug info is a little annoying after this point!
  
  /* Wait for connection */
  while (! ble.isConnected()) {
      delay(500);
  }
  
  Serial.println(F("*****************"));

  // Set module to DATA mode
  if (BLUEFRUIT_UART_MODE_PIN >= 0) {
    Serial.println( F("Switching to DATA mode using the MODE pin!") );
    ble.setModePin(BLUEFRUIT_MODE_DATA);
  } else {
    Serial.println( F("Switching to DATA mode using +++!") );
    ble.println("+++");
    delay(100);
    ble.waitForOK();
  }
  
  Serial.println(F("*****************"));
}

/**************************************************************************/
/*!
    @brief  Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{
  // Check for user input
  char n, inputs[BUFSIZE+1];
  
  if (Serial.available())
  {
    n = Serial.readBytes(inputs, BUFSIZE);
    inputs[n] = 0;
    // Send characters to Bluefruit
    Serial.print("Sending: ");
    Serial.print(inputs);

    // Send input data to host via Bluefruit
    ble.print(inputs);
  }

  // Echo received data
  while ( ble.available() )
  {
    int c = ble.read();

    Serial.print((char)c);

    // Hex output too, helps w/debugging!
    Serial.print(" [0x");
    if (c <= 0xF) Serial.print(F("0"));
    Serial.print(c, HEX);
    Serial.print("] ");
  }
}

I receive the following error message:

Code:
C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp: In member function 'bool Adafruit_BLE::sendCommandWithIntReply(const __FlashStringHelper*, uint32_t*)':
C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp:170:26: error: 'isDigit' was not declared in this scope
if (! isDigit(buffer[0]))
^
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/HardwareSerial.h:163:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:16,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.h:41,
from C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp:36:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Stream.h: In member function 'size_t Adafruit_BLE::readln(char*, size_t)':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Stream.h:62:6: error: 'int Stream::timedPeek()' is private
int timedPeek();
^
C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp:212:10: error: within this context
if ( timedPeek() == '\n' ) read();
^
In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/HardwareSerial.h:163:0,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:16,
from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
from C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.h:41,
from C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp:36:
C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Stream.h:62:6: error: 'int Stream::timedPeek()' is private
int timedPeek();
^
C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp:212:20: error: within this context
if ( timedPeek() == '\n' ) read();
^
Error compiling.

I resolved the first error by changing isDigit() to isdigit() (lowercase, in case you missed it). The second error with timedPeek() is causing me more trouble. The original arduino libraries have it in a protected class. Making it protected or public stops the errors, however it gets stuck while compiling at approximately 40%.

Here is the verbose output from the compiler:

Code:
Build options changed, rebuilding all
Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI (1.0.x format)
Using library SoftwareSerial in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial (1.0.x format)
Using library Adafruit_BluefruitLE_nRF51-master in folder: C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master (1.0.x format)

C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=123 -DARDUINO=10604 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master C:\Users\Shadowed\AppData\Local\Temp\build4077207500859128305.tmp\bleuart_datamode.cpp -o C:\Users\Shadowed\AppData\Local\Temp\build4077207500859128305.tmp\bleuart_datamode.cpp.o 
bleuart_datamode.ino: In function 'void loop()':
bleuart_datamode.ino:129:13: warning: array subscript has type 'char' [-Wchar-subscripts]
C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=123 -DARDUINO=10604 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI\utility C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI\SPI.cpp -o C:\Users\Shadowed\AppData\Local\Temp\build4077207500859128305.tmp\SPI\SPI.cpp.o 
C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=123 -DARDUINO=10604 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial\utility C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial\SoftwareSerial.cpp -o C:\Users\Shadowed\AppData\Local\Temp\build4077207500859128305.tmp\SoftwareSerial\SoftwareSerial.cpp.o 
C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=123 -DARDUINO=10604 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\utility C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp -o C:\Users\Shadowed\AppData\Local\Temp\build4077207500859128305.tmp\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE.cpp.o 
C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=123 -DARDUINO=10604 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\utility C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE_HWSPI.cpp -o C:\Users\Shadowed\AppData\Local\Temp\build4077207500859128305.tmp\Adafruit_BluefruitLE_nRF51-master\Adafruit_BLE_HWSPI.cpp.o 
C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -O -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=123 -DARDUINO=10604 -DF_CPU=96000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SoftwareSerial -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master -IC:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\utility C:\Users\Shadowed\Documents\Arduino\libraries\Adafruit_BluefruitLE_nRF51-master\Adafruit_BluefruitLE_UART.cpp -o C:\Users\Shadowed\AppData\Local\Temp\build4077207500859128305.tmp\Adafruit_BluefruitLE_nRF51-master\Adafruit_BluefruitLE_UART.cpp.o

Any help would be much appreciated.

Thanks!

EDIT: That last line of the compiler output is where it's stuck. It never finishes compiling.
 
Last edited:
Wow, thanks for the fast reply, I wasn't expecting anyone to be up so late at night! Tried 1.6.3 and sure enough it compiled with no issues, sweet!

Thanks for the help!
 
Awesome that was it! A fix was recorded against the IDE and should be out and PJRC is expecting it to update. Late? West coast time here won't be late for hours.
 
I'm west coast time as well, but I figured the forums were asleep by now :p Of course now it won't detect the bluetooth device, but that requires more troubleshooting before I bug you guys some more, it's probably something simple, since it worked on the Uno.
 
All sorts of odd hours here with folks around the world. I see Serial1 commented out and SoftwareSerial in use? Do you need flow control - the hardware serial is there and I've toyed with that and found it to work well. Ideally your mapping from UNO to Teensy and having the pins right way around should keep Rx/Tx straight. Not sure of the BLE startup timing - the Teensy wastes no time - a simple delay up front might be good. I don't see any delay before starting USB Serial and printing - I've found a delay there helpful so the debug spew can show after the connection starts. YMMV - easily adjusted.

I've found the qBlink code expressed here useful. It shows a couple things I picked up - waiting for serial, WriteFast/ReadFast in the qBlink(), starting the LED_BUILTIN quickly and then being able to toggle it.
 
I tried uncommenting the hardware serial part and using Serial2 last night, but I'm not sure how I messed up. Waking up today with a clear head, I tried again with Serial1, and no dice... Then I realized that I had the TX and RX pins switched... Oops. Here's the final code below for anyone that may come across this from a search engine.

Code:
/*!
    @file     bleuart_datamode.ino
    @author   hathach, ktown (Adafruit Industries)
    
    This demo will show you how to initialize the module in COMMAND mode then
    send data in DATA mode, uses the MODE pin
*/

#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#include <SoftwareSerial.h>

#include "Adafruit_BLE.h"
#include "Adafruit_BLE_HWSPI.h"
#include "Adafruit_BluefruitLE_UART.h"

// If you are using Software Serial....
// The following macros declare the pins used for SW serial, you should
// use these pins if you are connecting the UART Friend to an UNO
#define BLUEFRUIT_SWUART_RXD_PIN        1    // Required for software serial!
#define BLUEFRUIT_SWUART_TXD_PIN        0   // Required for software serial!
#define BLUEFRUIT_UART_CTS_PIN          11   // Required for software serial!
#define BLUEFRUIT_UART_RTS_PIN          2   // Optional, set to -1 if unused

// If you are using Hardware Serial
// The following macros declare the Serial port you are using. Uncomment this
// line if you are connecting the BLE to Leonardo/Micro or Flora
#define BLUEFRUIT_HWSERIAL_NAME           Serial1

// Other recommended pins!
#define BLUEFRUIT_UART_MODE_PIN         12   // Optional but recommended, set to -1 if unused

// Sketch Settings
#define BUFSIZE                         128   // Read buffer size for incoming data
#define VERBOSE_MODE                    true  // Enables full debug output is 'true'

/* Create the bluefruit object, either software serial... */

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);

Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
                      BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);

/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
//Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);


// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}


/**************************************************************************/
/*!
    @brief  Sets up the HW an the BLE module (this function is called
            automatically on startup)
*/
/**************************************************************************/
void setup(void)
{
  delay(5000);
  Serial.begin(115200);
  Serial.println(F("Adafruit Bluefruit Command <-> Data Mode Example"));
  Serial.println(F("------------------------------------------------"));

  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));
  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  /* Perform a factory reset to make sure everything is in a known state */
  Serial.print(F("Performing a factory reset: "));
  if (! ble.factoryReset() ){
       error(F("Couldn't factory reset"));
  }

  /* Disable command echo from Bluefruit */
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  ble.info();

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in UART mode"));
  Serial.println(F("Then Enter characters to send to Bluefruit"));
  Serial.println();
  
  ble.verbose(false);  // debug info is a little annoying after this point!
  
  /* Wait for connection */
  while (! ble.isConnected()) {
      delay(500);
  }
  
  Serial.println(F("*****************"));

  // Set module to DATA mode
  if (BLUEFRUIT_UART_MODE_PIN >= 0) {
    Serial.println( F("Switching to DATA mode using the MODE pin!") );
    ble.setModePin(BLUEFRUIT_MODE_DATA);
  } else {
    Serial.println( F("Switching to DATA mode using +++!") );
    ble.println("+++");
    delay(100);
    ble.waitForOK();
  }
  
  Serial.println(F("*****************"));
}

/**************************************************************************/
/*!
    @brief  Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void)
{
  // Check for user input
  char n, inputs[BUFSIZE+1];
  
  if (Serial.available())
  {
    n = Serial.readBytes(inputs, BUFSIZE);
    inputs[n] = 0;
    // Send characters to Bluefruit
    Serial.print("Sending: ");
    Serial.print(inputs);

    // Send input data to host via Bluefruit
    ble.print(inputs);
  }

  // Echo received data
  while ( ble.available() )
  {
    int c = ble.read();

    Serial.print((char)c);

    // Hex output too, helps w/debugging!
    Serial.print(" [0x");
    if (c <= 0xF) Serial.print(F("0"));
    Serial.print(c, HEX);
    Serial.print("] ");
  }
}

EDIT: I threw a delay in there as well. Seems to work fine without it, but I left a small one in to be safe.
 
Last edited:
Same issue; changing to 1.6.3 didn't help

Problem may be 1.6.4, others bugs on it hanging compiler are active

I'm trying to do the same thing (same BLE board, with Teensy 3.1), and got the same compilation errors.

I was using Arduino IDE 1.6.5, and tried again with 1.6.3, but the errors were the same.

I got past it by changing the case of IsDigit, and then moved int timedPeek(); into public.

I 'm using whatever is the current Teensyduino as of today.
 
Success!

After modding the libraries I made some changes to the sketch and my wiring.

The Uno example as given on the Adafruit site makes use of software serial. Since the Teensy 3 has hardware UART I decided to try that.

Here's my code:

Code:
/*!
    @file     bleuart_datamode.ino
    @author   hathach, ktown (Adafruit Industries)
    
    This demo will show you how to initialize the module in COMMAND mode then
    send data in DATA mode, uses the MODE pin

  Altered to work with a Teensy 3.1 using Serial2

  The Bluefruit CTS pin is connected to Teensy pin 8.
  The Bluefruit MOD pin is connected to Teensy pin 12.

  Bluefruit is switched to DATA.
  Bluefruit RTS pin is connected to GND.

  Teensy rx2 goes to Bluefruit tx
  Teensy tx2 goes to Bluefruit rx


*/

#include <string.h>
#include <Arduino.h>
#include <SPI.h>
#include <SoftwareSerial.h>

#include "Adafruit_BLE.h"
#include "Adafruit_BLE_HWSPI.h"
#include "Adafruit_BluefruitLE_UART.h"


// If you are using Hardware Serial
// The following macros declare the Serial port you are using. Uncomment this
// line if you are connecting the BLE to Leonardo/Micro or Flora
#define BLUEFRUIT_HWSERIAL_NAME           Serial2

#define BLUEFRUIT_UART_MODE_PIN         12   // Optional but recommended, set to -1 if unused

// Sketch Settings
#define BUFSIZE                         128   // Read buffer size for incoming data
#define VERBOSE_MODE                    true  // Enables full debug output is 'true'


/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);


// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}


/**************************************************************************/
/*!
    @brief  Sets up the HW an the BLE module (this function is called
            automatically on startup)
*/
/**************************************************************************/
void setup(void) {
  Serial.begin(115200);
  Serial.println(F("Adafruit Bluefruit Command <-> Data Mode Example"));
  Serial.println(F("------------------------------------------------"));

  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));
  if ( !ble.begin(VERBOSE_MODE) ) {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  /* Perform a factory reset to make sure everything is in a known state */
  Serial.print(F("Performing a factory reset: "));
  if (! ble.factoryReset() ) {
       error(F("Couldn't factory reset"));
  }

  /* Disable command echo from Bluefruit */
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  ble.info();

  Serial.println(F("Please use Adafruit Bluefruit LE app to connect in UART mode"));
  Serial.println(F("Then Enter characters to send to Bluefruit"));
  Serial.println();
  
  ble.verbose(false);  // debug info is a little annoying after this point!
  
  /* Wait for connection */
  while (! ble.isConnected()) {
      delay(500);
  }
  
  Serial.println(F("*****************"));

  // Set module to DATA mode
  if (BLUEFRUIT_UART_MODE_PIN >= 0) {
    Serial.println( F("Switching to DATA mode using the MODE pin!") );
    ble.setModePin(BLUEFRUIT_MODE_DATA);
  } else {
    Serial.println( F("Switching to DATA mode using +++!") );
    ble.println("+++");
    delay(100);
    ble.waitForOK();
  }
  
  Serial.println(F("*****************"));
}

/**************************************************************************/
/*!
    @brief  Constantly poll for new command or response data
*/
/**************************************************************************/
void loop(void) {
  // Check for user input
  char n, inputs[BUFSIZE+1];
  
  if (Serial.available()) {
    n = Serial.readBytes(inputs, BUFSIZE);
    inputs[n] = 0;
    // Send characters to Bluefruit
    Serial.print("Sending: ");
    Serial.print(inputs);

    // Send input data to host via Bluefruit
    ble.print(inputs);
  }

  // Echo received data
  while ( ble.available() ) {
    int c = ble.read();

    Serial.print((char)c);

    // Hex output too, helps w/debugging!
    Serial.print(" [0x");
    if (c <= 0xF) Serial.print(F("0"));
    Serial.print(c, HEX);
    Serial.print("] ");
  }
}

Also at https://gist.github.com/Neurogami/423f4d4d3c03e0414480 if you want syntax highlighting

I was then able to connect using the Bluefruit LE Android app.
 
Hi all,

I am posting into this thread, because I try exactly the same code posted above on the Teensy 3.2, which is similar to the Teensy 3.1.

There were only 2 changes I had to change:

Code:
//#include "Adafruit_BLE_HWSPI.h"
#include "Adafruit_BluefruitLE_SPI.h"

and

Code:
//ble.setModePin(BLUEFRUIT_MODE_DATA);
ble.setMode(BLUEFRUIT_MODE_DATA);

The serial monitor shows me always the same output, regardless what I am trying:

Code:
ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- ATZ

<- Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?

Attached is a picture of my wiring.
20170211_214832.jpg

Arduino version 1.8.1, Teensyduino version 1.35 and BluefruitLE nRF51 version 1.9.4

Could anyone help me please?

Robert
 
Dear Dobby

Did you find a solution for this problem? I also have teensy 3.2 and I'm getting the same error as you

Cheers
 
I found a solution after a more in-depth search in the pjrc forums, from this post:

https://forum.pjrc.com/threads/39644-Fastest-Bluetooth-Data-transfers-from-Teensy-to-Host-Should-I-use-SPI-What-module

which suggested adding

Code:
#define TEENSY_CTS_PIN 11
#define TEENSY_RTS_PIN 8
hs->attachCts(TEENSY_CTS_PIN);
hs->attachRts(TEENSY_RTS_PIN);

to Adafruit_BluefruitLE_UART.cpp right after the call to hs->begin(9600)

This solved the issue for me (I was using teensy hardware serial interface Serial2)

Cheers
 
Thanks for the hint phuijse. It is now working also in my case, but with a small difference:

Code:
Adafruit_BluefruitLE_UART ble(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN,11,8);

The constructor needs 4 parameters in my library revision, that means CTS and RTS need to be set.
 
Status
Not open for further replies.
Back
Top