質問編集履歴

3

code表記の変更

2019/05/02 09:02

投稿

d-morishige
d-morishige

スコア13

test CHANGED
File without changes
test CHANGED
@@ -90,54 +90,6 @@
90
90
 
91
91
  ```
92
92
 
93
- import time
94
-
95
- import dht11
96
-
97
- import RPi.GPIO as GPIO
98
-
99
-
100
-
101
- Temp_sensor=14
102
-
103
- def main():
104
-
105
- GPIO.setwarnings(False)
106
-
107
- GPIO.setmode(GPIO.BCM)
108
-
109
- instance = dht11.DHT11(pin = Temp_sensor)
110
-
111
-
112
-
113
- while True:
114
-
115
-
116
-
117
- result = instance.read()
118
-
119
-
120
-
121
- print("Temperature = ",result.temperature,"C"," Humidity = ",result.humidity,"%")
122
-
123
- time.sleep(1)
124
-
125
-
126
-
127
- if __name__ == '__main__':
128
-
129
-
130
-
131
- try:
132
-
133
- main()
134
-
135
- except KeyboardInterrupt:
136
-
137
- pass ←こいつが原因?try以下が何を意味しているのかまったく分かりません
138
-
139
-
140
-
141
93
 
142
94
 
143
95
  ### 補足情報

2

code表記の変更

2019/05/02 09:02

投稿

d-morishige
d-morishige

スコア13

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,55 @@
40
40
 
41
41
  ### pythonプログラム(dht11-test.py)コード
42
42
 
43
+ ```ここに言語を入力
43
44
 
45
+ import time
46
+
47
+ import dht11
48
+
49
+ import RPi.GPIO as GPIO
50
+
51
+
52
+
53
+ Temp_sensor=14
54
+
55
+ def main():
56
+
57
+ GPIO.setwarnings(False)
58
+
59
+ GPIO.setmode(GPIO.BCM)
60
+
61
+ instance = dht11.DHT11(pin = Temp_sensor)
62
+
63
+
64
+
65
+ while True:
66
+
67
+
68
+
69
+ result = instance.read()
70
+
71
+
72
+
73
+ print("Temperature = ",result.temperature,"C"," Humidity = ",result.humidity,"%")
74
+
75
+ time.sleep(1)
76
+
77
+
78
+
79
+ if __name__ == '__main__':
80
+
81
+
82
+
83
+ try:
84
+
85
+ main()
86
+
87
+ except KeyboardInterrupt:
88
+
89
+ pass ←こいつが原因?try以下が何を意味しているのかまったく分かりません
90
+
91
+ ```
44
92
 
45
93
  import time
46
94
 

1

ディレクトリーの問題からプログラムの問題へ

2019/05/02 09:01

投稿

d-morishige
d-morishige

スコア13

test CHANGED
File without changes
test CHANGED
@@ -2,11 +2,23 @@
2
2
 
3
3
 
4
4
 
5
- 初歩的な質問申し訳ありませんが、大変困っていま.
5
+ プログラミング未経験者です
6
6
 
7
7
 
8
8
 
9
9
  ラズベリーパイでpythonのプログラム(dht11-test.py)を作動させようとした所エラーとなりました.ディレクトリーの問題だと思いますが、何が悪いのか全く分かりません.
10
+
11
+
12
+
13
+ sudo python ./dht11-test.p の最後に【y】が抜けている事が原因でしたが、
14
+
15
+ sudo python ./dht11-test.py を作動させるも無反応でした.
16
+
17
+
18
+
19
+ pythonのプログラム(dht11-test.py)のコードの一部【print】に問題があったことが原因だと思われ、
20
+
21
+ そこを修正して再度作動させようとすると次のエラーが表示されここで手詰まりとなりました.
10
22
 
11
23
 
12
24
 
@@ -14,23 +26,69 @@
14
26
 
15
27
 
16
28
 
17
- pi@raspberrypi:~ $ sudo python ./dht11-test.p
29
+ i@raspberrypi:~ $ sudo python ./dht11-test.py
18
30
 
19
- python: can't open file './dht11-test.p': [Errno 2] No such file or directory
31
+ File "./dht11-test.py", line 27
32
+
33
+ pass
34
+
35
+ ^
36
+
37
+ IndentationError: expected an indented block
20
38
 
21
39
 
22
40
 
23
-
24
-
25
- ### 試したこと
41
+ ### pythonプログラム(dht11-test.py)コード
26
42
 
27
43
 
28
44
 
29
- 絶対パス?を入れても同じエラーが出ます
45
+ import time
30
46
 
31
- sudo python ./home/pi/dht11-test.p
47
+ import dht11
32
48
 
49
+ import RPi.GPIO as GPIO
50
+
51
+
52
+
53
+ Temp_sensor=14
54
+
55
+ def main():
56
+
57
+ GPIO.setwarnings(False)
58
+
59
+ GPIO.setmode(GPIO.BCM)
60
+
61
+ instance = dht11.DHT11(pin = Temp_sensor)
62
+
63
+
64
+
65
+ while True:
66
+
67
+
68
+
69
+ result = instance.read()
70
+
71
+
72
+
73
+ print("Temperature = ",result.temperature,"C"," Humidity = ",result.humidity,"%")
74
+
75
+ time.sleep(1)
76
+
77
+
78
+
33
- sudo python /home/pi/dht11-test.p
79
+ if __name__ == '__main__':
80
+
81
+
82
+
83
+ try:
84
+
85
+ main()
86
+
87
+ except KeyboardInterrupt:
88
+
89
+ pass ←こいつが原因?try以下が何を意味しているのかまったく分かりません
90
+
91
+
34
92
 
35
93
 
36
94
 
@@ -38,20 +96,10 @@
38
96
 
39
97
 
40
98
 
41
- Python IDLEで現在のカレントディレクトリを表示させると以下のようになりました.
42
-
43
- >>> import os
44
-
45
- >>> print(os.getcwd())
46
-
47
- /home/pi
48
-
49
-
50
-
51
- 作動させたいプログラム(dht11-test.py)は /home/pi の中にあります.
52
-
53
-
54
-
55
99
  私のやりたい事が以下のホームページに載っています
56
100
 
57
101
  http://osoyoo.com/ja/2017/04/raspberrypidht11/
102
+
103
+
104
+
105
+ 間違えと思われる記載が多々あります