Incompatibility between Bluefruit.h and Adafruit_SPIFlash.h

Hi there,

Using the Xiao nRF52840 in both Peripheral and Central roles simultaneously is possible because the nRF52840 supports concurrent roles in BLE using its SoftDevice. To achieve this, you’ll need to set up the device with both roles enabled and handle the different connections accordingly.

Here’s how you can approach this:
Check out the Adafruit , example in this thread.it has Dual mode and advertises DFU
change the baud rate to 9600 to make it readable
Check out this thread ;

I have seen the demos on the NRF_SDK fo rthis working well too, so If you’re using Arduino IDE, consider transitioning to the nRF5 SDK or nRF Connect SDK (with Zephyr). They provide robust support for configuring the nRF52840 as both Peripheral and Central.

  • nRF5 SDK: Use SoftDevice S140, which allows the nRF52840 to operate as a Central and Peripheral at the same time.
  • nRF Connect SDK: Based on Zephyr RTOS, it has BLE support with multi-role capability.

Using nRF5 SDK

  1. Install the nRF5 SDK.
  2. Use the ble_app_multilink_central and ble_app_multilink_peripheral examples as references.
  3. Merge the examples or use the ble_app_hrs_rscs_relay example, which demonstrates both Central and Peripheral roles.

Using Arduino IDE

The Arduino BLE libraries may have limited support for concurrent roles. You might need to:

  1. Use the Adafruit Bluefruit nRF52 library (but verify if dual-role support is sufficient for your needs).
  2. Write custom firmware for concurrent Central and Peripheral using the nRF5 SDK.

II was testing with this code also.

#include <Arduino.h>
#include <LSM6DS3.h>
#include <bluefruit.h>
#include <Wire.h>
#include <U8x8lib.h>
LSM6DS3 IMU;  //I2C device address 0x6A  // IMU
#define int2Pin PIN_LSM6DS3TR_C_INT1
float aX, aY, aZ, gX, gY, gZ;
String timeDateStamp = (" __TIME____DATE__" ); 
// Initialize BLE
BLEUart bleUart;  // Peripheral
BLEClientUart clientUart; // Central

void setup() {
  // Start Serial
  Serial.begin(9600);
  while (!Serial) delay(10); // Wait for Serial to initialize
  Serial.println("Starting BLE example...");

  // Peripheral Role
  Bluefruit.begin();
  Bluefruit.setName("Xiao_Peripheral");
  bleUart.begin();
  Bluefruit.Advertising.start();

  // Central Role
  Bluefruit.Central.begin();
  Bluefruit.Central.setConnectCallback(central_connect_callback);
  Bluefruit.Central.setDisconnectCallback(central_disconnect_callback);
  Bluefruit.Scanner.setRxCallback(scanner_callback);
  Bluefruit.Scanner.start(0); // Continuously scan
}

void loop() {
  // No need for poll() for BLEUart
}

void central_connect_callback(uint16_t conn_handle) {
  Serial.println("Connected as Central!");
}

void central_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
  Serial.println("Disconnected as Central!");
}

void scanner_callback(ble_gap_evt_adv_report_t* report) {
  Serial.print("Found device: ");

  // Print the MAC address (6 bytes in reverse order)
  for (int i = 5; i >= 0; i--) {
    Serial.print(report->peer_addr.addr[i], HEX);
    if (i > 0) Serial.print(":");
  }
  Serial.println(); // New line after MAC address
}

HTH
GL :slight_smile: PJ :v:

P.s I would start a New thread If You need more info in the Dual role scenarios. Tnx. :+1: