Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve STM32duinoBLE robustness and flexibility #11

Merged
merged 23 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c4f359a
Improve STM32duinoBLE robustness and flexibility
cparata Feb 7, 2020
02ff3a6
SPISettings managements
fpistm Feb 17, 2020
2f22ce9
Replace boolean with standard bool
fpistm Nov 19, 2019
7e7cf88
Fix workflow to build ST targets
fpistm Feb 17, 2020
94a834a
Merge pull request #1 from fpistm/pr-11
cparata Feb 17, 2020
ab1df57
Update examples/Central/PeripheralExplorer/PeripheralExplorer.ino
cparata Feb 17, 2020
19ce615
Update examples/Central/PeripheralExplorer/PeripheralExplorer.ino
cparata Feb 17, 2020
81ff00b
Update examples/Central/LedControl/LedControl.ino
cparata Feb 17, 2020
9f46797
Update examples/Central/LedControl/LedControl.ino
cparata Feb 17, 2020
775a60a
Update examples/Central/Scan/Scan.ino
cparata Feb 17, 2020
f7d45fa
Update examples/Central/Scan/Scan.ino
cparata Feb 17, 2020
c9f4239
Update examples/Central/ScanCallback/ScanCallback.ino
cparata Feb 17, 2020
b598a3f
Update examples/Central/ScanCallback/ScanCallback.ino
cparata Feb 17, 2020
aa6e1b3
Update examples/Central/SensorTagButton/SensorTagButton.ino
cparata Feb 17, 2020
18e0ca1
Update examples/Central/SensorTagButton/SensorTagButton.ino
cparata Feb 17, 2020
fafde93
Update examples/Peripheral/ButtonLED/ButtonLED.ino
cparata Feb 17, 2020
b95942f
Update examples/Peripheral/ButtonLED/ButtonLED.ino
cparata Feb 17, 2020
da2c4fd
Update examples/Peripheral/CallbackLED/CallbackLED.ino
cparata Feb 17, 2020
11bb949
Update examples/Peripheral/CallbackLED/CallbackLED.ino
cparata Feb 17, 2020
d4bb5d8
Update examples/Peripheral/LED/LED.ino
cparata Feb 17, 2020
e53282b
Update examples/Peripheral/LED/LED.ino
cparata Feb 17, 2020
5d789c6
Improve check when BLE chip is not supported
cparata Feb 17, 2020
bd1b0e0
Update keywords.txt with new classes, methods and constants
cparata Feb 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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 */
/*SPIClass SpiHCI(D11, D12, D13);
cparata marked this conversation as resolved.
Show resolved Hide resolved
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