This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bluetooth connection between Arduino NANO 33 BLE Sense and NRF52840 DK

CENTRAL :  nrf52840 DK
    -SDK 15.3
    -SES 5.40
    -s140

PERIPHERAL :  Arduino NANO 33 BLE Sense

 

Hello, I'd like to deliver the Arduino's sensor data to DK board via Bluetooth.

Is it possible to connect with the arduino BLE using the example ble_app_uart_c on the DK board?

I used LED.ino, the default example of ARDUINO ble peripheral, but I couldn't connect with the central (DK board).

Do I have to use a different code?

Or can't I connect the two boards?

Or is i2c connection easier than ble connection?

#include <ArduinoBLE.h>

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

const int ledPin = LED_BUILTIN; // pin to use for the LED

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

  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("LED");
  BLE.setAdvertisedService(ledService);

  // add the characteristic to the service
  ledService.addCharacteristic(switchCharacteristic);

  // add service
  BLE.addService(ledService);

  // set the initial value for the characeristic:
  switchCharacteristic.writeValue(0);

  // start advertising
  BLE.advertise();

  Serial.println("BLE LED Peripheral");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, HIGH);         // will turn the LED on
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin, LOW);          // will turn the LED off
        }
      }
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

  • I'd like to deliver the Arduino's sensor data to DK board via Bluetooth

    The whole point about Standards like BLE is that it is entirely independent of what hardware is used.

    The communication is entirely defined by the GATT Characteristics and Services.

    Is it possible to connect with the arduino BLE using the example ble_app_uart_c on the DK board?

    You need to find out the GATT Characteristics and Services used by the Arduino - and use that.

    If that happens to be the proprietary Nordic UART Service (NUS)  then, of course, the NUS Central will work - and, if it's not, then it won't!

    If NUS is used, it is just a "stream" of arbitrary data - so you will still need to consult the Arduino documentation to see how they've formatted/structured the sensor data over the NUS link.

    For Arduino support, you will need to go to the Arduino forums, and/or the board manufacturer.

Related