Hello,
I am trying to read data from UART and display but only first byte is read: 100 packet / second = 8000bits/s
No problem, 1 packet / second rate.
I tried baudrate 9600 and 115200.
Any idea?
Thank you.
Hello,
I am trying to read data from UART and display but only first byte is read: 100 packet / second = 8000bits/s
No problem, 1 packet / second rate.
I tried baudrate 9600 and 115200.
Any idea?
Thank you.
Any idea?
You posted no code. You did not explain what is sending the data. You did not explain how you know the Arduino is "stuck".
So, no, I have no idea how to help you.
Sorry, PaulS
My code:
#define SERIAL_BUFFER_SIZE 16
#define SIGNIFICANT_FIGURES 10
#define SERIAL_BAUDRATE 115200
#define SAMPLE_SIZE 15000
void print_results() {}
int real_time_mean() {}
char buffer_serial[16];
byte ds_i = 0;
unsigned int total_samples = 0;
void setup() {
Serial.begin(SERIAL_BAUDRATE);
while(!Serial) {}
Serial.print("Sample size: ");
Serial.println(SAMPLE_SIZE);
delay(5000);
Serial.flush();
}
void loop() {
if (total_samples < SAMPLE_SIZE - 1) {
//
}
else {
total_samples = 0;
// print_results();
}
if (Serial.available() > 0 ) {
buffer_serial[ds_i++] = (char) Serial.read();
if (buffer_serial[ds_i - 1] == '\n') {
total_samples = total_samples + 1;
Serial.print("Sample ");
Serial.print(total_samples);
Serial.print(": ");
Serial.println(atof(buffer_serial));
// err = real_time_mean();
ds_i = 0;
}
}
}
}
RESULTS
Sample size: 15000
Sample 1: 1551599.00
Sample 2: 1390301.00
Sample 3: 1217744.00
Sample 4: 1054522.00
Sample 5: 910601.00
Sample 6: 795179.00
.....
Sample size: 15000
Sample 1: 0.00
Sample 2:
-215647.00
Sample 3: -2416445.00
Sample 4: -3
454754.00
Sample 5: -2502710.00
Sample 6: -183
856.00
Sample 7: 21030.00
Sample 8: 0.00
Samp
le 9: 0.00
Sample 10: 0.00
....
Sample 500: 0.00
To make it easy for people to help you please modify your post and use the code button </>
so your code looks like this
and is easy to copy to a text editor. See How to use the Forum
In the meantime have a look at the examples in Serial Input Basics - simple reliable ways to receive data.
By the way, the baud rate determines the number of bits per second.
...R
That code does not compile;; it has a } too many (or is missing a {), your call.
You have not added a terminating nul character to your buffer. After Arduino reset, the buffer is filled with zeroes and you will have a nul-terminated character array. After you have received the data and printed it, you reset ds_i but do not clear the buffer.
ds_i = 0;
// add the below to clear the buffer
memset(buffer_serial, 0, sizeof(buffer_serial));
Or nul-terminate the received data before converting
if (buffer_serial[ds_i - 1] == '\n') {
// nul-terminate by replacing '\n' by '\0'
buffer_serial[ds_i - 1] = '\0';
...
...
}
It might not be the cause of the problem though.