How to improve the frequency of the BLE

Hello everyone,
I’m trying to send a signal from my Arduino nano 33 BLE to my PC, the Signal is 200Hz, but the BLE didn’t go that far.
How can I manipulate the BLE to get them to communicate with 200Hz or even more.
I’ve tried to use the function BLE.setConnectionInterval( , ), but it did’t work for more the 100Hz (BLE.setConnectionInterval(8,8 )).

#include <ArduinoBLE.h>

//Signalauslesen
int Pin = A0;

//Tiefpass-Filter Koeffizienten
float a0TP = 0.20657128726265578 ;
float a1TP = 0.41314257452531156;
float a2TP = 0.20657128726265578;
float b1TP = 0.36952595241514796;
float b2TP = 0.19581110146577102;

//Noach-Filter Koeffizienten
float a0 = 0.5857841106784856 ;
float a1 = 1.3007020142696517e-16;
float a2 = 0.5857841106784856;
float b1 = 1.3007020142696517e-16;
float b2 = 0.17156822135697122;

// EingangsSignale Notch
int eingangsSignal = 0.0;
int ES_a1 = 0.0;
int ES_a2 = 0.0;

//EingangsSignale TP
int ES_a1TP = 0.0;
int ES_a2TP = 0.0;

//AusgangsSignale Notch
int ausgangsSignal = 0.0;
int AS_b1 = 0.0;
int AS_b2 = 0.0;

//AusgangsSignale TP
int ausgangsSignalTP = 0.0;
int AS_b1TP = 0.0;
int AS_b2TP = 0.0;

