BLE maximal sampling rate Arduino Nano BLE Sense

Hello,

I am wondering what is the maximal sampling rate of date sent by BLE. Here are my codes for a MAX30102 sensor connected to an Arduino Nano BLE 33 Sense.

I get a data every 0.05s eg a sampling rate of around 20 Hz. Does anyone have managed to reach a higer sampling rate? Does anyone know if an android app is made, the sampling rate could be better?

Thanks

central

/*
  BLE_Central_Device.ino

 /*
 * Device: Arduino Nano 33 BLE Sense
 * Central
 * The values of the integrated temperature sensor and 
 * accelerometer of another Nano 33 BLE are received using BLE.
 */

#include <ArduinoBLE.h>

int const d_r=1;

int32_t r = 0;

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

  if (!BLE.begin()) {
    Serial.println("* Starting BLE module failed!");
    while (1);
  }

  BLE.setLocalName("Arduino XYZT (Central)"); 
  Serial.println("Arduino XYZT (Central)");
  Serial.println(" ");
}

void loop() {
 BLE.scan();
 BLEDevice peripheral = BLE.available();

 //Serial.println("- Discovering peripheral device...");

//  do
//  {
//    BLE.scanForUuid("1101");
//    peripheral = BLE.available();
//  } while (!peripheral);

  if (peripheral) {
    Serial.print("Found ");
    Serial.print(peripheral.address());
    Serial.print(" '");
    Serial.print(peripheral.localName());
    Serial.print("' ");
    Serial.print(peripheral.advertisedServiceUuid());
    Serial.println();
    
    if (peripheral.localName() == "Arduino XYZT (peripheral)") {
      // stop scanning
      BLE.stopScan();
      connectPeripheral(peripheral);
      
  while (peripheral.connect()) {
  
    //BLECharacteristic TChar = peripheral.characteristic( "2104" );
    BLEService service = peripheral.service("1101");
    Serial.print("Service ");
    Serial.print(service.uuid());
        
    BLECharacteristic Rchar = service.characteristic("2107");
    readCharacteristicValue(Rchar);  
    } 
  }
}
}

void connectPeripheral(BLEDevice peripheral) {
      if (peripheral.connect()) {
       Serial.println("Connected");
       } else {
       Serial.println("Failed to connect!");
       return;
      }
      
     // discover peripheral attributes
      Serial.println("Discovering attributes ...");
      if (peripheral.discoverAttributes()) {
      Serial.println("Attributes discovered");
      } else {
      Serial.println("Attribute discovery failed!");
      peripheral.disconnect();
      return;
      }
      
     // read and print device name of peripheral
     Serial.println();
     Serial.print("Device name: ");
     Serial.println(peripheral.deviceName());
     Serial.print("Appearance: 0x");
     Serial.println(peripheral.appearance(), HEX);
     Serial.println();
}


void readCharacteristicValue(BLECharacteristic Rchar) {

          //readCharacteristicValue(characteristic);
    Serial.print("\tR characteristic ");
    Serial.print(Rchar.uuid());
    // check if the characteristic is readable
    if (Rchar.canRead()) {
      //read the characteristic value
      
      Rchar.readValue(&r,4);
      Serial.print(", r = ");
      Serial.println((float)r/pow(10,d_r));
    }
    else {
      Serial.println(" ");
    }
}

peripheral

/*
* Device: Arduino Nano 33 BLE Sense
* Peripheral
* The values of the integrated temperature sensor and 
* accelerometer are sent using BLE.
* created from sketch_nanoBLEsense33_BLE_acc_T_peripheral_v9_MAX30102
*/

#include <ArduinoBLE.h>
#include <Arduino_LSM9DS1.h> //accelerometer sensor
#include <Arduino_HTS221.h> // temperature sensor
#include <Wire.h>
#include "MAX30105.h"

MAX30105 particleSensor;

int const d_t=0; //number of decimal to keep for the temperature
int const d_ir=0;
int const d_a=2;

//float values read by the sensor
float tSensor=25;
float irSensor=0;
float xSensor=0;
float ySensor=0;
float zSensor=0;

//integer variables to send via BLE
int tBLE=floor(tSensor*pow(10,d_t)+0.5);
int irBLE=floor(irSensor*pow(10,d_ir)+0.5);
int xBLE=xSensor*pow(10,d_a);
int yBLE=ySensor*pow(10,d_a);
int zBLE=zSensor*pow(10,d_a);

int compteur=0;

BLEService SensorService("1101");

BLEUnsignedIntCharacteristic XChar("2101", BLERead | BLENotify);
BLEUnsignedIntCharacteristic YChar("2102", BLERead | BLENotify);
BLEUnsignedIntCharacteristic ZChar("2103", BLERead | BLENotify);
BLEUnsignedIntCharacteristic TChar("2104", BLERead | BLENotify);
BLEUnsignedIntCharacteristic IRChar("2107", BLERead | BLENotify);

