Skip to content

Commit

Permalink
Merge pull request stm32duino#11 from cparata/master
Browse files Browse the repository at this point in the history
Improve STM32duinoBLE robustness and flexibility
  • Loading branch information
cparata authored Feb 17, 2020
2 parents 495b941 + bd1b0e0 commit 04a895f
Show file tree
Hide file tree
Showing 27 changed files with 637 additions and 855 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ jobs:
strategy:
matrix:
fqbn: [
"arduino:samd:mkrwifi1010",
"arduino:samd:nano_33_iot",
"arduino:megaavr:uno2018:mode=on",
"arduino:mbed:nano33ble"
'"STM32:stm32:Eval:pnum=STEVAL_MKSBOX1V1,usb=CDCgen" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"',
'"STM32:stm32:Nucleo_64:pnum=NUCLEO_L476RG" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"',
'"STM32:stm32:Disco:pnum=DISCO_L475VG_IOT" "https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json"'
]

steps:
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# STM32duinoBLE

This library is a fork of ArduinoBLE library to add the support of SPBTLE-RF and SPBTLE-1S BLE modules.
It was successfully tested with the X-NUCLEO-IDB05A1 expansion board and a NUCLEO-F401RE or NUCLEO-L476RG or
NUCLEO-L053R8, with B-L475E-IOT01A and with STEVAL-MKSBOX1V1.
It was successfully tested with the X-NUCLEO-IDB05A1 or X-NUCLEO-BNRG2A1 expansion board and a NUCLEO-F401RE
or NUCLEO-L476RG or NUCLEO-L053R8, with B-L475E-IOT01A and with STEVAL-MKSBOX1V1.
In order to use this library with STEVAL-MKSBOX1V1, you need to update the firmware of the SPBTLE-1S BLE module
mounted on that board as described in the following wiki page:

https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-STEVAL_MKSBOX1V1

You can find the official Pull Request at the following link:
In order to use this library with X-NUCLEO-BNRG2A1, you need to update the firmware of the BLUENRG-M2SP BLE module
mounted on that expansion board as described in the following wiki page:

https://github.com/arduino-libraries/ArduinoBLE/pull/26
https://github.com/stm32duino/wiki/wiki/STM32duinoBLE-with-X_NUCLEO_BNRG2A1

For more information about ArduinoBLE library please visit the official web page at:
https://github.com/arduino-libraries/ArduinoBLE
Expand Down
82 changes: 73 additions & 9 deletions examples/Central/LedControl/LedControl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
it will remotely control the BLE Peripheral's LED, when the button is pressed or released.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
- Button with pull-up resistor connected to pin 2.
- STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1
You can use it with another board that is compatible with this library and the
Peripherals -> LED example.
Expand All @@ -18,12 +16,47 @@

#include <ArduinoBLE.h>

#if defined(ARDUINO_STEVAL_MKSBOX1V1)
/* STEVAL-MKSBOX1V1 */
SPIClass SpiHCI(PC3, PD3, PD1);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport);
const int buttonPin = PG1; // set buttonPin to digital pin PG1
#elif defined(ARDUINO_DISCO_L475VG_IOT)
/* B-L475E-IOT01A1 */
SPIClass SpiHCI(PC12, PC11, PC10);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
const int buttonPin = PC13; // set buttonPin to digital pin PC13
#else
/* Shield IDB05A1 with SPI clock on D3 */
SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
const int buttonPin = PC13; // set buttonPin to digital pin PC13
/* Shield IDB05A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
const int buttonPin = PC13; // set buttonPin to digital pin PC13 */
/* Shield BNRG2A1 with SPI clock on D3 */
/*SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport);
const int buttonPin = PC13; // set buttonPin to digital pin PC13 */
/* Shield BNRG2A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport);
const int buttonPin = PC13; // set buttonPin to digital pin PC13 */
#endif

// variables for button
const int buttonPin = 2;
int oldButtonState = LOW;
int initialButtonState = LOW;

void setup() {
Serial.begin(9600);
Serial.begin(115200);
while (!Serial);

// configure the button pin as input
Expand All @@ -32,10 +65,23 @@ void setup() {
// initialize the BLE hardware
BLE.begin();

// Get initial button state
initialButtonState = digitalRead(buttonPin);
oldButtonState = initialButtonState;

Serial.println("BLE Central - LED control");

// start scanning for peripherals
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
int ret = 1;
do
{
ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
if (ret == 0)
{
BLE.end();
BLE.begin();
}
} while(ret == 0);
}

void loop() {
Expand All @@ -57,12 +103,30 @@ void loop() {
}

// stop scanning
BLE.stopScan();
int ret = 1;
do
{
ret = BLE.stopScan();
if (ret == 0)
{
BLE.end();
BLE.begin();
}
} while(ret == 0);

controlLed(peripheral);

// peripheral disconnected, start scanning again
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
ret = 1;
do
{
ret = BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
if (ret == 0)
{
BLE.end();
BLE.begin();
}
} while(ret == 0);
}
}

