-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype.py
More file actions
197 lines (155 loc) · 4.93 KB
/
prototype.py
File metadata and controls
197 lines (155 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import os
import sys
import matplotlib.pyplot as plt
import numpy as np
import time
import random
import picamera
import Adafruit_DHT
from time import sleep
from datetime import datetime
from daqhats import hat_list, HatIDs, mcc118
def my_plotter(ax, data1, data2, param_dict):
"""
A helper function to make a graph
Parameters
----------
ax : Axes
The axes to draw to
data1 : array
The x data
data2 : array
The y data
param_dict : dict
Dictionary of kwargs to pass to ax.plot
Returns
-------
out : list
list of artists added
"""
out = ax.plot(data1, data2, **param_dict)
return out
def set_parameters(arguments):
if arguments.find('-r') != -1:
rampMode = True
print('Its set!')
def calc_elapsed_time():
t = time.time() - startTime
return round(t,0)
def capture_photo(path):
with picamera.PiCamera() as camera:
camera.resolution = (1280,720)
camera.capture(path)
return
set_parameters(str(sys.argv))
timeRamp = float(sys.argv[1])
timeInterval = float(sys.argv[2])
#File path
startTime = datetime.now()
filePath = "/home/pi/Desktop/tests/" + startTime.strftime("%Y-%m-%d-%H%M%S")
logFileName = filePath + "/logfile.txt"
figureName = filePath + "/figure.png"
try:
os.mkdir(filePath)
except OSError:
print("Failed to create the directory %s" % filePath)
else:
print("Successfully created the directory %s" % filePath)
#print('Arg 1 = ' + timeRamp + ' Arg 2 = ' + timeInterval)
#Initialize DHT22
sensor = Adafruit_DHT.DHT22
pin = 4
#Initialize MCC daqhat boards
# get hat list of MCC daqhat boards
board_list = hat_list(filter_by_id = HatIDs.ANY)
if not board_list:
print("No boards found")
sys.exit()
f = open(logFileName, "x")
f = open(logFileName, "a")
#Frequency in Hz and convert into seconds
freqRamp = 1
delayRamp = 1/freqRamp
runDAQ = True
timeData = []
yData = []
i = 0
j = 0
startTime = time.time()
while i < timeRamp:
if i == 0:
print('Started ramping recording at %s...' %time.ctime())
#print('Run = %s' %i)
timeElapsed = calc_elapsed_time()
timeData.append(timeElapsed)
#yData.append(round(float(random.random())*1000,0))
#Capture Photo
picName = str(timeElapsed) + '.jpg'
completeFilePath = filePath +"/"+ picName
capture_photo(completeFilePath)
# with picamera.PiCamera() as camera:
# camera.resolution = (1280,720)
# camera.capture(completeFilePath)
# #print("Captured at: " + picTime)
#Capture Envrionmental conditions
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
yData.append(humidity)
f.write("Test number: " + str(timeElapsed))
#Read Analog input
for entry in board_list:
if entry.id == HatIDs.MCC_118:
#print("Board {}: MCC 118".format(entry.address))
board = mcc118(entry.address)
x_out = board.a_in_read(0)
y_out = board.a_in_read(1)
z_out = board.a_in_read(2)
#print("Ch {0}: {1:.3f}".format(0, x_out))
#print("Ch {0}: {1:.3f}".format(1, y_out))
#print("Ch {0}: {1:.3f}".format(2, z_out))
sleep(delayRamp)
i += 1
print('Finished ramping recording finished at %s ' %time.ctime())
#x = np.arange(0, 10, 0.2)
#y = np.arrange(2,4,5,4,6)
#fig1, ax = plt.subplots()
#ax.plot(x, y)
#fig1.savefig('/Users/patrickpischulti/Pictures/fig.png')
try:
while runDAQ == True:
if j == 0:
print('Main DAQ started at %s...' %time.ctime())
#print('DAQ loop iteration = %s' %j)
timeElapsed = calc_elapsed_time()
timeData.append(timeElapsed)
#yData.append(round(float(random.random())*1000,0))
#Capture Photo
picName = str(timeElapsed) + '.jpg'
completeFilePath = filePath +"/"+ picName
with picamera.PiCamera() as camera:
camera.resolution = (1280,720)
camera.capture(completeFilePath)
#print("Captured at: " + picTime)
#Capture Envrionmental conditions
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
yData.append(humidity)
f.write("Test number: " + str(timeElapsed))
#Read Analog input
for entry in board_list:
if entry.id == HatIDs.MCC_118:
#print("Board {}: MCC 118".format(entry.address))
board = mcc118(entry.address)
x_out = board.a_in_read(0)
y_out = board.a_in_read(1)
z_out = board.a_in_read(2)
#print("Ch {0}: {1:.3f}".format(0, x_out))
#print("Ch {0}: {1:.3f}".format(1, y_out))
#print("Ch {0}: {1:.3f}".format(2, z_out))
j += 1
sleep(timeInterval)
except KeyboardInterrupt:
for x in timeData:
print(x)
fig, ax = plt.subplots(1, 1)
my_plotter(ax, timeData, yData, {'marker': 'x'})
fig.savefig(figureName)
print('...DAQ Stopped!')