python - 是否可以使用Python提高Raspberry Pi上ADXL345的采样率?

标签 python raspberry-pi3 delay i2c downsampling

我有一个带有 2 个 ADXL345 加速计的 Raspberry Pi,我想最大化它们的数据采样率。当我在互联网上搜索时,我很感兴趣地发现 Raspberry Pi 论坛 ( https://www.raspberrypi.org/forums/viewtopic.php?t=254552 ) 上有人显示了这段代码,在此示例中他使用了两个加速度计:

import time
import Adafruit_ADXL345


accel1 = Adafruit_ADXL345.ADXL345()
accel2 = Adafruit_ADXL345.ADXL345(address=0x1d, busnum=1)


print('Printing X, Y, Z axis values, press Ctrl-C to quit...')
cordinates = []

import time
start_time = time.time()
NUM_OF_SEC_TO_RUN = 10 

while time.time()<=start_time+NUM_OF_SEC_TO_RUN:

    x1, y1, z1 = accel1.read()
    x2, y2, z2 = accel2.read()
    cordinates.append([x1,y1,z1,x2,y2,z2,time.time()])

import csv
with open('02.txt', 'a') as csvFile:
    writer = csv.writer(csvFile)
    writer.writerows(cordinates)

在帖子的后面,他说该片段

x1, y1, z1 = accel1.read()
x2, y2, z2 = accel2.read()
cordinates.append([x1,y1,z1,x2,y2,z2,time.time()])

最可能的原因是加速度计进行下采样,从而降低读取速率并延迟数据采集。

他说,

The average time for execution of the above 3 lines of code is 0.002121 seconds. Does this mean than the reading capability is limited because of i2c and Raspberry pi, not the sensor? Or is it because of my code?

我也想知道同样的问题,但我会以不同的方式提出它。有没有办法使上面的段缩短,从而有可能减少延迟并提高数据采样率?就是说有没有办法把它变成一行呢? 据我所知,这个人的帖子还没有得到回应,也没有任何对我有帮助的结论性的帖子。

如果没有办法回答这个问题,那么我提出这个问题:有没有办法加快 Raspberry Pi 3 B+ 上 I2C 的数据采样速度,或者是否可以复制此代码SPI通讯?我知道 SPI 通信比 I2C 更快,但我不确定如何在 Raspberry Pi 中的 Python 上实现它。如果这篇文章太长,我深表歉意。

最佳答案

ADXL345 数据表显示,使用快速 i2c 的最快采样率为 800Hz。需要 SPI 来获得更快的采样率——高达 3200Hz。

看起来 Adafruit_ADXL345 库仅支持 i2c。它已被弃用。 Adafruit Blinka 库支持 SPI,但您必须推出自己的 ADXL345 接口(interface)。

关于python - 是否可以使用Python提高Raspberry Pi上ADXL345的采样率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59923169/

相关文章:

python - 对嵌套元组列表进行排序

docker - 在树莓派上运行docker时出错

c++ - 在 ARM 上编译 ChromeDriver

javascript - js 中的动画有不必要的轻微延迟

java - 等待输入字符 10 秒,还是在按下某个键时提前继续?

css - 无限循环之前和之后的动画延迟 CSS3

Python 和 Yum 发布 CentOS 5.4

python - Pyinstaller导入错误: cannot import name 'dist' on Windows

java - 将 JSON 字符串转换为 Java/Python (Jython) 对象?

linux - 找不到安装sh文件命令