Expand Down Expand Up @@ -110,7 +174,7 @@ void controlLed(BLEDevice peripheral) {
// button changed
oldButtonState = buttonState;

if (buttonState) {
if (buttonState != initialButtonState) {
Serial.println("button pressed");

// button is pressed, write 0x01 to turn the LED on
Expand Down
56 changes: 51 additions & 5 deletions examples/Central/PeripheralExplorer/PeripheralExplorer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
is found. Then connects, and discovers + prints all the peripheral's attributes.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
- STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1
You can use it with another board that is compatible with this library and the
Peripherals -> LED example.
Expand All @@ -16,8 +15,37 @@

#include <ArduinoBLE.h>

#if defined(ARDUINO_STEVAL_MKSBOX1V1)
/* STEVAL-MKSBOX1V1 */
SPIClass SpiHCI(PC3, PD3, PD1);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport);
#elif defined(ARDUINO_DISCO_L475VG_IOT)
/* B-L475E-IOT01A1 */
SPIClass SpiHCI(PC12, PC11, PC10);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
#else
/* Shield IDB05A1 with SPI clock on D3 */
SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
/* Shield IDB05A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport); */
/* Shield BNRG2A1 with SPI clock on D3 */
/*SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport); */
/* Shield BNRG2A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport); */
#endif

void setup() {
Serial.begin(9600);
Serial.begin(115200);
while (!Serial);

// begin initialization
Expand All @@ -30,7 +58,16 @@ void setup() {
Serial.println("BLE Central - Peripheral Explorer");

// start scanning for peripherals
BLE.scan();
int ret = 1;
do
{
ret = BLE.scan();
if (ret == 0)
{
BLE.end();
BLE.begin();
}
} while(ret == 0);
}

void loop() {
Expand All @@ -50,7 +87,16 @@ void loop() {
// see if peripheral is a LED
if (peripheral.localName() == "LED") {
// stop scanning
BLE.stopScan();
int ret = 1;
do
{
ret = BLE.stopScan();
if (ret == 0)
{
BLE.end();
BLE.begin();
}
} while(ret == 0);

explorerPeripheral(peripheral);

Expand Down
47 changes: 42 additions & 5 deletions examples/Central/Scan/Scan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,44 @@
address, local name, adverised service UUID's.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
- STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1
This example code is in the public domain.
*/

#include <ArduinoBLE.h>

#if defined(ARDUINO_STEVAL_MKSBOX1V1)
/* STEVAL-MKSBOX1V1 */
SPIClass SpiHCI(PC3, PD3, PD1);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport);
#elif defined(ARDUINO_DISCO_L475VG_IOT)
/* B-L475E-IOT01A1 */
SPIClass SpiHCI(PC12, PC11, PC10);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
#else
/* Shield IDB05A1 with SPI clock on D3 */
SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
/* Shield IDB05A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport); */
/* Shield BNRG2A1 with SPI clock on D3 */
/*SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport); */
/* Shield BNRG2A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport); */
#endif

void setup() {
Serial.begin(9600);
Serial.begin(115200);
while (!Serial);

// begin initialization
Expand All @@ -26,8 +54,17 @@ void setup() {

Serial.println("BLE Central scan");

// start scanning for peripheral
BLE.scan();
// start scanning for peripherals
int ret = 1;
do
{
ret = BLE.scan();
if (ret == 0)
{
BLE.end();
BLE.begin();
}
} while(ret == 0);
}

void loop() {
Expand Down
45 changes: 41 additions & 4 deletions examples/Central/ScanCallback/ScanCallback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,44 @@
reported for every single advertisement it makes.
The circuit:
- Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.
- STEVAL-MKSBOX1V1, B-L475E-IOT01A1, or a Nucleo board plus the X-NUCLEO-IDB05A1 or the X-NUCLEO-BNRG2A1
This example code is in the public domain.
*/

#include <ArduinoBLE.h>

#if defined(ARDUINO_STEVAL_MKSBOX1V1)
/* STEVAL-MKSBOX1V1 */
SPIClass SpiHCI(PC3, PD3, PD1);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_1S, PD0, PD4, PA8, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport);
#elif defined(ARDUINO_DISCO_L475VG_IOT)
/* B-L475E-IOT01A1 */
SPIClass SpiHCI(PC12, PC11, PC10);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, PD13, PE6, PA8, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
#else
/* Shield IDB05A1 with SPI clock on D3 */
SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport);
/* Shield IDB05A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, SPBTLE_RF, A1, A0, D7, 8000000, SPI_MODE0);
BLELocalDevice BLE(&HCISpiTransport); */
/* Shield BNRG2A1 with SPI clock on D3 */
/*SPIClass SpiHCI(D11, D12, D3);
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport); */
/* Shield BNRG2A1 with SPI clock on D13 */
/*#define SpiHCI SPI
HCISpiTransportClass HCISpiTransport(SpiHCI, BLUENRG_M2SP, A1, A0, D7, 1000000, SPI_MODE1);
BLELocalDevice BLE(&HCISpiTransport); */
#endif

void setup() {
Serial.begin(9600);
Serial.begin(115200);
while (!Serial);

// begin initialization
Expand All @@ -32,7 +60,16 @@ void setup() {
BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler);

// start scanning for peripherals with duplicates
BLE.scan(true);
int ret = 1;
do
{
ret = BLE.scan(true);
if (ret == 0)
{
BLE.end();
BLE.begin();
}
} while(ret == 0);
}

void loop() {
Expand Down
Loading

0 comments on commit 04a895f

Please sign in to comment.