2023-02-14 11:31 PM
I am using LSM6DSRTR, and the device-tree compatible is "st,lsm6dsr".
I can see two iio device node under
/sys/bus/iio/devices/iio:device1
/sys/bus/iio/devices/iio:device2
But when I try to read in a python loop, it gets really slow.
Anyway better to read it?
def getData(self, path):
fd = open(path, "r")
data = fd.read().strip()
fd.close()
return data
def testData(self):
iio_oneshot_path = "/sys/bus/iio/devices/iio:device2/in_accel_x_raw"
fd = open(iio_oneshot_path, "r")
while self.refresh:
self.accX = self.getData('/sys/bus/iio/devices/iio:device2/in_accel_x_raw')
self.accY = self.getData('/sys/bus/iio/devices/iio:device2/in_accel_y_raw')
self.accZ = self.getData('/sys/bus/iio/devices/iio:device2/in_accel_z_raw')
self.gyroX = self.getData('/sys/bus/iio/devices/iio:device1/in_anglvel_x_raw')
self.gyroY = self.getData('/sys/bus/iio/devices/iio:device1/in_anglvel_y_raw')
self.gyroZ = self.getData('/sys/bus/iio/devices/iio:device1/in_anglvel_z_raw')
print(self.accX)
time.sleep(0.01)
2023-04-12 05:14 AM
Ciao @WYang.9 ,
Welcome to ST Community!
The most recommended way to read data in continuous mode is to use the IIO buffer interface and for this I suggest the generic_buffer tool or the libiio test application iio_read.
If it is necessary to read the data via raw data to speed up the reading procedure it's recommended to set a high ODR because when you use raw data read the driver turn on the device than expect an ODR and furthermore the first samples must be discarded because the device is turned on, this means waiting much longer than an ODR.
If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster