Created
January 17, 2020 23:08
-
-
Save dwblair/90284534fe04cad0783e0881fea20200 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
PORT='/dev/ttyACM0' | |
OUTFILE='out.csv' | |
NUM_SAMPLES = 1000 | |
f=open(OUTFILE,"w+") | |
s=serial.Serial(PORT,115200,timeout=1) | |
SIZE = 100 | |
NUM = 1 | |
RES = 8 | |
# SET UP THE SAMPLING | |
s.write('ADC.SET_SIZE '+str(SIZE)+'\n\r') # number of samples to grab in one go | |
s.write('ADC.SET_NUM '+str(NUM)+'\n\r') # number of times to repeat the sample grab | |
s.write('ADC.SET_RES '+str(RES)+'\n\r') # resolution | |
s.write('ADC.START\n\r') | |
print("SIZE=",SIZE) | |
print("NUM=",NUM) | |
print("RES=",RES) | |
i=0 | |
go=True | |
while go==True: | |
line=s.readline() | |
p=line.split(':') | |
if (len(p) > 1): | |
go = False | |
index=p[0].strip() | |
start=p[1].strip() | |
delta=p[3].strip() | |
print("micros_start:"+str(start),"micros_delta:"+str(delta)) | |
print('uS total:'+str(float(delta)/float(SIZE))) | |
vals = p[2].split(',') | |
print(vals) | |
for v in vals: | |
f.write(v+'\n') | |
#s.write('ADC.STOP\n\r') | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment