I am trying to measure data from a vibration sensor at 10 kHz and transmit to a central over BLE. I can reach that sampling rate with no problem when I try to transmit it over serial to the computer, but when I start a BLE, even without any connection, I get a lot of delays that cause my sampling to miss the sample deadline. This code visualizes it.
#include <ArduinoBLE.h>
#define T 100
#define BUFFSZ 512
unsigned short buff [BUFFSZ];
const char* deviceServiceUuid = "ab6f99b3-4127-4d63-884a-d19fc6f4e98d";
const char* deviceServiceCharacteristicUuid = "c7600e82-ba43-4f24-82c7-64b0db67abf1";
BLEService audioService(deviceServiceUuid); // Define a service
BLECharacteristic audioCharacteristic(deviceServiceCharacteristicUuid, BLEWrite | BLERead , BUFFSZ);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial);
analogReadResolution(12);
if (!BLE.begin()) {
Serial.println("Failed to initialize BLE!");
while (1);
}
BLE.setLocalName("BaboonCollar");
BLE.setAdvertisedService(audioService);
audioService.addCharacteristic(audioCharacteristic);
BLE.addService(audioService);
BLE.advertise();
Serial.println("Nano 33 BLE (Peripheral Device)");
Serial.println(" ");
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long begin = micros();
int read = analogRead(A0);
if (micros() - begin > T)
Serial.println(micros() - begin);
while (micros() - begin < T);
}
I know of a great guide about how to do non-blocking ADC sampling, but using that messes up the BLE. Is there anything I can do or will I have to try a different chip outside arduino?