1

I am working in a project using Raspberry Pi 3 B where I get data from a IR sensor(Sharp GP2Y0A21YK0F) through a ADC MPC3008 and display it in real-time using PyQtgraph library.

However, it seems that I am getting very few samples and the graph is not "smooth" as I expect.

I am using the Adafruit Python MCP3008 Library and the function mcp.read_adc(0) to get the data.

Is there a way to measure the sample rate in Python?

Thank you

Hugo Oliveira

4

1 回答 1

0

我建议设置一些下一级缓冲,最好是通过多处理(请参阅多处理和 GUI 更新 - Qprocess 或多处理?) 以更好地掌握访问数据的速度。目前您正在使用 QTimer 进行轮询,每 50 毫秒仅获得 3 次原始读取......所以您真的通过计时器人为地限制了自己。我没有使用过 MCP3008,但是快速浏览一下他们的代码似乎你必须设置一些示例测试来尝试一些事情,或者进一步调查以获得更好的文档。问题是 mcp.read_adc(0) 方法的行为,它是阻塞的还是非阻塞的……如果是非阻塞的,如果没有新数据,它是否返回陈旧的数据……等等。这将是理想的如果它从时间意义上说是阻塞的,您可以在其上设置一个循环,并在每次连续返回时设置时间增量,以确定您能够以多快的速度获得新样本。如果它是非阻塞的,您希望它在没有新样本的情况下返回 null,并且仅在它确实返回某些内容时才返回新的实际样本。你必须玩弄它,看看它的行为如何。无论如何,一旦您将辅助线程设置为仅轮询 mcp.read_adc(0),您就可以使用 update() 计时器来收集最新的缓冲区并绘制它。我也不知道多线程/多处理对 RaspPI 的影响(请参阅此处的一般讨论:Multiprocessing vs Threading Python),但任何事情都应该比 QTimer 轮询更好。

于 2016-11-14T07:08:28.930 回答