Slow data transfer BLE

I'm using an Arduino Nano 33 BLE Sense Rev2 to record IMU data and send recorded data over BLE to my laptop. I have working code, but the transfer is really slow (17 minutes for 8000 samples of 18 bytes) and I'm hoping for tips on how to speed it up.

I'm using a state machine for the Arduino, with an initial state to establish the connection, then up to 8000 samples are recorded and stored locally. After 8000 samples, we switch to the transfer mode and I use one data characteristic to showcase a 18byte array. I write one data sample to the data characteristic, then, after reading the value on my receiver side an acknowledge characteristic is written to communicate back to the Arduino that the value was indeed read, and then the next value is written to the data characteristic on the Arduino side. This is the code for the transfer mode (also, I'm using the ArduinoBLE library) :

    case MODE_TRANSFER: {
      returnMode = MODE_TRANSFER;

      // magenta led
      digitalWrite(BLUE, LOW);
      digitalWrite(RED, LOW);
      digitalWrite(GREEN, HIGH);

      while (!transferComplete && central.connected()) {
        if (ackCharacteristic.written()){
          printLine("Connection verified. Transferring data...");
          dataCharacteristic.writeValue(recordData[recordIndex], 18);
          recordIndex++;
        }
        if (recordIndex == maxData) {
          printLine("Transfer complete");
          transferComplete = true;
        }
      }

      if (transferComplete) {
        recordIndex = 0;
        currentMode = MODE_WAKEUP;
        wakeupTime = millis();
        transferComplete = false;
      } else {
        printLine("Connection lost.");
        currentMode = MODE_CONNECT;
      }
      break;

I'm using bleak, a python package, to control the central device (my laptop). It subscribes to the data characteristic (which has read & notify properties) and when it gets notified it will read the value, write it to a buffer and write to the acknowledge characteristic. When all 8000 values are written to the buffer, it stores all values to a text file.

Btw, I have also tried using another Nano as a central device and let it print the received values to the Serial Monitor. Transfer speeds were comparable.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.