connecting nrf8001 adafruit ble to teensylc

Status
Not open for further replies.

marinek9

Member
Has anyone been able to get nrf8001 ble boards to work with any teensy board??? I recntly switched to a teensy from arduino and the ble no longer connects.

im using the echodemo code from adafruit
Code:
/*********************************************************************
This is an example for our nRF8001 Bluetooth Low Energy Breakout

  Pick one up today in the adafruit shop!
  ------> [url]http://www.adafruit.com/products/1697[/url]

Adafruit invests time and resources providing this open source code, 
please support Adafruit and open-source hardware by purchasing 
products from Adafruit!

Written by Kevin Townsend/KTOWN  for Adafruit Industries.
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in any redistribution
*********************************************************************/

// This version uses the internal data queing so you can treat it like Serial (kinda)!

#include <SPI.h>
#include "Adafruit_BLE_UART.h"


#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2     // This should be an interrupt pin, on Uno thats #2 or #3
#define ADAFRUITBLE_RST 9

Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
/**************************************************************************/
/*!
    Configure the Arduino and start advertising with the radio
*/
/**************************************************************************/
void setup(void)
{ 
  Serial.begin(9600);
  while(!Serial); // Leonardo/Micro should wait for serial init
  Serial.println(F("Adafruit Bluefruit Low Energy nRF8001 Print echo demo"));

  // BTLEserial.setDeviceName("NEWNAME"); /* 7 characters max! */

  BTLEserial.begin();
}

/**************************************************************************/
/*!
    Constantly checks for new events on the nRF8001
*/
/**************************************************************************/
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop()
{
  // Tell the nRF8001 to do whatever it should be working on.
  BTLEserial.pollACI();

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();
  // If the status changed....
  if (status != laststatus) {
    // print it out!
    if (status == ACI_EVT_DEVICE_STARTED) {
        Serial.println(F("* Advertising started"));
    }
    if (status == ACI_EVT_CONNECTED) {
        Serial.println(F("* Connected!"));
    }
    if (status == ACI_EVT_DISCONNECTED) {
        Serial.println(F("* Disconnected or advertising timed out"));
    }
    // OK set the last status change to this one
    laststatus = status;
  }

  if (status == ACI_EVT_CONNECTED) {
    // Lets see if there's any data for us!
    if (BTLEserial.available()) {
      Serial.print("* "); Serial.print(BTLEserial.available()); Serial.println(F(" bytes available from BTLE"));
    }
    // OK while we still have something to read, get a character and print it out
    while (BTLEserial.available()) {
      char c = BTLEserial.read();
      Serial.print(c);
    }

    // Next up, see if we have any data to get from the Serial console

    if (Serial.available()) {
      // Read a line from Serial
      Serial.setTimeout(100); // 100 millisecond timeout
      String s = Serial.readString();

      // We need to convert the line to bytes, no more than 20 at this time
      uint8_t sendbuffer[20];
      s.getBytes(sendbuffer, 20);
      char sendbuffersize = min(20, s.length());

      Serial.print(F("\n* Sending -> \"")); Serial.print((char *)sendbuffer); Serial.println("\"");

      // write the data
      BTLEserial.write(sendbuffer, sendbuffersize);
    }
  }
}
 
Last edited by a moderator:
'no longer connects' is short on details - what was connected and if there was any error/warning/problem compiling. Going to adafruit link it says "won't work on DUE" ? - and from link it shows it is an SPI device - and should run from 3.3 V, also it isn't clear what Teensy and software versions and OS are in use.
 
Well it never actually connected using the LC... I’m using an Teensy Lc , No errors when compiling, based on some debugging the code appears to lock up when I call uart.begin()
 
I used Adafruit's library.

Would you like help figuring out what's wrong? We're pretty good at helping here, but only when you show us what you're really doing. At the very least, we need to see photos of how you actually connected the wires. A link to exactly which library and which example you're using also helps. I see you posted the code, which is good. When trying to figure this out, usually we'll copy that into Arduino and try to verify. Which version of Arduino and Teensyduino and which OS you have might also matter.

The less we have to guess, the more clearly we can see what you're actually doing, the better the change we'll be able to notice what's gone wrong.
 
Thanks so much for the help and quick response...I’m using the latest copy of teensyduino and 1.86 of the arduino ide.. I did notice that there is a separate Adafruit library that you authored. Should I be using that one? I’m not sure how to ensure that the CS line is set up for HW Interupt....
 
SCK is supposed to connect to pin 13 on Teensy. I see it's the gray wire in your photo. That wire looks like it's going to pin 14/A0 on the Teensy, not pin 13.
 
Well, I used the adafruit library that published on git under your name and I connected immediately!!! Thank you for that.... Unfortunately when I send data to the peripheral device (ipad) using the Adafruit App it only prints 5-6 lines of data then stops, it doesn't disconnect immediately but each time I try I get exactly 6 lines of data, then nothing. The image shows what happens on the serial monitor side, on the app I just get 5 lines of data then nothing.
https://drive.google.com/open?id=1g-qXxLnW1aNi0aULqRmkeIfQ7Y3u2502
 
Status
Not open for further replies.
Back
Top