XIAO nrf52840 sense

Recently got a sense board. Amazing how small it is!

But I’ve had inconsistent luck with the board. uploads always complete, but uploading the exact same code worked one time then not the next…

I’ve gotten the adafruit keyboard example to work, as well as Seeed’s code for turning the LED on/off over bluetooth. (once each, now it’s unrecoverable)

The issue is I’m rarely able to discover it with my phone. It just won’t pop up.

Any help is appreciated thanks!

HI, have you replaced your phone and tested it?

yep, unfortunately so.

Which code are you using and can you paste it out?

the keyboard example worked once as well, but after changing no variables I’m aware of, it works no longer.

from: For Seeed nRF52 Boards Library - Seeed Wiki

#include <bluefruit.h>

BLEClientBas clientBas; // battery client
BLEClientDis clientDis; // device information client
BLEClientUart clientUart; // bleuart client

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

void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb

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

Serial.println(“Bluefruit52 Central BLEUART Example”);
Serial.println("-----------------------------------\n");

// Initialize Bluefruit with maximum connections as Peripheral = 0, Central = 1
// SRAM usage required by SoftDevice will increase dramatically with number of connections
Bluefruit.begin(0, 1);

Bluefruit.setName(“Bluefruit52 Central”);

// Configure Battery client
clientBas.begin();

// Configure DIS client
clientDis.begin();

// Init BLE Central Uart Serivce
clientUart.begin();
clientUart.setRxCallback(bleuart_rx_callback);

// Increase Blink rate to different from PrPh advertising mode
Bluefruit.setConnLedInterval(250);

// Callbacks for Central
Bluefruit.Central.setConnectCallback(connect_callback);
Bluefruit.Central.setDisconnectCallback(disconnect_callback);

/* Start Central Scanning

    • Enable auto scan if disconnected
    • Interval = 100 ms, window = 80 ms
    • Don’t use active scan
    • Start(timeout) with timeout = 0 will scan forever (until connected)
      */
      Bluefruit.Scanner.setRxCallback(scan_callback);
      Bluefruit.Scanner.restartOnDisconnect(true);
      Bluefruit.Scanner.setInterval(160, 80); // in unit of 0.625 ms
      Bluefruit.Scanner.useActiveScan(false);
      Bluefruit.Scanner.start(0); // // 0 = Don’t stop scanning after n seconds
      }

/**

  • Callback invoked when scanner pick up an advertising data

  • @param report Structural advertising data
    /
    void scan_callback(ble_gap_evt_adv_report_t
    report)
    {
    // Check if advertising contain BleUart service
    if ( Bluefruit.Scanner.checkReportForService(report, clientUart) )
    {
    Serial.print("BLE UART service detected. Connecting … ");

    // Connect to device with bleuart service in advertising
    Bluefruit.Central.connect(report);
    }else
    {
    // For Softdevice v6: after received a report, scanner will be paused
    // We need to call Scanner resume() to continue scanning
    Bluefruit.Scanner.resume();
    }
    }

/**

  • Callback invoked when an connection is established
  • @param conn_handle
    */
    void connect_callback(uint16_t conn_handle)
    {
    Serial.println(“Connected”);

Serial.print("Dicovering Device Information … ");
if ( clientDis.discover(conn_handle) )
{
Serial.println(“Found it”);
char buffer[32+1];

// read and print out Manufacturer
memset(buffer, 0, sizeof(buffer));
if ( clientDis.getManufacturer(buffer, sizeof(buffer)) )
{
  Serial.print("Manufacturer: ");
  Serial.println(buffer);
}

// read and print out Model Number
memset(buffer, 0, sizeof(buffer));
if ( clientDis.getModel(buffer, sizeof(buffer)) )
{
  Serial.print("Model: ");
  Serial.println(buffer);
}

Serial.println();

}else
{
Serial.println(“Found NONE”);
}

Serial.print("Dicovering Battery … ");
if ( clientBas.discover(conn_handle) )
{
Serial.println(“Found it”);
Serial.print(“Battery level: “);
Serial.print(clientBas.read());
Serial.println(”%”);
}else
{
Serial.println(“Found NONE”);
}

Serial.print("Discovering BLE Uart Service … ");
if ( clientUart.discover(conn_handle) )
{
Serial.println(“Found it”);

Serial.println("Enable TXD's notify");
clientUart.enableTXD();

Serial.println("Ready to receive from peripheral");

}else
{
Serial.println(“Found NONE”);

// disconnect since we couldn't find bleuart service
Bluefruit.disconnect(conn_handle);

}
}

/**

  • Callback invoked when a connection is dropped
  • @param conn_handle
  • @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
    */
    void disconnect_callback(uint16_t conn_handle, uint8_t reason)
    {
    (void) conn_handle;
    (void) reason;

Serial.print(“Disconnected, reason = 0x”); Serial.println(reason, HEX);
}

/**

  • Callback invoked when uart received data
  • @param uart_svc Reference object to the service where the data
  • arrived. In this example it is clientUart
    */
    void bleuart_rx_callback(BLEClientUart& uart_svc)
    {
    Serial.print("[RX]: ");

while ( uart_svc.available() )
{
// Serial.print( (char) uart_svc.read() );
if ((char)uart_svc.read() == ‘1’) { // 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
}
}

Serial.println();
}

void loop()
{
if ( Bluefruit.Central.connected() )
{
// Not discovered yet
if ( clientUart.discovered() )
{
// Discovered means in working state
// Get Serial input and send to Peripheral
if ( Serial.available() )
{
delay(2); // delay a bit for all characters to arrive

    char str[20+1] = { 0 };
    Serial.readBytes(str, 20);

    clientUart.print( str );
  }
}

}
}

alright. got it to work. But god damn was it convoluted.

curious, are you running m-bed or non mbed board

Curious why you used blue fruit. Csnt the BLE sense do keyboard as well without another board?