 # How to Determine Arduino UNO (actual/real) Recording Sample Rate?

Hey all,
While you are reading this topic and preparing your responses, please keep in mind that I am self-taught and a newbie in the world of microcontrollers. I have never had a course in microcontrollers or software development etc. But I love to build stuff, and I am a fast learner. ;D

• My main question is: How can I determine the actual/real sample rate of the Arduino UNO?

A part of my Ph.D. dissertation requires synchronizing the signals from two devices. I am using an Arduino UNO to read the two devices' voltage using three analog pins (Device A) and one digital pin (Device B). I am using Matlab to store the signals, and I have set the BaudRate at 115200. I have connected the Arduino UNO with Matlab using a USB which means that I can have a maximum of 1000 transactions per sec.

• How can I determine the actual/real sample rate that the Arduino UNO transfers the data into Matlab?
• Or at least how can I determine the actual/real sample rate in that the Arduino UNO is transfecting the data into Arduino IDE?

Thank you
Nikos

A timer controlled interrupt could do the sampling. One headace is how to store the data regarding the sample frequency and duration of the session.

Nikoltos:
Hey all,
While you are reading this topic and preparing your responses, please keep in mind that I am self-taught and a newbie in the world of microcontrollers. I have never had a course in microcontrollers or software development etc. But I love to build stuff, and I am a fast learner. ;D

• My main question is: How can I determine the actual/real sample rate of the Arduino UNO?

A part of my Ph.D. dissertation requires synchronizing the signals from two devices. I am using an Arduino UNO to read the two devices’ voltage using three analog pins (Device A) and one digital pin (Device B). I am using Matlab to store the signals, and I have set the BaudRate at 115200. I have connected the Arduino UNO with Matlab using a USB which means that I can have a maximum of 1000 transactions per sec.

• How can I determine the actual/real sample rate that the Arduino UNO transfers the data into Matlab?
• Or at least how can I determine the actual/real sample rate in that the Arduino UNO is transfecting the data into Arduino IDE?

Thank you
Nikos

Welcome to the Arduino forum.
If you read what you wrote, you are asking several different questions. The sample rate of the Arduino program can be determined by using the millis() function to get the millisecond time and save it. Next time through the loop, get the millis() time and subtract from the first. there you have the time in milliseconds for each sample. You can process that time any way you want to get the value you want.
The other questions do not relate to an Arduino.
Paul

I'm not familiar with Matlab and I don't know what exactly you mean by "1000 transactions per sec"

I have the impression you are mixing up two things - {A} how often the Arduino can collect samples with analogRead() and {B} how many bytes per second an Arduino can send over a serial port.

The latter is reasonably easy to answer. The maximum rate of sending data is set by the baud rate - for example at 115200 buad it can send a max of about 11,000 bytes per second. At 500,000 baud the max would be about 50,000 bytes per second

However you also need to take into account the USB system which does not perform well for small data packets. IIRC it works best with data in chunks of 64 bytes. With less than 64 bytes it will wait for a 1 millisec timeout before sending data. That could mean a low rate of 1000 bytes per second if each message only contains one byte - even with a high baud rate.

To figure out how many ADC samples can be taken per second just set up a test for (say) 1000 samples and use micros() to time the start and the end of the test. Note that performance will degrade significantly if you need to take samples from different analog pins. There is only one ADC device and switching to another analog pin usually require discarding the first reading from the new pin.

...R

I assume you mean that Matlab can accept only 1000 "messages" per second from the USB port, so that is an upper limit.
Do you know if you are below that limit? Can you store data in Matlab for a predetermined interval and then see how many samples you collected? Alternatively, how long does it take you to gather one set of readings from your devices? Is the data collected short enough so that it will transfer completely at the 115200 baud rate before the next set of data is available? Using the microsecond or millisecond function, you ought to be able to determine this. If you are not experiencing an overflow in the serial buffer, then the rate of data transfer is exssentially equal to the time period required to collect one sample and push it to the serial port.