General questions on data logging
Posted: Thu Mar 22, 2018 6:00 pm
I am working on setting up a simple datalogger. The following code works in the REPL:
##################################################################################
adc = pyb.ADC('X1')
f = open('/sd/log_1.csv', 'w')
t_start = pyb.millis()
for i in range(10):
pyb.delay(1000)
dt = pyb.millis() - t_start
str = '%i, %i\n' %(dt, adc.read())
f.write(str)
f.close()
####################################################################################
If I type this in line-by-line in the REPL, it does exactly what I want, and saves to a file on the SD card the value of an ADC read.
However if I save this to main.py on the SD card, I get blinking red and green lights, indicating an error. The source can be traced back to the pyb.delay statement at the beginning of the for loop. Why would REPL and a runtime program be giving different results?
##################################################################################
adc = pyb.ADC('X1')
f = open('/sd/log_1.csv', 'w')
t_start = pyb.millis()
for i in range(10):
pyb.delay(1000)
dt = pyb.millis() - t_start
str = '%i, %i\n' %(dt, adc.read())
f.write(str)
f.close()
####################################################################################
If I type this in line-by-line in the REPL, it does exactly what I want, and saves to a file on the SD card the value of an ADC read.
However if I save this to main.py on the SD card, I get blinking red and green lights, indicating an error. The source can be traced back to the pyb.delay statement at the beginning of the for loop. Why would REPL and a runtime program be giving different results?