0

I have two related questions. I'm happy to get advice or links to recommended reading as well.

How many times per second can a Pi pull data over SPI

  • Over SPI what sort of timescale can I query measurements on? I'm curious if the Pi is limiting here as I know one of the Arduino's benefits is fast timings? (In my case the sensor's limit is 1 kHz)

  • What is the best practice for achieving high rates? In the past I have written a loop in python which repeatedly polls the sensor. Should I be doing something more sophisticated?

  • At these timescales, how much should I worry about lag of the Pi?

When recieving data in rapid succession, how should I usher it to disk without the program waiting for a write

  • It seems that the sensor polling should happen concurrently/independently of my digestion of the data stream.

More details:

I have two sensors - a break beam sensor and an accelerometer. I want to save to disk the sensor data from 1 second before to 5 seconds after the beam is broken. Realistically, post processing the data would be fine here, but my "extra credit" project for myself is to filter the data to be saved prior to writing to disk.

1
  • "how should I usher it to disk without the program waiting for a write" -> As a rule, contemporary operating systems don't wait; they cache data in RAM and write it out to hardware when convenient (hopefully mostly via DMA, i.e., not requiring much CPU involvement), on a timescale in the seconds. So the overhead is just the time required for the syscall, which would be on a microsecond scale. – goldilocks Jan 11 '17 at 2:24
1

If you use the standard Linux driver you are limited to about 20ksps on Pi's other than the Pi3B which can manage about 80ksps.

If you write your own driver or use a library which uses its own driver you can do considerably better.

See http://abyz.me.uk/rpi/pigpio/faq.html#How_fast_is_SPI for my pigpio figures and some test software.

If you want the highest sample rates you need to be using C.

I'd suggest a limit of about 16Mbps for the actual SPI transfer bit rate. For this figure you may be limited by what the chip you want to talk to can handle.

1
  • Great link, thanks. All of the relevant information in a way that helped me to understand the factors at play here. – nate Jan 12 '17 at 16:21
0

From Raspberry Pi forum: One setting worth considering is the maximum transmission speed. The Atmel reference for SPI states that the system clock of the slave must be at least 4 times the SPI transmission rate. Since the barebones ATMEGA328P we're using is configured for an 8MHz clock, transmission from the Pi master could be as high as 2MHz.

Your device is 1000hz, so tx rate=250hz or 250 x second from pi forum. hope this is helpful. This is slow for the pi, which is the master, the sensor is the limit here.

From Raspberry Pi forum: Here we'll set the SPI clock speed to 1MHz with a system call to ioctl, using the spidev defined SPI_IOC_WR_MAX_SPEED_HZ and the value 1000000. Note that all values must be passed to ioctl by reference. First we assign the desired value to a variable (in this case speed and then rather than pass the actual variable, we pass a pointer to the variable using the syntax

    &speed.unsigned int speed = 1000000;
    ioctl (fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);

I am looking into I2c and am not much help on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.