Jan-18-2018, 03:47 PM
Hello Helpers,
I made (partly copied) a script that gathers data from a MCP3008.
It loops as often as there are active MCP channels; in this case 0, 1, and 2.
Now the output comes in three separate lines whereas i would like to have them on one line to store in a CSV file together with the date/time.
Is there a way to accomplish this?? Or am i completely on the wrong path.
I made (partly copied) a script that gathers data from a MCP3008.
It loops as often as there are active MCP channels; in this case 0, 1, and 2.
Now the output comes in three separate lines whereas i would like to have them on one line to store in a CSV file together with the date/time.
Is there a way to accomplish this?? Or am i completely on the wrong path.
#Versie 15 jan 2018 # Importeer libraries. import sys import time import csv import os # Definieer een array (temp). # temp = {} # Definieer variabelen. DY = time.strftime("%Y") DM = time.strftime("%m") DD = time.strftime("%d") TH = time.strftime("%H") TM = time.strftime("%M") sensorids = ["28-000009aeb158"] # Doet de loop zo vaak als aantal sensors for sensor in range(len(sensorids)): tfile = open("/sys/bus/w1/devices/"+ sensorids[sensor] +"/w1_slave") tfile.close() # Sluit het "bestand" nadat we het gelezen hebben. temperaturedata =text.split(" ")[21] # Selecteer het 21ste woord(tellend vanaf 0) # Let op eventuele '\n'in string. temperature = float(temperaturedata[2:]) # Haal 't=' weg en maak een float temp[sensor] = temperature / 1000 print ("sensor", sensor, "=", temp[sensor], "graden.") #Print resultaat waretemp = '%.1f' % temp[0] #Afronden op 1 achter de komma data = [DY, DM, DD, TH, TM, waretemp] print (data) # Sla gegevens op in een bestand (per maand) in /usr/src/DHT_DATA_[YYYY]_[MM].csv csvfile = "/home/pi/DHT_DATA_" + DY + "_" + DM + ".csv" # Open het csv bestand en schijf door achter de bestaande inhoud. # with open(csvfile, "a") as output: # writer = csv.writer(output, delimiter=";", lineterminator='\n') # writer.writerow(data)Thanks for advice, rgds Steffen