ul-gh / PiPyADC

Python classes for interfacing Texas Instruments analog-to-digital converters with the Raspberry Pi
GNU Lesser General Public License v2.1
69 stars 27 forks source link

example_2.py #28

Closed Kakalos14 closed 2 years ago

Kakalos14 commented 3 years ago

As far as it concerns the example_2.py. Could you please show me a way in which I could access the samples of the buffer for each channel and write them in a file? For example I'd like to take 10000 samples of a single channel every second and write them to a file. I work on theTexas Instrument ADS1256 ADC that has a hardware buffer. Thank you in advance!

ul-gh commented 3 years ago

Hi,

if you look at line 160, this is a numpy array that can be indexed just like any Python list object:

ch0 = ch_volts[0]
ch1 = ch_volts[1] ...

Writing this to a file, every second (you can append or overwrite each time):

with open("demofile2.txt", "a") as file:
    text = f"Channel 1 volts reading is: {ch_volts[0]}"
    file.write(text)
    file.close()

https://www.w3schools.com/python/python_file_write.asp https://www.pythonforbeginners.com/files/reading-and-writing-files-in-python

Btw: No, you can not read 10000 samples every second. See: https://github.com/ul-gh/PiPyADC/issues/27#issuecomment-773673952