Time between each serial data

Hi All,

I am printing a serial data at a rate of 9600,I know it is 9600bits per second, but I don’t know how to find the time lapse between each sample, or the moment at which each sample is printed.

I need some thing like:

time 00:00:00.005 date 45
time 00:00:00.006 data 234
time 00:00:00.007 data 48

Please tell, How we can do it?

Thank you.

With the timing functions millis() or micros().

kintali: I am printing a serial data at a rate of 9600,I know it is 9600bits per second, but I don't know how to find the time lapse between each sample, or the moment at which each sample is printed.

You need to post your program.

At 9600 baud there are about 960 characters per second or about 1 millisec between characters.

Why do you need to measure it?

...R

You have to keep a pretty tight polling loop since serial is very happy to buffer characters.

In your example, if you really print all that - even though the output is buffered - you may miss a character.

You might want to dive in to Serial to record the actual time the character arrives and add it to the buffer.

for example:

Serial determines the end of the character and stores it in the buffer. You add code to serial that will record the millis() value and store it as 4 bytes in the buffer.

In loop, every time you read your data, you read the next 4 bytes and concatenate them to create the millis() value when the character arrived.