1

I'm trying to acquire a signal from sensor and process it "real time" with Raspberry and Python. I use ADC converter to have digital input. I was told to implement a sort of buffer since time processing takes too time and would stop ADC acquisition. My scheme is:

  1. Acquisition thread: ADC outputs samples at choosen sample rate and put them into a ring buffer (Queue in Python)
  2. Processing thread:takes samples from buffer when it's full and processes in one block

My question Is: how can I send ADC data saved in buffer all in one block to the processing code? I've read that processing in blocks it's more convenient but I don't know how to do this. I want to use threds because I don't want to loose samples

Tagalog
  • 31
  • 2

1 Answers1

0

While it is possible to create multiple threads in Python, I'm sorry to say that the (standard CPython) interpreter has limited ability to actually execute those threads truly simultaneously. The crux of the problem is that the interpreter is not thread safe, so a thread must hold the "Global Interpreter Lock" or "GIL" to safely access Python objects: "only the thread that has acquired the GIL may operate on Python objects or call Python/C API functions."

See also these related posts:

If possible, I'd consider using Java or C++ or another language with better support for multithreading for this project.

How can I send ADC data saved in buffer all in one block to the processing code?

(If you still want to use Python) the ADC data could be passed to the processing code as a list or numpy array.

Pascal Getreuer
  • 2,906
  • 1
  • 5
  • 14