2

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?

toolic
  • 5,637
  • 5
  • 20
  • 33
  • 2
    Please share the complete code, otherwise it'sreally hard to finde the problem. – kruemi Jun 27 '22 at 04:26
  • WaveShare AD/DA board with ADS1256 and DAC8552 is professional. You go to their Wiki and find interface spec and demo code to test it. – tlfong01 Jun 27 '22 at 04:46
  • 1
    Hi, the code is [link](https://github.com/waveshare/High-Precision-AD-DA-Board/tree/master/Raspberry%20PI/ADS1256/python3) , So in this code i have just modified the while loop which now is: while(time.time() – Varun Dhankhar Jun 27 '22 at 04:57
  • 2
    edit your question and add your code there, not in the comment as it is hard to read. – hcheung Jun 27 '22 at 05:08
  • 1
    (1) Your code is OK: High-Precision-AD-DA-Board/Raspberry PI/ADS1256/python3/ - GitHub WaveShare 2019jul29 https://github.com/waveshare/High-Precision-AD-DA-Board/tree/master/Raspberry%20PI/ADS1256/python3 (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***. – tlfong01 Jun 27 '22 at 05:09
  • 1
    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. – Varun Dhankhar Jun 27 '22 at 05:50
  • (1) But there is a formatted print statement in your while loop, and that might also slow things down. Your might like to ***remove the print statement, and time stamp after exiting the while loop***. (2) Appending something to a list is also time consuming. You might like to remove this append job, just to check if the list appending is consuming some time. – tlfong01 Jun 27 '22 at 07:37
  • 1
    @tlfong01 1) I am using the mentioned while loop in place of the original loop given by waveshare with print commands. 2) Also from my observations the reading from ADC.ADS1256_GetAll() function is consuming time. – Varun Dhankhar Jun 27 '22 at 09:48
  • 1
    I am sorry I don't understanding your comments. I must also apologize I did not read too carefully the WaveShare's code and your While loop. Perhaps you can show us ***the full listing of your test code***, so everybody can follow. – tlfong01 Jun 27 '22 at 12:07
  • 1
    Hi @tlfong01 I have updated the question with the link for the Code that I am using. Now according to me, there is no problem with the 'main.py' file. I think that the other 2 files(ads1256 and config) are slowing me down, due to which I am unable to reach desired sampling rate. – Varun Dhankhar Jun 27 '22 at 12:30
  • Ha, I am glad that you are making some progress. I have the feeling that you are almost there. I usually stop at this point, let the lonely hunter walk the last mile, enjoy finding the last bug. Happy programming. Cheers. – tlfong01 Jun 27 '22 at 12:40

0 Answers0