What are the current options for supporting Bluetooth Low Energy (BLE)?


#1

So I have two Electrons and they are working quite well! I’ve been looking into adding BLE support to talk to some local devices, and the only references I can find are two years old.

Obviously things can change a lot in a year or two, so I wanted to see if there are any recommendations on connecting BLE hardware to an Electron, and to see what sort of results others have had in this area.

Thanks for any insight and updates!


#2

Check out http://Bluz.io

They have a BLE device that interfaces to the Particle build tools and APIs.


#3

There’s also RedBear Duo. It can be programmed OTA through the Particle cloud and has both BLE and WiFi on the same dev board.


#4

The two suggestions above are good. I also ported the library for the Adafruit Bluefruit LE SPI nRF51 breakout boards. I only tested it with the Photon but it should work on the Electron as well. It’s “Adafruit_BLE” in the community libraries and here on github: https://github.com/rickkas7/Adafruit_BLE


#5

Hey thanks for the ideas! I’ve seen the redbear but need the cell connectivity that I get on this Electron… though might be good for wifi option versions of this test setup.

I haven’t really looked at Bluz at all, that’s pretty interesting.

If I have an Electron and GPS unit already connected, I’d need something that would fit in together in the mix there. The Adafruit board mentioned:

Looks pretty small and perhaps that would be the best bet? I wonder if the Electron would have any power issues powering both the GPS and the BLE board. Has anybody tried both on the single board?


#6

The Adafruit BlueFruit LE board can be powered at 3.3V and uses a minuscule amount of current, hence the “LE” or “Low Energy” part of the name, something like 20 mA maximum if I recall correctly, but it is a reasonable question. I’ll look it up and hook one up tomorrow and see if it works.


#7

Awesome! I’d be really curious to hear how it goes. I’ll pick one up if it looks promising, it would be a fun addition to this project I’m tinkering with.


#8

