My name is Sam, and I am a graduate student in mechanical engineering, trying to collect data from an analog pressure sensor for a personal research project. Earlier tonight, I was able to get a simple script working to record the sensor (and 3V3 reference) voltage, along with a timestamp. However, it only works for "small" numbers of data points. I have included an excerpt of my script and data.
The time frame I wish to collect over is likely on the order of ~100-200 seconds, and I found that if I make the elapsed time too large, a file will be created, but it will be empty-- a size of 0 KB. The script I am using is one that I repurposed after reading this article [/viewtopic.php?t=86]. I noticed that a similar thing occurred when I used the loop, with the data logging for smaller values of the loop iteration number, but failing for larger values. I have not pinpointed the exact number which it no longer records, but it cannot do 10 seconds.
I assume that I am running into some kind of memory limit, but as there is no error (that I can see). Does anyone know what limit I am running into? Some kind of time-out?
Once I can record data, I plan to write the data onto an SD card. If anyone has recommendations about using a queue/buffer, those would also be appreciated, as I believe this script may be somewhat slow. Me thinks the writing and collecting in the loop causes unwanted delay. But thats just my intuition. And if anyone has a script to do what I am trying to do, I would gladly take (a look at) it.
And lastly, thank you for your time! If anyone needs any clarifying info, I am happy to provide it.
Warm regards,
Sam
Code: Select all
[/# main.py -- put your code here!
import pyb
from pyb import Pin,ADC
pyb.LED(4).on
f = open('samm.dat', 'w') # open the file for writing
start=pyb.millis()
while pyb.elapsed_millis(start) < 100:
time = pyb.millis() # get the current time
adc=int(ADC(Pin('X21')).read())
volt=int(ADC(Pin('X22')).read())
# write time and x,y,z values to the file
f.write('{} {} {}\n'.format(time, adc, volt))
pyb.delay(5)
f.close() # close the file
pyb.LED(4).off()]
# a representative output
2067 2217 4093
2073 2223 4095
2078 2224 4093
2083 2221 4095
2088 2220 4095
2093 2219 4093
2098 2221 4092
2103 2217 4093
2108 2221 4095
2113 2221 4093
2118 2221 4095
2123 2222 4093
2128 2221 4095
2133 2220 4095
2138 2221 4095