// BLE Arduino Service
BLEService SignalService(“19B10010-E8F2-537E-4F6C-D104768A1214”);
// BLE Signal Characteristic
BLEUnsignedCharCharacteristic characteristicSignal(“19B10011-E8F2-537E-4F6C-D104768A1214”, // standard 16-bit characteristic UUID
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes

void setup() {
pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected
//begin initialization
if (!BLE.begin()) {
while (1);
}
BLE.setLocalName(“Test-Nano-33”);
BLE.setAdvertisedService(SignalService); // add the service UUID
SignalService.addCharacteristic(characteristicSignal); // add the Signal characteristic
BLE.addService(SignalService); // Add the Arduino service
// characteristicSignal.writeValue(oldValue); // set initial value for this characteristic

/* Start advertising BLE. It will start continuously transmitting BLE
advertising packets and will be visible to remote BLE central devices
until it receives a new connection */
BLE.setAdvertisingInterval(32);
BLE.setConnectionInterval(8, 8); // 1/(8 * 1.25ms)
BLE.advertise();
}

void loop() {
BLEDevice central = BLE.central();
//if a central is connected to the peripheral:
if (central) {
//turn on the LED to indicate the connection:
digitalWrite(LED_BUILTIN, HIGH);
// while the central is connected:
while (central.connected()) {
EKG();
// kurze Delay um die Daten zu verarbeiten
delayMicroseconds(5000);
}
//when the central disconnects, turn off the LED:
digitalWrite(LED_BUILTIN, LOW);
}
}

void EKG() {
eingangsSignal = analogRead(Pin);
ausgangsSignal = (eingangsSignal * a0) - (ES_a1 * a1) + (ES_a2 * a2) + (AS_b1 * b1) - (AS_b2 * b2);

//Eingangssignale-Notch speichern
ES_a2 = ES_a1;
ES_a1 = eingangsSignal;
//Ausgangssignale-Notch speichern
AS_b2 = AS_b1;
AS_b1 = ausgangsSignal;

//Tiefpass Filterung
ausgangsSignalTP = (ausgangsSignal * a0TP) + (ES_a1TP * a1TP) + (ES_a2TP * a2TP) + (AS_b1TP * b1TP) - (AS_b2TP * b2TP);

//Eingangssignale-TP speichern
ES_a2TP = ES_a1TP;
ES_a1TP = ausgangsSignal;
//Ausgangssignale-TP speichern
AS_b2TP = AS_b1TP;
AS_b1TP = ausgangsSignalTP;

characteristicSignal.writeValue(ausgangsSignalTP); // and update the Signal characteristic //ueber Bluetooth darstellen
Serial.println(ausgangsSignalTP);
}

Welcome to the forum

First an unofficial warning. Please do not cross post. It is against the forum rules. It wastes time of people who spend their free time to help. I recommend you modify your second post before an admin finds it.

Second please read the General guidance and How to use this forum. It will help you get good answers by creating a good post. e.g. use code tags. Try to modify your original post above to make your code appear like this.

Example code

Now regarding your issues:

  • Do not use delay(). It will ether just waste processing cycles which could be used for something useful or for the Nano 33 BLE use sleep which is equally not what you want. Have a look at the following example to learn how to time parts of your code without stopping everything else.

File -> Examples -> 02.Digital -> BlinkWithoutDelay

This will be the most important thing you will every learn for Arduino.

  • BLE sends data in packets. When you want to increase throughput you can create a compound characteristic that transfers multiple values in a single packet. I will try to add a link to an example I posted in the forum a while ago. See reply #32 in the following post.
  • Try to make your data size as small as needed. e.g. 16 bit integer instead of float. This will allow you to get more data values into a packet.

The following comment is wrong

BLEUnsignedCharCharacteristic characteristicSignal("19B10011-E8F2-537E-4F6C-D104768A1214", // standard 16-bit characteristic UUID

This is a 128-bit UUID. But good that you made use of it because you should only use 16-bit UUIDs for Bluetooth SiG standardized characteristics and services.

Pro Tip: Try to avoid programming in 3 languages. :slight_smile: This will reduce the number of programmers that can read your code and help you effectively.

Looks like an interesting project. What are you using on the PC side?

Thank you very much, I took all your advice and it was so helpful.
I hope it’s okay for you that I took some ideas from your program.
I had to use “uint8_t” as data type to make the BLE go faster.
I receive the data on my PC with “p5.js” (javascript), I am trying to build a Serial Monitor with BLE.

#include <ArduinoBLE.h>
#define BLE_UUID_DATA_SERVICE                 "180D" // standard 16-bit Service UUID for Heart Rate
#define BLE_UUID_DATA_Characteristic          "2A37" // standard 16-bit characteristic UUID for Heart Rate Measurement

const long interval = 5;           // interval at which to measure up (milliseconds)
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time the EKG was updated

//Signalauslesen
int Pin = A0;

//Lowpass-Filter coefficient
float a0TP = 0.20657128726265578 ;
float a1TP = 0.41314257452531156;
float a2TP = 0.20657128726265578;
float b1TP = 0.36952595241514796;
float b2TP = 0.19581110146577102;

//Noach-Filter coefficient
float a0 = 0.5857841106784856 ;
float a1 = 1.3007020142696517e-16;
float a2 = 0.5857841106784856;
float b1 = 1.3007020142696517e-16;
float b2 = 0.17156822135697122;

// Entry Signal Notch_Filter
int EntrySignal = 0.0;
int ES_a1 = 0.0;
int ES_a2 = 0.0;

//Entry Signal Lowpass_Filter
int ES_a1TP = 0.0;
int ES_a2TP = 0.0;

//output Signal Notch_Filter
int OutpusSignal = 0.0;
int AS_b1 = 0.0;
int AS_b2 = 0.0;

//output Signal Lowpass_Filter
int OutputSignalLP = 0.0;
int AS_b1TP = 0.0;
int AS_b2TP = 0.0;

//The data to send
uint8_t OutputSignalLPMod = 0;
//----------------------------------------------------------------------------------------------------------------------
// BLE
//----------------------------------------------------------------------------------------------------------------------
// BLE Arduino Service
BLEService SignalService(BLE_UUID_DATA_SERVICE);
// BLE Signal Characteristic
BLECharacteristic characteristicSignal(BLE_UUID_DATA_Characteristic,  
                                       BLERead | BLENotify, sizeof OutputSignalLPMod); // remote clients will be able to get notifications if this characteristic changes



void setup() {
  pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected
  //Set up BLE
  setupBleMode();
}

void loop() {
  unsigned long currentMillis = millis();
  BLEDevice central = BLE.central();
  //if a central is connected to the peripheral:
  if (central) {
    //turn on the LED to indicate the connection:
    digitalWrite(LED_BUILTIN, HIGH);
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      EKG();
    }
    //when the central disconnects, turn off the LED:
    digitalWrite(LED_BUILTIN, LOW);
  }
}

void EKG() {
  EntrySignal = analogRead(Pin);
  OutpusSignal = (EntrySignal * a0) - (ES_a1 * a1) + (ES_a2 * a2) + (AS_b1 * b1) - (AS_b2 * b2);

  //Entry Signals -Notch to save
  ES_a2 = ES_a1;
  ES_a1 = EntrySignal;
  //Output Signals -Notch to save
  AS_b2 = AS_b1;
  AS_b1 = OutpusSignal;

  //Lowpass Filter
  OutputSignalLP = (OutpusSignal * a0TP) + (ES_a1TP * a1TP) + (ES_a2TP * a2TP) + (AS_b1TP * b1TP) - (AS_b2TP * b2TP);

  //Entry Signals LP to save
  ES_a2TP = ES_a1TP;
  ES_a1TP = OutpusSignal;
  //Output Signals LP to save
  AS_b2TP = AS_b1TP;
  AS_b1TP = OutputSignalLP;
  
  OutputSignalLPMod = map(OutputSignalLP, 400 , 800 , 0 , 255);
  
  characteristicSignal.writeValue( OutputSignalLPMod ); //  update the Signal characteristic
  Serial.println(OutputSignalLPMod);
}


bool setupBleMode()
{
  if ( !BLE.begin() )
  {
    return false;
  }

  // set advertised local name and service UUID:
  BLE.setDeviceName( "Arduino Nano 33 BLE EKG" );
  BLE.setLocalName( "Arduino Nano 33 BLE EKG" );
  BLE.setAdvertisedService( SignalService );

  // BLE add characteristics
  SignalService.addCharacteristic( characteristicSignal );

  // add service
  BLE.addService( SignalService );

  // set the initial value for the characeristic:
  characteristicSignal.writeValue(OutputSignalLPMod );

  // set the interval for the communication
  BLE.setConnectionInterval(4, 4); // 1/(4 * 1.25ms) 200 Hz
  // start advertising
  /* Start advertising BLE.  It will start continuously transmitting BLE
     advertising packets and will be visible to remote BLE central devices
     until it receives a new connection */
  BLE.advertise();
  
  return true;
}

@mahmood_alkawarit

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

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