質問編集履歴
1
質問の当初に省略していたコード(前半、01行目-23行目を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,58 +30,116 @@
|
|
30
30
|
|
31
31
|
```コード thpva.py
|
32
32
|
|
33
|
+
質問の当初に省略していたコード(前半、01行目-23行目を追記しました。
|
33
34
|
|
34
35
|
|
35
|
-
01 check = commands.getoutput("i2cset -y 1 0x41 0x05 0x0a 0x00 i")
|
36
36
|
|
37
|
-
|
37
|
+
---------------------------以下、追記
|
38
38
|
|
39
|
-
0
|
39
|
+
01 import RPi.GPIO as GPIO
|
40
40
|
|
41
|
-
0
|
41
|
+
02 import time
|
42
42
|
|
43
|
-
0
|
43
|
+
03 import commands
|
44
44
|
|
45
|
-
0
|
45
|
+
04 import datetime
|
46
46
|
|
47
|
-
0
|
47
|
+
05 import csv
|
48
48
|
|
49
|
-
0
|
49
|
+
06 import os
|
50
50
|
|
51
|
-
0
|
51
|
+
07 import bme280_custom
|
52
52
|
|
53
|
-
|
53
|
+
08
|
54
54
|
|
55
|
-
|
55
|
+
09 def GetV():
|
56
56
|
|
57
|
-
1
|
57
|
+
10 check = commands.getoutput("i2cget -y 1 0x41 0x02 w")
|
58
58
|
|
59
|
-
1
|
59
|
+
11 return (int(check[4:6],16)*256+int(check[2:4],16))*1.25/1000
|
60
60
|
|
61
|
-
1
|
61
|
+
12
|
62
62
|
|
63
|
-
1
|
63
|
+
13 def GetA():
|
64
64
|
|
65
|
-
1
|
65
|
+
14 check = commands.getoutput("i2cget -y 1 0x41 0x04 w")
|
66
66
|
|
67
|
-
1
|
67
|
+
15 if int(check[4:6],16)<128:
|
68
68
|
|
69
|
-
1
|
69
|
+
16 return (int(check[4:6],16)*256+int(check[2:4],16))
|
70
70
|
|
71
|
-
1
|
71
|
+
17 else:
|
72
72
|
|
73
|
-
|
73
|
+
18 return (int(check[4:6],16)*256+int(check[2:4],16)-256*256)
|
74
74
|
|
75
|
-
|
75
|
+
19
|
76
76
|
|
77
|
-
2
|
77
|
+
20
|
78
78
|
|
79
|
-
2
|
79
|
+
21 GPIO.setmode(GPIO.BCM)
|
80
80
|
|
81
|
-
2
|
81
|
+
22 GPIO.setup(5,GPIO.OUT)
|
82
82
|
|
83
|
-
2
|
83
|
+
23
|
84
84
|
|
85
|
-
|
85
|
+
-------------------------------以上、追記
|
86
86
|
|
87
|
+
24 check = commands.getoutput("i2cset -y 1 0x41 0x05 0x0a 0x00 i")
|
88
|
+
|
87
|
-
|
89
|
+
25
|
90
|
+
|
91
|
+
26 GPIO.output(5,GPIO.HIGH)
|
92
|
+
|
93
|
+
27 print "LED-on"
|
94
|
+
|
95
|
+
28 time.sleep(1)
|
96
|
+
|
97
|
+
29
|
98
|
+
|
99
|
+
30 dir_path = '/home/pi/ina226-data'
|
100
|
+
|
101
|
+
31
|
102
|
+
|
103
|
+
32 now = datetime.datetime.now()
|
104
|
+
|
105
|
+
33 filename = now.strftime('%Y%m%d')
|
106
|
+
|
107
|
+
34 label = now.strftime('%H:%M')
|
108
|
+
|
109
|
+
35 csv = bme280_custom.readData()
|
110
|
+
|
111
|
+
36 va = str(GetV())+","+str(GetA())
|
112
|
+
|
113
|
+
37
|
114
|
+
|
115
|
+
38 if not os.path.exists('/home/pi/ina226-data'):
|
116
|
+
|
117
|
+
39 os.makedirs('/home/pi/ina226-data')
|
118
|
+
|
119
|
+
40 f = open('/home/pi/ina226-data/'+filename+'.csv','a')
|
120
|
+
|
121
|
+
41 f.write("'"+label+"',"+csv+","+va+"\n")
|
122
|
+
|
123
|
+
42
|
124
|
+
|
125
|
+
43 #with open('/home/pi/ina226-data/'+filename+'.csv','a')as f:
|
126
|
+
|
127
|
+
44 # writer=csv.writer(f)
|
128
|
+
|
129
|
+
45 # writer.writerow ([GetV(),GetA()])
|
130
|
+
|
131
|
+
46 #f.close()
|
132
|
+
|
133
|
+
47
|
134
|
+
|
135
|
+
48 GPIO.output(5,GPIO.LOW)
|
136
|
+
|
137
|
+
49 print "LED-off"
|
138
|
+
|
139
|
+
50
|
140
|
+
|
141
|
+
51
|
142
|
+
|
143
|
+
52 GPIO.cleanup()
|
144
|
+
|
145
|
+
53 exit
|