質問編集履歴

1

質問の当初に省略していたコード(前半、01行目-23行目を追記しました。

2018/01/18 08:45

投稿

k.horigome
k.horigome

スコア12

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
- 02
37
+ ---------------------------以下、追記
38
38
 
39
- 03 GPIO.output(5,GPIO.HIGH)
39
+ 01 import RPi.GPIO as GPIO
40
40
 
41
- 04 print "LED-on"
41
+ 02 import time
42
42
 
43
- 05 time.sleep(1)
43
+ 03 import commands
44
44
 
45
- 06
45
+ 04 import datetime
46
46
 
47
- 07 dir_path = '/home/pi/ina226-data'
47
+ 05 import csv
48
48
 
49
- 08
49
+ 06 import os
50
50
 
51
- 09 now = datetime.datetime.now()
51
+ 07 import bme280_custom
52
52
 
53
- 10 filename = now.strftime('%Y%m%d')
53
+ 08
54
54
 
55
- 11 label = now.strftime('%H:%M')
55
+ 09 def GetV():
56
56
 
57
- 12 csv = bme280_custom.readData()
57
+ 10 check = commands.getoutput("i2cget -y 1 0x41 0x02 w")
58
58
 
59
- 13 va = str(GetV())+","+str(GetA())
59
+ 11 return (int(check[4:6],16)*256+int(check[2:4],16))*1.25/1000
60
60
 
61
- 14
61
+ 12
62
62
 
63
- 15 if not os.path.exists('/home/pi/ina226-data'):
63
+ 13 def GetA():
64
64
 
65
- 16 os.makedirs('/home/pi/ina226-data')
65
+ 14 check = commands.getoutput("i2cget -y 1 0x41 0x04 w")
66
66
 
67
- 17 f = open('/home/pi/ina226-data/'+filename+'.csv','a')
67
+ 15 if int(check[4:6],16)<128:
68
68
 
69
- 18 f.write("'"+label+"',"+csv+","+va+"\n")
69
+ 16 return (int(check[4:6],16)*256+int(check[2:4],16))
70
70
 
71
- 19
71
+ 17 else:
72
72
 
73
- 20 f.close()
73
+ 18 return (int(check[4:6],16)*256+int(check[2:4],16)-256*256)
74
74
 
75
- 21
75
+ 19
76
76
 
77
- 22 GPIO.output(5,GPIO.LOW)
77
+ 20
78
78
 
79
- 23 print "LED-off"
79
+ 21 GPIO.setmode(GPIO.BCM)
80
80
 
81
- 24
81
+ 22 GPIO.setup(5,GPIO.OUT)
82
82
 
83
- 25 GPIO.cleanup()
83
+ 23
84
84
 
85
- 26 exit
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