import numpy as np import pandas as pd import tclab import time import matplotlib.pyplot as plt # generate step test data on Arduino filename = 'tclab_dyn_data1.csv' # heater steps Qd = np.zeros(601) Qd[10:200] = 80 Qd[200:400] = 20 Qd[400:] = 50 # Connect to Arduino a = tclab.TCLab() fid = open(filename,'w') fid.write('Time,H1,T1\n') fid.close() # run step test (10 min) for i in range(601): # set heater value a.Q1(Qd[i]) print('Time: ' + str(i) + \ ' H1: ' + str(Qd[i]) + \ ' T1: ' + str(a.T1)) # wait 1 second time.sleep(1) # write results to file fid = open(filename,'a') fid.write(str(i)+','+str(Qd[i])+','+str(a.T1)+'\n') fid.close() # close connection to Arduino a.close() # read data file data = pd.read_csv(filename) # plot measurements plt.figure() plt.subplot(2,1,1) plt.plot(data['Time'],data['H1'],'b-',label='Heater 1') plt.ylabel('Heater (%)') plt.legend(loc='best') plt.subplot(2,1,2) plt.plot(data['Time'],data['T1'],'r.',label='Temperature 1') plt.ylabel('Temperature (degC)') plt.legend(loc='best') plt.xlabel('Time (sec)') plt.savefig('tclab_dyn_meas1.png') plt.show()