I'm trying to acquire ECG data using Arduino and stream the values to Android smartphone in a real time over BLE. It works fine, but I have a problem that ble_write function is really slow (I'm using RedBear Lab BLE shield and its SDK). I need to have at least 100 samples per second (or more than that), but the best I could get is about 20 when I'm doing acquiring and sending every sample after reading it on the Arduino. Is there any better approach or way how to do this and how to have all recorded samples on the smartphone side?
Thank you in advance
Without seeing your code, we can only guess at what the problem is. I'm going to guess that it is your code.
I'm using RedBearLab BLEShield SimpleControls.ino example file for analog read.
It is this file: BLEShield/SimpleControls.ino at master · RedBearLab/BLEShield · GitHub
And the problem is around line 96, this is the critical part:
if (analog_enabled) // if analog reading enabled
// Read and send out
uint16_t value = analogRead(ANALOG_IN_PIN);
ble_write(value >> 8);
and when I comment out ble_write lines I got more than 1000 entries per second, but with these lines uncommented, the maximum is around 20 lines (values read) per second.
and when I comment out ble_write lines I got more than 1000 entries per second
I find that difficult to believe. Sending 1000 samples per second to the serial port, and rates that the Serial Monitor application can handle, just isn't practical.
The relevant part of any response, in the absence of full code:
Are there any other ways to do this? I just want to be able to receive as much as possible values per second on the smartphone and I cannot find a right way to do this.
It sounds like a dog-chasing-car situation, and perhaps the first thing to do is work out what you are going to do with 1000 entries a second once you get them.
I just need to forward (under some conditions) ECG signal values from the sensor to smartphone (over BLE shield mounted to Arduino).