Support Forum

Share your projects and post your questions

Register   or   Sign In
The Forum

max sampling rate

1677 Views - Created 24/09/2018


Posted by:

mallok05 Avatar

Hi, I wanted to know, if there´s some experience and maybe examples of evaluating the possible speed to get out of the MCP3208 with python.

I´m totally aware about pythons overhead but it´s required for my project. As I saw for the ADC DAC board it states that with python 12ksps would be possible. Those boards are comparable, or am I misstaking?

I did some basic testing of sampling one channel with 512 samples and timed it. If I break it down to one sample it results in ~21ksps.

Just wanted to double check if some experienced simimlar performance or can give me some guidance.

Thanks & greetings

test = np.zeros(N)
adc = ExpanderPi.ADC()

while True:
T_start =
for n in np.arange(0, N):
test[n] = adc.read_adc_voltage(1, 0)
T_end =
T_sample_all = (T_end - T_start).total_seconds()
T_sample_one = T_sample_all/N
f_sample= 1/T_sample_all


Posted by:

andrew Avatar

United Kingdom

andrew Twitter  andrew Website  


21Ksps will be about the average for the Expander Pi ADC when using a Raspberry Pi 3. I have uploaded a speed test demo to our GitHub repository which works similarly to your code. You can find it at

The sample rate will vary depending on several factors like the Raspberry Pi model, whether you are using Python 2 or 3 and what other processes are running at the same time. You will probably see about a 10% speed gain when using Python 2 instead of 3 as 2 seems to be better optimised.

The get the maximum sample rate out of the ADC you will need to use a compiled language like C or C++. I have uploaded a new speed test to our Expander Pi C library so I could compare the results and the sample rate of the C demo is around 54Ksps, so more than twice the speed of the Python library.


Posted by:

mallok05 Avatar

Hi Andrew,

thanks for your quick and helpful response!

Good to know about the better performance of python2. Yeah I'm aware about the variety of timing related on the by that comes with the Linux kernel scheduling. For the start I'll try to deal with it and hope isolation of cpu cores and the preempt_rt patch will provide me with satisfying performance.

Maximum sampling rate is not the main goal rather to have it somehow stable at a certain sampling rate and 20ksps would absolutely fit my needs.

For now I'm kind of forced to stick to python because the project is meant to be a proof of concept to design a radar system(adc, dac and spectrum analysis). We'll see where it ends up :)

Thanks for your help I really appreciate!


Sign in to post your reply

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.