Created
December 20, 2019 07:58
-
-
Save giorgiopizz/33ac96e07e97e6caa7f4f29e298f18dd to your computer and use it in GitHub Desktop.
python scrypt for micro serial acquisition adc
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 | |
ser=serial.Serial() | |
ser.baudrate=9600 | |
ser.port='COM10' | |
with open("dati_seriale.txt","w") as file: | |
r=ser.read() | |
while(r): | |
file.write(r) | |
r=ser.read() | |
with open("dati_seriale.txt","r") as file: | |
line=file.readline() | |
cnt=1 | |
vrefint_cal=0 | |
vrefint_data=0 | |
vec=[] | |
m=0 | |
i=0 | |
while line: | |
if line!='\n': | |
a=int(line) | |
b=3.3*a/(4095) | |
m+=b | |
if(i==1): | |
vec.append(m/2.0) | |
m=0 | |
i=0 | |
else: | |
i+=1 | |
print("Line{}: {}".format(line.strip(),b)) | |
cnt+=1 | |
line=file.readline() | |
with open("dati_seriale_convertiti.txt","w") as file: | |
for i in range(3,len(vec)): | |
file.write("{}, {}\n".format(i,vec[i])) | |
import matplotlib.pyplot as plt | |
import csv | |
x=[] | |
y=[] | |
with open("dati_seriale_convertiti.txt","r") as csvfile: | |
plots = csv.reader(csvfile,delimiter=',') | |
for row in plots: | |
x.append(float(row[0])) | |
y.append(float(row[1])) | |
print("{}, {}".format(row[0],row[1])) | |
plt.plot(x,y) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment