简体   繁体   English

将数据保存在列 Python DS18B20

[英]Save Data in a Column Python DS18B20

My Python code for data saves data of a temperature sensor(DS18B20) but doesn't save the Temperature in a column.我的 Python 数据代码保存了温度传感器(DS18B20)的数据,但没有将温度保存在列中。 The Temperature is written in a line like that: ['25.25'].温度写成这样的一行:['25.25']。 Can somebody please tell me how to fix it.有人可以告诉我如何解决它。 I have to separate the read Temperature from the Sensor into several Numbers.我必须将读取的温度从传感器分成几个数字。 Thanks for your help谢谢你的帮助

    while programmStatus == 1:
    #while True:
            now = datetime.now(timezoneBerlin)
                
#while True:
    # open new file
            with open ( 'test.tsv', 'w') as f:
                for temperature_single in Temperature:
                    f.write ("{:>5}\n".format('Temperature'))    
                    f.write("\t{:>5}\n".format 
                    (format(temperature_single)))
                    f.write("\n")
                    f.flush()
                    f.close()
   
                x = 0
                ds1820readout()
                print ("Sensorname und Temperaturevalue:")
                while x < tempSensorQuantity:
                    print (tempSensorName[x] , " " , tempSensorValue[x], " °C")
                    x = x + 1
print ("\n")

In this code, there is an I/0 error on closed file, can somebody please help?在这段代码中,关闭文件有一个 I/0 错误,有人可以帮忙吗?

It seems that Temperature is a list of values.似乎温度是一个值列表。 If you try to put them into the csv you have to iterate over the list first, eg:如果您尝试将它们放入 csv 中,您必须先遍历列表,例如:

tempSensorName = []
tempSensorQuantity = 0 
tempSensorValue = [] 
programmStatus = 1
Temperature = tempSensorValue   

def ds1820einlesen():
    global tempSensorName, tempSensorQuantity, programmStatus 
def ds1820auslesen():
    global tempSensorName, tempSensorQuantity, tempSensorValue,              
            with open ( 'test.tsv', 'w') as f:
                for temperature_single in Temperature:
                    f.write ("{:>5}\n".format('Temperature'))    
                    f.write("\t{:>5}\n".format(format(temperature_single)))
                    f.write("\n")
                    f.flush()
                    f.close()
    
                    x = 0
                    ds1820auslesen()
                    print ("Sensorname and Temperaturevalue:")
                    while x < tempSensorQuantity:
                        print (tempSensorName[x] , " " ,
    tempSensorValue[x], " °C")
                            x = x + 1
    print ("\n")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 树莓派与ds18b20接口 - raspberry pi interfacing with ds18b20 带有Arduino和多个ds18b20的Pyserial - Pyserial with Arduino and multiple ds18b20 测试多条DS18B20传感器电缆 - Testing multiple DS18B20 sensor cables 脚本在启动时运行,带有DS18B20的Raspberry Pi A +蓝牙不起作用 - Raspberry Pi A+ Bluetooth with DS18B20 not working when script runs on boot 如何在树莓派中直接从DS18B20传感器创建XML文件? - How to Create an XML file directly from DS18B20 sensor in raspberry Pi? 使用 Raspberry Pi 更快地读取多个 DS18B20 温度传感器 - Read multiple DS18B20 temperature sensors faster using Raspberry Pi 处理操作系统错误Python:[Errno 20]不是目录:&#39;/Volumes/ARLO/ADNI/.DS_Store&#39; - Dealing with OS Error Python: [Errno 20] Not a directory: '/Volumes/ARLO/ADNI/.DS_Store' 如何修复 ValueError:时间数据 &#39;18/02/2020 20:14:31&#39; 与 Python 中的格式 &#39;%d/%m/%y %H:%M:%S&#39; 不匹配? - How to fix ValueError: time data '18/02/2020 20:14:31' does not match format '%d/%m/%y %H:%M:%S' in Python? OSError: [Errno 20] 不是目录,.DS_Store - OSError: [Errno 20] Not a directory, .DS_Store 当现有列&#39;B&#39;的连续5个单元格值为python中数据框的空白时,为新列&#39;A&#39;分配一个标志 - Assigning a flag to a new column 'A' when continuously 5 cells value of existing column 'B' is blank of a data frame in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM