doceme / py-spidev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configure sampling rate in adxl355 accelerator using spidev

Phuntsho1984 opened this issue · comments

I am using mems adxl355 sensor using adxl355.py code for getting data in raspberry pi using spidev module. I am confused how do i configure the sampling rate to 100 samples per second or 100hz. I am wondering how does max_speed_hz in spidev affect the sampling rate.

commented

Also interested in the answer to this.
As far as I understand the sampling rate of the sensor might not be something controlled by the spi library. We might have to explicitly program it (like a timely controlled loop or similar). max_speed_hz is only for the clock of the spi. Might not relate directly to how often we query the slave.

delay_usec for the xfer function has caught my attention however.

xfer(list of values[, speed_hz, delay_usec, bits_per_word])
Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.

could this be used as a mean to control sampling rate of a sensor?

As @noeldum suggests, spi_speed_hz would only affect the data rate from the ADXL355 sensor, and not the update rate from the sensor.

This question isn't relevant to the underlying SPI library, but rather something you should be looking for in the Register Definitions/Register Map section of the ADXL355 datasheet - https://www.analog.com/media/en/technical-documentation/data-sheets/adxl354_355.pdf

Or asking of whoever authored the mentioned adxl355.py.

You would have to setup the sample rate in python by calling this library 100 times per second. The SPI clock speed in this library only affects the speed of the CLK pin for a given transfer and not how often you transfer data to/from your device.