Nov-06-2017, 10:49 PM
So far this is the code I've attempted
11/06/17,15:43:26,13,12754,11787,125,13882,14513,13269,0
11/06/17,15:43:28,10,9590,7790,83,8490,8926,8291,0
11/06/17,15:43:43,9,9243,7406,78,7880,8247,7718,0
11/06/17,15:43:58,9,8961,7229,77,7951,8139,7646,0
11/06/17,15:44:13,9,9710,7389,79,8690,8716,8206,0
sporadic outputs with incorrect numbers. it should be all zeroes right now as there is no input at the moment. also i dont understand why its giving outputs at 2 seconds then 15 seconds. I'm perplexed.
#!/usr/bin/python import RPi.GPIO as g import csv import datetime import time output1 = '/home/samba-share/nas/Output Machine Lihua Yu 442017.csv' output2 = '/media/pi/NEW VOLUME/Output Machine 1.csv' g.setmode(g.BCM) g.setup(5, g.IN) g.setup(6, g.IN) g.setup(13, g.IN) g.setup(19, g.IN) g.setup(26, g.IN) g.setup(20, g.IN) g.setup(21, g.IN) global SPM global NUP global NDWN global SPM2 global BTD global TRMD global LSWO global SSTATE SPM = 0 NUP = 0 NDWN = 0 SPM2 = 0 BTD = 0 TRMD = 0 LSWO = 0 SSTATE = 0 def inSPM(channel): global SPM SPM += 1 g.add_event_detect(5, g.RISING, callback=inSPM) def inNUP(channel): global NUP NUP += 1 g.add_event_detect(6, g.RISING, callback=inNUP) def inNDWN(channel): global NDWN NDWN +=1 g.add_event_detect(13, g.RISING, callback=inNDWN) def inSPM2(channel): global SPM2 SPM2 +=1 g.add_event_detect(19, g.RISING, callback=inSPM2) def inBTD(channel): global BTD BTD +=1 g.add_event_detect(26, g.RISING, callback=inBTD) def inTRMD(channel): global TRMD TRMD +=1 g.add_event_detect(20, g.RISING, callback=inTRMD) def inLSWO(channel): global SSTATE LSWO +=1 g.add_event_detect(21, g.RISING, callback=inLSWO) while True: time.sleep(120) DT = time.time() DATE = datetime.datetime.fromtimestamp(DT).strftime('%m/%d/%y') TIME = datetime.datetime.fromtimestamp(DT).strftime('%H:%M:%S') with open(output1,'ab') as output : writer=csv.writer(output, delimiter=',', quotechar='"') combined_row = [DATE, TIME, SPM/720, NUP, NDWN, SPM2/90, BTD, TRMD, LSWO, SSTATE] writer.writerow(combined_row) output.close print SPM/360 SPM = 0 NUP = 0 NDWN = 0 SPM2 = 0 BTD = 0 TRMD = 0 LSWO = 0 SSTATE = 0instead of getting an output every 2 minutes i get this
11/06/17,15:43:26,13,12754,11787,125,13882,14513,13269,0
11/06/17,15:43:28,10,9590,7790,83,8490,8926,8291,0
11/06/17,15:43:43,9,9243,7406,78,7880,8247,7718,0
11/06/17,15:43:58,9,8961,7229,77,7951,8139,7646,0
11/06/17,15:44:13,9,9710,7389,79,8690,8716,8206,0
sporadic outputs with incorrect numbers. it should be all zeroes right now as there is no input at the moment. also i dont understand why its giving outputs at 2 seconds then 15 seconds. I'm perplexed.