raspberrycomslex
Posts: 2
Joined: Wed Aug 07, 2019 1:04 pm

Raspberry Pi High Frequency Sampling

Wed Aug 07, 2019 1:07 pm

Hey guys,

I am trying to use the raspberry pi with an ADXL355 digital accelerometer over SPI and would like to sample at 4000hz. Does the pi have a maximum sampling rate cap, or can I somehow adjust it so it can process data that fast. I can do 500-1000 without the FIFO overflowing and losing some of my data points

Thanks in advance

grompot
Posts: 19
Joined: Tue Jan 09, 2018 12:02 am

Re: Raspberry Pi High Frequency Sampling

Sun Aug 11, 2019 7:40 pm

What programing language are you using? My experience with python and a mcp3008 (spi) was that i can get 48 readings per second while using IDLE, but 4700 readings per second while running the code the command line.

raspberrycomslex
Posts: 2
Joined: Wed Aug 07, 2019 1:04 pm

Re: Raspberry Pi High Frequency Sampling

Thu Aug 15, 2019 3:51 pm

I am using python and the script is found here https://github.com/nuclearfutureslab/adxl355-pi. The MCP3008 is an analog to digital converter, the accelerometer I am using is digital already? Is there something I'm missing here?

amcdonley
Posts: 169
Joined: Mon Jan 26, 2015 5:56 pm
Location: Florida, USA

Re: Raspberry Pi High Frequency Sampling

Sat Aug 17, 2019 4:34 pm

raspberrycomslex wrote:
Wed Aug 07, 2019 1:07 pm
Hey guys,

ADXL355 digital accelerometer over SPI and would like to sample at 4000hz.
Does the pi have a maximum sampling rate cap,
According to How Fast Is SPI the Linux SPI driver (in a C language program) seems to max out around 20K bytes per second. I don't know how many bytes each ADXL355 sample is that you want to transfer across that 20K bytes per second channel - you need to divide the 20,000 bytes by the number of bytes for each sample.

The other thing at issue here is that Python, on Raspbian does not guarantee you will execute. I don't know what the slice gaps are, but those can affect how often you get the opportunity to read the samples.

User avatar
joan
Posts: 14093
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Raspberry Pi High Frequency Sampling

Sat Aug 17, 2019 4:48 pm

That is samples per second, not bytes per second. So if each sample was 12 bytes (4 bytes each of X, Y, Z) then that would be 20,000 times 12 or 240,000 bytes per second.

amcdonley
Posts: 169
Joined: Mon Jan 26, 2015 5:56 pm
Location: Florida, USA

Re: Raspberry Pi High Frequency Sampling

Sat Aug 17, 2019 7:05 pm

joan wrote:
Sat Aug 17, 2019 4:48 pm
That is samples per second, not bytes per second. So if each sample was 12 bytes (4 bytes each of X, Y, Z) then that would be 20,000 times 12 or 240,000 bytes per second.
The top line is 1 byte per second, the bottom line slower for 5 bytes per second, which implies 12 bytes per second will be even lower samples per second, but perhaps probably still higher than 4K samples per second, so it would seem the answer is (in C at least) that 4K samples with this SPI IMU should be possible.

As to why the OP is only able to see 1K samples per second w/out buffer overrun, deeper analysis would be needed to see the max time in background, and how python unpacking is affecting it. (and if the while len[samples] < msamples is the fastest "end of while" test available.

Return to “Automation, sensing and robotics”