Page 1 of 1

ESP32 Measure and save data in paralell

Posted: Thu May 21, 2020 11:13 pm
by lederer.tom
Hi guys,
I am quite new to micropython and am currently stuck on the following problem:
I am programming an esp32 which should sample an acceleration sensor every 2 ms (500 Hz). The sampled datas are stored in a list (so far so good - the amount of samples was quite good => 4494 samples in 9 seconds - only 6 are missing, but this is ok)
Due to this, the esp32 also should save this samples to a sd card.

To enable paralell measuring and saving, I used the _thread module to generate two threads. The measuring thread thereby implements a timer, which fires all 2 ms and therefore measures the according value from the acceleration sensor and appends it to the list.
The saving thread is in a while loop that sleeps 4 seconds, then checks if the list is empy. If it is not, then the datas are sent to the sd card and the list is cleared, otherwise nothing happens and the same procedure is done in 4 seconds again and so on. To ensure that no errors occure I am locking the list, save the list to a temporary variable, clear the list, unlock the list and then go on.

The problem now just is: When I enable the saving thread, only about 2500 measurements are taken in the 9 seconds (should be 4500 ! and that´s not acceptable for my project)

Any help is appreciated.

Many thanks in advance