54 lines
1.1 KiB
Python
54 lines
1.1 KiB
Python
import serial
|
|
import re
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
#connect to device, check if correct port
|
|
ser =serial.Serial('COM3',19200)
|
|
|
|
if not ser.isOpen():
|
|
ser.open()
|
|
print('com3 is open', ser.isOpen())
|
|
Bx=[]
|
|
By=[]
|
|
Bz=[]
|
|
x=[]
|
|
i=0
|
|
f=open('Data/Cal_neg.txt','w')
|
|
fig, axs=plt.subplots(1,3)
|
|
|
|
#plug in number of measurement points (here 35)
|
|
#save all data in a txt sheet
|
|
for k in range(0, 55 ):
|
|
|
|
a=ser.readline()
|
|
data=str(a,'utf-8')
|
|
points=re.findall(r'-?\d+\.?\d*', data)
|
|
Bx_point=float(points[0])
|
|
By_point=float(points[1])
|
|
Bz_point=float(points[2])
|
|
Bx.append(Bx_point)
|
|
By.append(By_point)
|
|
Bz.append(Bz_point)
|
|
x.append(i)
|
|
i+=1
|
|
print(Bx_point,By_point,Bz_point)
|
|
f.write(str(Bx_point)+'\t'+str(By_point)+'\t'+str(Bz_point)+'\n')
|
|
|
|
f.close()
|
|
|
|
|
|
#plot to get a first look at magnetic field (not calibrated)
|
|
axs[0].errorbar(x,Bx,1.615)
|
|
axs[0].set_title('Bx')
|
|
axs[0].set(ylabel='G')
|
|
axs[1].errorbar(x,By,1.615)
|
|
axs[1].set_title('By')
|
|
axs[1].set(ylabel='G')
|
|
axs[2].errorbar(x,Bz,1.615)
|
|
axs[2].set_title('Bz')
|
|
axs[2].set(ylabel='G')
|
|
print(By)
|
|
plt.show()
|
|
|
|
np.save('Data/By_cal_neg.npy', By)
|