It does work! That’s an Electron (2G) on an AssetTracker, connected to an Adafruit Bluefruit LE SPI. I’m not sure what the use case for this contraption is, but it works. It’s the standard AssetTracker library with my port of the BLE library (Adafruit_BLE in the community libraries, or https://github.com/rickkas7/Adafruit_BLE). I used the Adafruit Bluefruit iOS phone app in UART mode and it prints the location from the asset tracker to the phone via Bluetooth. Neat!


#include "Particle.h"

#include "AssetTracker/AssetTracker.h"

#include "Adafruit_BLE/Adafruit_BLE.h"
#include "Adafruit_BLE/Adafruit_BluefruitLE_SPI.h"

#define BUFSIZE                        128   // Size of the read buffer for incoming data
#define VERBOSE_MODE                   true  // If set to 'true' enables debug output

#define BLUEFRUIT_SPI_CS               D4  	// Note: LIS3DH on the AssetTracker uses A2, don't use that!
#define BLUEFRUIT_SPI_IRQ              D3
#define BLUEFRUIT_SPI_RST              D2    // Optional but recommended, set to -1 if unused
// SPI: SCK=A3, MISO=A4, MOSI=A5
Adafruit_BluefruitLE_SPI ble(&SPI, BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

enum BluetoothState { BLUETOOTH_CONNECT_WAIT, BLUETOOTH_CONNECTED };
BluetoothState bluetoothState = BLUETOOTH_CONNECT_WAIT;

// Creating an AssetTracker named 't' for us to reference
AssetTracker assetTracker = AssetTracker();

const unsigned long CHECK_PERIOD_MS = 10000;

unsigned long lastCheck = 0;


void setup() {
	Serial.begin(9600);

	// Enable Asset Tracker
    assetTracker.begin();
    assetTracker.gpsOn();


    if (ble.begin(VERBOSE_MODE)) {
    	ble.factoryReset();
    	ble.echo(false);

    	// Optional, print some information
    	ble.info();
    }
    else {
    	Serial.println("BLE initialization failed");
    }
}

void loop() {
    // You'll need to run this every loop to capture the GPS output
    assetTracker.updateGPS();

    switch(bluetoothState) {
    case BLUETOOTH_CONNECT_WAIT:
    	if (ble.isConnected()) {
    		Serial.println("BLE connected, switching to data mode");
    		ble.setMode(BLUEFRUIT_MODE_DATA);

    		bluetoothState = BLUETOOTH_CONNECTED;
    	}
    	break;

    case BLUETOOTH_CONNECTED:
    	if (!ble.isConnected()) {
    		Serial.println("BLE disconnected");
    		bluetoothState = BLUETOOTH_CONNECT_WAIT;
    		break;
    	}

    	break;

    }

    if (millis() - lastCheck >= CHECK_PERIOD_MS) {
    	lastCheck = millis();

    	String latLon = assetTracker.readLatLon();
    	Serial.println(latLon);

    	if (bluetoothState == BLUETOOTH_CONNECTED) {
    		ble.println(latLon.c_str());
    	}
    }

}


Using redbear BLE nano v2 (nRF52832) with electron
#9

Hey wow, that’s awesome! I want to try and interact with some BLE sensors and things, and this would be a great way to get some of the data back to the core services. Looks like I’m ordering myself an Adafruit Bluefruit LE SPI!

Can’t wait to give this a spin and see if I get the same success you have.

Thanks again!


#10

Adafruit Bluefruit LE SPI nRF51 is actually a peripheral only, and doesn’t run in Central mode, which would cause the module to behave similar to your mobile phone or BLE enabled laptop.

better switch to nRF52832 so you can switch roles from peripheral to centeral by firmware wise.


#11

Newbie to BT/BLE, but how easy is it to move to one of the newer/cheaper/volume-ready models? EG SiLabs BGM113 is central/peripheral and 8.7mA peak at $5 (cheapest central role unit I have found) and there are several peripheral only modules for $3.50+. If I did not need FCC module, I am sure there are cheaper…

The project will use a photon+antenna module and BLE and a couple wired sensors with BLe peripheral GATT devices.


#12

I am trying to get this module to work with your Library. I can use the adafruit app to query the device and connect to it but the sketch in your Library produces this outpput and then sits in the error

Adafruit Bluefruit AT Command Example
-------------------------------------
Initialising the Bluefruit LE module: OK!
Performing a factory reset:
AT+FACTORYRESET

<- Couldn't factory reset
Adafruit Bluefruit AT Command Example

I upgraded the firmware on the Adafruit BlueFruit LE to v7.7 which was the latest and i did the facotry reset by holding the DFU low. Any suggestions?


#13

Hello,

I am a super newbie to the bluz world ( 0.5 hours old :stuck_out_tongue_winking_eye:) so I apologize in advance if this seems dumb!

I am working towards adding bluetooth functionality to my Electron such that it gets information from upto 4 local devices over bluetooth, processes and finally, publishes the information onto the Particle cloud via its cellular network. After a lot of research I decided that Bluz would be perfect for this application since it essentially does exactly that.

BUT then i read this…

Gateway Shield Programming Limitations
The gateway shield requires more resources to run then bluz DK. Therefore, some peripherals or resources may not be available or may be limited. The following is a list of differences from bluz DK to the gateway shield: - SPI and I2C are not available on the gateway shield to the user app - Only 1K of RAM is available to the user app - The System.sleep(SLEEP_MODE_CPU) is not available or necessary in the user app - There is no RGB LED for the nrf51822 on the gateway shield

Further, it is advised that no code be placed in the loop() function. This can block the gateway shield from working properly.

Now, my system uses SPI, I2C, UART and Serial1 communication for various sensors and I’m pretty sure my firmware is 1KB with most of the code, including publishes, inside the loop().

Can someone please help me understand this section of the docs…? Thank you :slight_smile:


#14

These would actually be questions best asked at the bluz community.