void setup() {
 Serial.begin(115200); 

 //initialisation of the accelerometer
 if (!IMU.begin()) {
   Serial.println("Failed to initialize IMU!");
   while (1);
 }

// initialisation of the temperature sensor
 HTS.begin();

 while (!Serial);
 
 pinMode(LED_BUILTIN, OUTPUT);

 //initialisation of the BLE
 if (!BLE.begin()) {
   Serial.println("BLE failed to Initiate");
   //delay(500);
   while (1);
   }
 
 BLE.setLocalName("Arduino XYZT (peripheral)");
 BLE.setAdvertisedService(SensorService);
 
 SensorService.addCharacteristic(TChar);
 SensorService.addCharacteristic(IRChar);
 SensorService.addCharacteristic(XChar);
 SensorService.addCharacteristic(YChar);
 SensorService.addCharacteristic(ZChar);
 BLE.addService(SensorService);

 XChar.writeValue(xBLE);
 YChar.writeValue(yBLE);
 ZChar.writeValue(zBLE);
 TChar.writeValue(tBLE);
 IRChar.writeValue(irBLE);
 
 BLE.advertise();
 
 Serial.println("Arduino XYZT peripheral device is now active, waiting for connections...");

 //initialisation from Example4_HeartBeatPlotter
 Serial.println("Initializing...");

 // Initialize sensor
 if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
 {
   Serial.println("MAX30105 was not found. Please check wiring/power. ");
   while (1);
 }

 //Setup to sense a nice looking saw tooth on the plotter
 byte ledBrightness = 0x1F; //Options: 0=Off to 255=50mA
 byte sampleAverage = 8; //Options: 1, 2, 4, 8, 16, 32
 byte ledMode = 3; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
 int sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
 int pulseWidth = 411; //Options: 69, 118, 215, 411
 int adcRange = 4096; //Options: 2048, 4096, 8192, 16384

 particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings

 //Arduino plotter auto-scales annoyingly. To get around this, pre-populate
 //the plotter with 500 of an average reading from the sensor

 //Take an average of IR readings at power up
 const byte avgAmount = 64;
 long baseValue = 0;
 for (byte x = 0 ; x < avgAmount ; x++)
 {
   baseValue += particleSensor.getIR(); //Read the IR value
 }
 baseValue /= avgAmount;

 //Pre-populate the plotter so that the Y scale is close to IR values
 for (int x = 0 ; x < 500 ; x++)
   Serial.println(baseValue);
}


void loop() {

 Serial.print("inside the void loop \t");
 compteur++;
 Serial.print("compteur void loop \t");
 Serial.println(compteur);

 tSensor=HTS.readTemperature();
 Serial.print(" tSensor \t");
 Serial.println(tSensor);

 irSensor=particleSensor.getIR();
 Serial.print(" irSensor \t");
 Serial.println(irSensor); //Send raw data to plotter

 if (IMU.accelerationAvailable()) {
   IMU.readAcceleration(xSensor, ySensor, zSensor);
   Serial.print("xSensor ");
   Serial.print(xSensor);
   Serial.print(" - ySensor ");
   Serial.print(ySensor);
   Serial.print(" - zSensor ");
   Serial.print(zSensor);
   Serial.print(" - mSensor ");
 }

 BLEDevice central = BLE.central();  
 BLE.advertise();
 
 if (central) {
   Serial.print("Connected to central: ");
   Serial.print("* Device MAC address: ");
   Serial.println(central.address());
   
   digitalWrite(LED_BUILTIN, HIGH);
   
   if (central.connected()) { // doesn't work if it is a while loop

     // send temperature data
     tBLE=floor(tSensor*pow(10,d_t)+0.5);
     Serial.print(" tBLE \t");
     Serial.println(tBLE);

     TChar.writeValue(tBLE);
     Serial.print(" TChar ");
     Serial.println(TChar.value());

     //send IR data
     irBLE=floor(irSensor*pow(10,d_ir)+0.5);
     Serial.print(" irBLE \t");
     Serial.println(irBLE);

     IRChar.writeValue(irBLE);
     Serial.print(" IRChar ");
     Serial.println(IRChar.value());

     //send accelerometer datas
     xBLE=xSensor*pow(10,d_a);
     yBLE=ySensor*pow(10,d_a);
     zBLE=zSensor*pow(10,d_a);
//
     Serial.print("xBLE ");
     Serial.print(xBLE);
     Serial.print(" - yBLE ");
     Serial.print(yBLE);
     Serial.print(" - zBLE ");
     Serial.print(zBLE);
//
     XChar.writeValue(xBLE);
     YChar.writeValue(yBLE);
     ZChar.writeValue(zBLE);
//
     Serial.print("XChar ");
     Serial.print(XChar.value());
     Serial.print(" - YChar ");
     Serial.print(YChar.value());
     Serial.print(" - ZChar ");
     Serial.print(ZChar);
     
     }
   }
 Serial.println("");
 digitalWrite(LED_BUILTIN, LOW);
 //Serial.print("Disconnected from central: ");
 //Serial.println(central.address());



 //delay(1000);
}

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