Skip to content

Instantly share code, notes, and snippets.

@dwblair
Created January 17, 2020 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwblair/90284534fe04cad0783e0881fea20200 to your computer and use it in GitHub Desktop.
Save dwblair/90284534fe04cad0783e0881fea20200 to your computer and use it in GitHub Desktop.
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