I recently acquired an ADS1256 Raspberry Pi expansion board from Amazon https://www.amazon.com/High-Precision-A ... B083WN119J and have encountered an issue that I'm hoping to get some help with. After running the board successfully with the provided sample code, I tested the onboard light sensor and potentiometer, which worked well. However, when I modified the sample program to save data, I noticed the sampling rate was quite low—only a few samples per second.
On further inspection of the Python code for reading the ADC signal, I observed that the delay command had been commented out in the original code. Could this be affecting the sampling rate? For clarity, I'm attaching my main02.py and adc_data.txt files. The data file has timestamps in the first column and CH0 values in the second.
Could anyone advise on how to increase the sampling rate or point out any potential issues in my code modification that might be causing this low sampling rate? Any guidance would be greatly appreciated.
I check the sampling rate at the config file from waveshare. It was 30kHz. I also check whether any delay put into the code to read the data in the waveshare created function. The delay was comment out before I downloaded the code.
Timestamp, 0_ADC Value
1705536089.1570663, 0.2797329759279461
1705536089.1926162, 0.30320469179209375
1705536089.2292516, 0.32551888531671586
1705536089.265661, 0.3478527483764587
1705536089.2997172, 0.3685945711844648
1705536089.3348975, 0.3862637741880148
1705536089.3689992, 0.4030883792744135
1705536089.4028306, 0.41864698155486363
1705536089.4366567, 0.4303992307662047
1705536089.4702778, 0.43968325134316105
1705536089.5039077, 0.4457980925796142
1705536089.5376248, 0.44940298192536615
1705536089.5732758, 0.4500830710033263
1705536089.607516, 0.4494774877402172
1705536089.6413796, 0.4467225607302857
1705536089.6751845, 0.44205730462757403
1705536089.7086089, 0.4354626459434802
1705536089.7419515, 0.4273736986367343
1705536089.7752671, 0.4166204233909158
1705536089.8085806, 0.4041147713798012
1705536089.841971, 0.39115612401439237
1705536089.87532, 0.376427814534642
1705536089.9086585, 0.36050920015683174
1705536089.941974, 0.344383757636995
1705536089.9753053, 0.3266477974233386
1705536090.008616, 0.3087187181375883
1705536090.041931, 0.29100779187772174
1705536090.075243, 0.272533330027262
1705536090.1085527, 0.25427404097009193
1705536090.1418622, 0.23682001075983175
1705536090.1751766, 0.21905246008067847
1705536090.208509, 0.20212712313260114
1705536090.2418191, 0.18672528108659758
1705536090.275153, 0.1714110578788588
1705536090.3084705, 0.15744330375710772
1705536090.3418202, 0.14533700291359458
1705536090.3752189, 0.13336183230421927
1705536090.4085617, 0.12358130497709573
1705536090.4418778, 0.11612297488724886
1705536090.4751945, 0.10972560760088057
1705536090.5085568, 0.1056146747606605
1705536090.541944, 0.10425032427910856
1705536090.575313, 0.10356427473596033
1705536090.6086257, 0.10479809102989328
1705536090.6419392, 0.10881484852014166
1705536090.675339, 0.11494101464045223
1705536090.708875, 0.12422503521740856
1705536090.7425957, 0.1368576451370293
1705536090.7773657, 0.1509362639112787
1705536090.8124628, 0.16771556946224803
1705536090.8478794, 0.18616916968454952
1705536090.882402, 0.20654978830215792
1705536090.915948, 0.22723558273739608
1705536090.949545, 0.2486753760189266
1705536090.9831953, 0.27018669488271413
1705536091.0167623, 0.2922618737532942
1705536091.0503538, 0.3134543077295193
1705536091.083917, 0.3343576591441225
1705536091.1174772, 0.3549290126477495
On further inspection of the Python code for reading the ADC signal, I observed that the delay command had been commented out in the original code. Could this be affecting the sampling rate? For clarity, I'm attaching my main02.py and adc_data.txt files. The data file has timestamps in the first column and CH0 values in the second.
Could anyone advise on how to increase the sampling rate or point out any potential issues in my code modification that might be causing this low sampling rate? Any guidance would be greatly appreciated.
I check the sampling rate at the config file from waveshare. It was 30kHz. I also check whether any delay put into the code to read the data in the waveshare created function. The delay was comment out before I downloaded the code.
Code:
import timeimport ADS1256import RPi.GPIO as GPIOtry: ADC = ADS1256.ADS1256() ADC.ADS1256_init() with open("adc_data.txt", "w") as file: # Write the header row file.write("Timestamp, 0_ADC Value\n") start_time = time.time() while time.time() - start_time <= 2: # Run for 2 seconds ADC_Value = ADC.ADS1256_GetAll() adc_0_value = ADC_Value[0] * 5.0 / 0x7fffff current_time = time.time() file.write(f"{current_time}, {adc_0_value}\n")except Exception as e: print(f"An error occurred: {e}")finally: GPIO.cleanup() print("\r\nProgram end")
Timestamp, 0_ADC Value
1705536089.1570663, 0.2797329759279461
1705536089.1926162, 0.30320469179209375
1705536089.2292516, 0.32551888531671586
1705536089.265661, 0.3478527483764587
1705536089.2997172, 0.3685945711844648
1705536089.3348975, 0.3862637741880148
1705536089.3689992, 0.4030883792744135
1705536089.4028306, 0.41864698155486363
1705536089.4366567, 0.4303992307662047
1705536089.4702778, 0.43968325134316105
1705536089.5039077, 0.4457980925796142
1705536089.5376248, 0.44940298192536615
1705536089.5732758, 0.4500830710033263
1705536089.607516, 0.4494774877402172
1705536089.6413796, 0.4467225607302857
1705536089.6751845, 0.44205730462757403
1705536089.7086089, 0.4354626459434802
1705536089.7419515, 0.4273736986367343
1705536089.7752671, 0.4166204233909158
1705536089.8085806, 0.4041147713798012
1705536089.841971, 0.39115612401439237
1705536089.87532, 0.376427814534642
1705536089.9086585, 0.36050920015683174
1705536089.941974, 0.344383757636995
1705536089.9753053, 0.3266477974233386
1705536090.008616, 0.3087187181375883
1705536090.041931, 0.29100779187772174
1705536090.075243, 0.272533330027262
1705536090.1085527, 0.25427404097009193
1705536090.1418622, 0.23682001075983175
1705536090.1751766, 0.21905246008067847
1705536090.208509, 0.20212712313260114
1705536090.2418191, 0.18672528108659758
1705536090.275153, 0.1714110578788588
1705536090.3084705, 0.15744330375710772
1705536090.3418202, 0.14533700291359458
1705536090.3752189, 0.13336183230421927
1705536090.4085617, 0.12358130497709573
1705536090.4418778, 0.11612297488724886
1705536090.4751945, 0.10972560760088057
1705536090.5085568, 0.1056146747606605
1705536090.541944, 0.10425032427910856
1705536090.575313, 0.10356427473596033
1705536090.6086257, 0.10479809102989328
1705536090.6419392, 0.10881484852014166
1705536090.675339, 0.11494101464045223
1705536090.708875, 0.12422503521740856
1705536090.7425957, 0.1368576451370293
1705536090.7773657, 0.1509362639112787
1705536090.8124628, 0.16771556946224803
1705536090.8478794, 0.18616916968454952
1705536090.882402, 0.20654978830215792
1705536090.915948, 0.22723558273739608
1705536090.949545, 0.2486753760189266
1705536090.9831953, 0.27018669488271413
1705536091.0167623, 0.2922618737532942
1705536091.0503538, 0.3134543077295193
1705536091.083917, 0.3343576591441225
1705536091.1174772, 0.3549290126477495
Statistics: Posted by zmarcoz — Thu Jan 18, 2024 12:36 am — Replies 1 — Views 81