Unable to get first sketch running on Uno with Bluefruit LE

I’m trying to get my first sketch running with Blynk. I’m using an Arduino UNO with the Adafruit Bluefruit LE SPI friend (not the UART version) I’ve successfully run one of the examples from Adafruit, so I know the board is wired properly and working. I’m using the Blynk example code builder with the options: selected Board:“UNO”, Connection:“Adafruit Bluefruit BLE,” Example:”Terminal”. When I tried to compile it, I get a compiler error that BLESerial.h was not found. I then moved the files BLESerial.h and BLESerial.cpp from BLEPeripheral/examples/serial to BLEPeripheral/src and the code compiles. However when I run the sketch, I see nothing on the Serial monitor. I added some print statements - I can see “begin” but not “back from begin”, which tells me the code is getting stuck in the statement: “SerialBLE.begin()” Can someone help me getting going with Blynk? Thanks!

 *************************************************************
  For this example you need BLEPeripheral library
    from http://librarymanager/all#BLEPeripheral
    or https://github.com/sandeepmistry/arduino-BLEPeripheral

  Warning: 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 <BLEPeripheral.h>
#include "BLESerial.h"
#include <SPI.h>

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

// define pins (varies per shield/board)
#define BLE_REQ   10
#define BLE_RDY   2
#define BLE_RST   9

// create ble serial instance, see pinouts above
BLESerial SerialBLE(BLE_REQ, BLE_RDY, BLE_RST);

// 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.setLocalName("Blynk");
  SerialBLE.setDeviceName("Blynk");
  SerialBLE.setAppearance(0x0080);
  
  Serial.println(F("begin"));
  SerialBLE.begin();
  Serial.println(F("back from begin"));

  Blynk.begin(SerialBLE, auth);

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

  // Clear the terminal content
  terminal.clear();

  // 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()
{
  SerialBLE.poll();
  Blynk.run();
}

With a little more poking around I decided that these pin assignments were more appropriate:

#define BLE_REQ   8
#define BLE_RDY   7
#define BLE_RST   4

Made no difference :frowning:

You need to have the BLE widget in your app, and use this to initialise a connection between the Uno and the app/server.

Pete.

Thanks, Pete. Can you point me to a sample app that might work for me?

I have an idea of what the problem is. In the list of supported hardware here: https://github.com/blynkkk/blynkkk.github.io/blob/master/SupportedHardware.md I see the entry: “nRF8001-based boards (Adafruit Bluefruit LE, etc.)” My Adafruit board is nRF51822-based. Is there support for this, or am I simply out of luck?

You don’t need any additional app, you need to add the BLE widget into your Blynk app and use it to connect to your hardware.

Your Blynk app currently has three widgets, Vertical Slider, Terminal and LCD - no BLE widget, so no BLE connection.

Pete.

Thanks very much, Pete! That was, indeed, a key missing piece. Also, I needed to use the sketch “Adafruit_Feather_32u4_BLE” which is set up for my BLE board, rather than the example sketch I was using. I’m up and running now! Whee! I can also see from your reply that in general I shouldn’t share auth tokens; I’ll delete my app and start over :laughing: Thanks again for your help with this

Just generate a fresh auth token in the app project.

Pete.