]>
vault307.fbx.one Git - mu_code.git/blob - uart.py
4 ser
=serial
.Serial('/dev/ttyACM0', 9600,timeout
=.5) # serial connection
6 logFile
=open('lightLog.txt','w') # open and write to lightLog.txt
9 now
= time
.localtime() # year[0], month[1], day[2], hour[3], minute[4], second[5], weekday[6], yearday[7]
10 timestamp
=(str(now
[3])+":"+str(now
[4])+":"+str(now
[5])+" "+str((now
[1]))+"/"+str(now
[2])+"/"+str(now
[0]))
11 if int(now
[3]) == 7: # if hour is 7 am or greater, STOP collecting data
13 exit() # no error message, or breaks crontab
16 light
=str(data
).encode("utf-8")
17 a
=light
.strip(b
"b'") # remove beginning empty space
18 Light
=int(float(a
[:-4])) # remove last 4 bits, leaving only float->int of light_val
19 logFile
.write("Ambient Light: "+str(Light
)+" "+timestamp
+"\n")
21 print((Light
),timestamp
)
22 time
.sleep(60) # how often to sample data line