Noob Help - Bluetooth DAQ Project using the Bluno Beetle - Part 2
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
Hello everyone,
I'm following up on a previous post: viewtopic.php?f=18&t=15410&p=28386#p27256
In short - I want to record various physiological signals using the Bluno Beetle and transmit them via bluetooth to a PC (with a USB Bluetooth link dongle) where they will be stored for offline processing.
I'm making progress and learning despite being a complete noob at Arduino and microcontrollers in general.
I've managed to send 4 analog inputs measured by the bluno beetle via BT to my laptop which plots them in real time using the Serial Plotter. I've also managed to impose a sampling frequency - a fixed/constant frequency at which I read and send my analog samples. I did this by basically measuring the current time, and when the current time exceeds a fixed, pre-defined, sampling interval, I take new samples and send them. So far so good.
The problem is in the stability of the transmission. My serial monitor looks like this:
10:55:54.624 -> 200 0 0 0 293
10:55:54.624 -> 2000 0 0 0 292
10:55:54.658 -> 2000 0 0 2000 0 0 0 293
10:55:54.658 -> 2000 0 0 0 293
10:55:54.658 -> 2000 2000 0 0 0 293
10:55:54.658 -> 2000 0 0 0 293
10:55:54.658 -> 2000 0 0 293
10:55:54.658 -> 2000 0 0 0 292
10:55:54.692 -> 2000 0 0 0 2900 0 0 0 293
10:55:54.692 -> 2000 0 0 0 293
10:55:54.692 -> 2000 0 94
10:55:54.692 -> 2000 0 0 0 292
10:55:54.692 -> 2000 0 0 0 292
10:55:54.692 -> 202000 0 0 0 294
10:55:54.726 -> 2000 0 0 0 293
10:55:54.726 -> 2000 000 0 0 0 292
From left to right, the columns should be: the time stamp, the delta between the current and previous sample in ms (for 500Hz it should always be 2000ms), A0, A1, A2, A3.
The values are correct, but as you can see, they are not stable - they jump all over the place and "overlap" messing the values up.
The code used is the following:
My first though as to why the serial monitor is unstable was insufficient baud rate. I'm running at 115200 baud rate. So (if I'm not mistaken) that's 115200 bits per second. Which for 2ms (fs=500Hz) corresponds to 230 bits per 2ms.
I'm sending across the serial:
- four ints corresponding to the analog inputs(4 x 16bits = 64 bits)
- one int corresponding to the time delta (1 x 16bits)
- five '\t' characters (this is a char so its a byte right? - 5x8=48 bits)
This adds up to 128, so its not really near to my calculated baud rate limit. I even tried changing everything to bytes to cut my total by 40 bits but that doesn't help. Also, if I connect the Bluno Beetle to the laptop via a USB and I use the same code and same baud rate, the serial monitor becomes stable:
11:12:46.708 -> 2004 0 0 0 37
11:12:46.708 -> 2004 0 0 0 35
11:12:46.708 -> 2004 0 0 0 35
11:12:46.708 -> 2004 0 0 0 37
11:12:46.708 -> 2000 0 0 0 37
11:12:46.708 -> 2000 0 0 0 37
11:12:46.708 -> 2000 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
11:12:46.741 -> 2000 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
So I'm not sure anymore this has to do with baud rate. Any pointers? Ideas? Help?
Thank you!
R
I'm following up on a previous post: viewtopic.php?f=18&t=15410&p=28386#p27256
In short - I want to record various physiological signals using the Bluno Beetle and transmit them via bluetooth to a PC (with a USB Bluetooth link dongle) where they will be stored for offline processing.
I'm making progress and learning despite being a complete noob at Arduino and microcontrollers in general.
I've managed to send 4 analog inputs measured by the bluno beetle via BT to my laptop which plots them in real time using the Serial Plotter. I've also managed to impose a sampling frequency - a fixed/constant frequency at which I read and send my analog samples. I did this by basically measuring the current time, and when the current time exceeds a fixed, pre-defined, sampling interval, I take new samples and send them. So far so good.
The problem is in the stability of the transmission. My serial monitor looks like this:
10:55:54.624 -> 200 0 0 0 293
10:55:54.624 -> 2000 0 0 0 292
10:55:54.658 -> 2000 0 0 2000 0 0 0 293
10:55:54.658 -> 2000 0 0 0 293
10:55:54.658 -> 2000 2000 0 0 0 293
10:55:54.658 -> 2000 0 0 0 293
10:55:54.658 -> 2000 0 0 293
10:55:54.658 -> 2000 0 0 0 292
10:55:54.692 -> 2000 0 0 0 2900 0 0 0 293
10:55:54.692 -> 2000 0 0 0 293
10:55:54.692 -> 2000 0 94
10:55:54.692 -> 2000 0 0 0 292
10:55:54.692 -> 2000 0 0 0 292
10:55:54.692 -> 202000 0 0 0 294
10:55:54.726 -> 2000 0 0 0 293
10:55:54.726 -> 2000 000 0 0 0 292
From left to right, the columns should be: the time stamp, the delta between the current and previous sample in ms (for 500Hz it should always be 2000ms), A0, A1, A2, A3.
The values are correct, but as you can see, they are not stable - they jump all over the place and "overlap" messing the values up.
The code used is the following:
Code: Select all
#define sampling_interval_hemo_us 2000U // The imposed sampling interval for the hemodynamic channels, in microseconds. 1000us -> fs= 1kHz. 2000us -> fs=500Hz. 1428us -> 700Hz.
// For the hemodynamic channels
unsigned long previous_micros_hemo = 0;
unsigned long delta_micros_hemo = 0;
unsigned int val_a0 = 0;
unsigned int val_a1 = 0;
unsigned int val_a2 = 0;
unsigned int val_a3 = 0;
void setup() {
Serial.begin(115200); // initialize serial communication at 115200 bits per second.
}
void loop()
{
delta_micros_hemo = micros() - previous_micros_hemo; // The time difference between the current time and the previous hemodynamic sample.
if ((delta_micros_hemo) >= sampling_interval_hemo_us) // If the delta is bigger than the hemodynamic sampling_interval -> Take new hemodynamic samples!
{
Serial.flush();
Serial.print(delta_micros_hemo, 1); // 1 is the number of decimals to print
Serial.print('\t');
val_a0 = analogRead(A0);
val_a1 = analogRead(A1);
val_a2 = analogRead(A2);
val_a3 = analogRead(A3);
Serial.print('\t'); Serial.print(val_a0);
Serial.print('\t'); Serial.print(val_a1);
Serial.print('\t'); Serial.print(val_a2);
Serial.print('\t'); Serial.println(val_a3);
previous_micros_hemo = micros();
}
}
My first though as to why the serial monitor is unstable was insufficient baud rate. I'm running at 115200 baud rate. So (if I'm not mistaken) that's 115200 bits per second. Which for 2ms (fs=500Hz) corresponds to 230 bits per 2ms.
I'm sending across the serial:
- four ints corresponding to the analog inputs(4 x 16bits = 64 bits)
- one int corresponding to the time delta (1 x 16bits)
- five '\t' characters (this is a char so its a byte right? - 5x8=48 bits)
This adds up to 128, so its not really near to my calculated baud rate limit. I even tried changing everything to bytes to cut my total by 40 bits but that doesn't help. Also, if I connect the Bluno Beetle to the laptop via a USB and I use the same code and same baud rate, the serial monitor becomes stable:
11:12:46.708 -> 2004 0 0 0 37
11:12:46.708 -> 2004 0 0 0 35
11:12:46.708 -> 2004 0 0 0 35
11:12:46.708 -> 2004 0 0 0 37
11:12:46.708 -> 2000 0 0 0 37
11:12:46.708 -> 2000 0 0 0 37
11:12:46.708 -> 2000 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
11:12:46.741 -> 2000 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
11:12:46.741 -> 2004 0 0 0 37
So I'm not sure anymore this has to do with baud rate. Any pointers? Ideas? Help?
Thank you!
R