2
\$\begingroup\$

I have a High Precision AD/DA board from waveshare with Raspberry Pi 3B (running on Raspbian).

However, I can write only 27 samples in 1s in my CSV file. I am using this Python code for writing to a CSV file. It seems my code is not optimized for writing at a higher sampling rate.

The only change done in the code is in the 'main.py' file(rest code is same as that from waveshare) and the edit is: The overall code used by me is: code_used_link. Now the problem that I am facing is that reading the value from ADC.ADS1256_GetAll() is taking time and also with this code i am not able to achieve the desired sampling rate.

while(time.time()<future):#running for 1 sec.
        
        tic = time.perf_counter()
        x.append(ADC.ADS1256_GetAll())#x is a list.
        toc = time.perf_counter()
        print(f"{(toc - tic)*1000000} useconds")#seeing time between each read    

After the whole reading process, I write the data from the list to CSV file.

Could you let me know how can I write the data to my CSV file above 10 KPS sampling rate?

\$\endgroup\$
11
  • 2
    \$\begingroup\$ Please share the complete code, otherwise it'sreally hard to finde the problem. \$\endgroup\$
    – kruemi
    Jun 27, 2022 at 4:26
  • 1
    \$\begingroup\$ Hi, the code is link , So in this code i have just modified the while loop which now is: while(time.time()<future):#running for 1 sec. tic = time.perf_counter() x.append(ADC.ADS1256_GetAll()) #x is a list. toc = time.perf_counter() print(f"{(toc - tic)*1000000} useconds")#seeing time between each read \$\endgroup\$ Jun 27, 2022 at 4:57
  • 2
    \$\begingroup\$ edit your question and add your code there, not in the comment as it is hard to read. \$\endgroup\$
    – hcheung
    Jun 27, 2022 at 5:08
  • 1
    \$\begingroup\$ (1) Your code is OK: High-Precision-AD-DA-Board/Raspberry PI/ADS1256/python3/ - GitHub WaveShare 2019jul29 github.com/waveshare/High-Precision-AD-DA-Board/tree/master/… (2) The ADC can do 30ksps. So I think it is the writing to CSV file that slows things down. (3) To troubleshoot, you can try NOT to write to CSV, but instead, write to a a big python array. \$\endgroup\$
    – tlfong01
    Jun 27, 2022 at 5:09
  • 1
    \$\begingroup\$ The edit has been done in question itself. Hi @tlfong01 , All the data writing process to CSV file is done outside the while loop mentioned in the question. Inside the loop, I am just reading and storing the data in my buffer list. \$\endgroup\$ Jun 27, 2022 at 5:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.