起因:学校运河杯报了个项目,制作一个天气预测的装置。我用arduino跑了BME280模块,用蓝牙模块实现两块arduino主从机透传。但是为了分析,还需要提取出数据。因此我用python写了个上位机程序,用pyserial模块实现arduiho和电脑的串口通讯,再用xlwt模块写入excel表格,用time模块获取时间作为excel的文件名。 import xlwt
import time
import serial
#设置表格样式
def set_style(name,height,bold=False):
style = xlwt.XFStyle()
font = xlwt.Font()
font.name = name
font.bold = bold
font.color_index = 4
font.height = height
style.font = font
return style
#写Excel
def write_excel():
if serial.isOpen():
print ('串口已打开\n')
f = xlwt.Workbook()
sheet1 = f.add_sheet('arduino_data',cell_overwrite_ok=True)
row0 = ["temp","pres","hum"]
time1=time.localtime(time.time())
#写第一行
for