質問編集履歴
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -209,3 +209,11 @@
|
|
209
209
|
|
210
210
|
|
211
211
|
エラー解消のアドバイスをご教授願います。
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
arduino→arduinoは成功したものの、ラズパイ→arduinoが上手く行かなかったです。
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
頭の中が混乱していました。arduino→arduinoで解答くださった方、余計なお時間取らせてしまい申し訳ありませんでした。
|
2
python→arduino
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,9 +10,91 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
|
14
|
+
|
15
|
+
```
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#ラズパイ→arduino
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
import cv2
|
24
|
+
|
25
|
+
import numpy as np
|
26
|
+
|
27
|
+
import smbus
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
def main():
|
32
|
+
|
33
|
+
bus = smbus.SMBus(1)
|
34
|
+
|
35
|
+
adress1 = 0x05
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
img = cv2.imread('/home/test.jpeg')
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
while True:
|
44
|
+
|
45
|
+
cv2.imshow('img',img)
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
ONE = 1
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
TWO = 1
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
one = int.from_bytes(ONE,'little')
|
58
|
+
|
59
|
+
two = int.from_bytes(TWO,'little')
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
bus.write_byte(adress1, one)
|
64
|
+
|
65
|
+
bus.write_byte(adress1, two)
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
key = cv2.waitKey(10)
|
70
|
+
|
71
|
+
# "Esc"キー押下で終了
|
72
|
+
|
73
|
+
if key == 27:
|
74
|
+
|
75
|
+
break
|
76
|
+
|
77
|
+
cv2.destroyAllWindows()
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
if __name__ == '__main__':
|
84
|
+
|
85
|
+
main()
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
|
13
|
-
////////////////////////////////////////////////////////////////
|
95
|
+
////////////////////////////////////////////////////////////////
|
14
|
-
|
96
|
+
|
15
|
-
```
|
97
|
+
` ```受信側(arduino)```
|
16
98
|
|
17
99
|
include <Wire.h>
|
18
100
|
|
@@ -20,114 +102,66 @@
|
|
20
102
|
|
21
103
|
|
22
104
|
|
105
|
+
byte one = 0;
|
106
|
+
|
107
|
+
byte two = 0;
|
108
|
+
|
23
109
|
|
24
110
|
|
25
111
|
void setup() {
|
26
112
|
|
27
|
-
Wire.begin();
|
28
|
-
|
29
|
-
Serial.begin(9600);
|
113
|
+
Serial.begin(9600);
|
114
|
+
|
115
|
+
Wire.onReceive(ReceiveMassage);
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
Wire.begin(0x05);
|
120
|
+
|
121
|
+
|
30
122
|
|
31
123
|
}
|
32
124
|
|
33
125
|
|
34
126
|
|
35
|
-
void loop()
|
127
|
+
void loop(){
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
128
|
+
|
42
|
-
|
43
|
-
|
129
|
+
|
44
|
-
|
45
|
-
Wire.beginTransmission(0x05);
|
46
|
-
|
47
|
-
Wire.write(a);
|
48
|
-
|
49
|
-
Wire.write(b);
|
50
|
-
|
51
|
-
Wire.endTransmission();
|
52
|
-
|
53
|
-
delay(500);
|
54
130
|
|
55
131
|
}
|
56
132
|
|
57
133
|
|
58
134
|
|
59
|
-
|
60
|
-
|
61
|
-
//
|
135
|
+
//i2cでのデータ受け取り
|
62
|
-
|
136
|
+
|
63
|
-
|
137
|
+
void ReceiveMassage(int n){
|
64
|
-
|
138
|
+
|
139
|
+
|
140
|
+
|
65
|
-
in
|
141
|
+
int one = Wire.read();
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
142
|
+
|
71
|
-
|
143
|
+
Serial.print("recv1: ");
|
72
|
-
|
73
|
-
|
144
|
+
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
void setup() {
|
78
|
-
|
79
|
-
|
145
|
+
Serial.println(one);
|
146
|
+
|
147
|
+
|
148
|
+
|
80
|
-
|
149
|
+
int two = Wire.read();
|
150
|
+
|
81
|
-
|
151
|
+
Serial.print("recv2: ");
|
82
|
-
|
83
|
-
|
84
|
-
|
152
|
+
|
85
|
-
|
153
|
+
Serial.println(two);
|
154
|
+
|
86
|
-
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
87
|
-
|
159
|
+
delay(50);
|
88
160
|
|
89
161
|
}
|
90
162
|
|
91
163
|
|
92
164
|
|
93
|
-
void loop(){
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
//i2cでのデータ受け取り
|
102
|
-
|
103
|
-
void ReceiveMassage(int n){
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
int one = Wire.read();
|
108
|
-
|
109
|
-
Serial.print("recv1: ");
|
110
|
-
|
111
|
-
Serial.println(one);
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
int two = Wire.read();
|
116
|
-
|
117
|
-
Serial.print("recv2: ");
|
118
|
-
|
119
|
-
Serial.println(two);
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
delay(50);
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
|
131
165
|
//////////////////////////////////////////////////
|
132
166
|
|
133
167
|
|
1
全体のコードを表示しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,15 +10,97 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
/////////////////////////////////////////////////////////////////
|
14
|
+
|
13
15
|
```送信側```
|
14
16
|
|
15
|
-
|
17
|
+
include <Wire.h>
|
16
|
-
|
17
|
-
Wire.write(2); //1と2を送信
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
void setup() {
|
26
|
+
|
27
|
+
Wire.begin();
|
28
|
+
|
29
|
+
Serial.begin(9600);
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
void loop() {
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
int a = 1;
|
42
|
+
|
43
|
+
int b = 2;
|
44
|
+
|
45
|
+
Wire.beginTransmission(0x05);
|
46
|
+
|
47
|
+
Wire.write(a);
|
48
|
+
|
49
|
+
Wire.write(b);
|
50
|
+
|
51
|
+
Wire.endTransmission();
|
52
|
+
|
53
|
+
delay(500);
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
////////////////////////////////////////////////////////////////
|
62
|
+
|
21
|
-
`
|
63
|
+
` ```受信側```
|
64
|
+
|
65
|
+
include <Wire.h>
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
byte one = 0;
|
72
|
+
|
73
|
+
byte two = 0;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
void setup() {
|
78
|
+
|
79
|
+
Serial.begin(9600);
|
80
|
+
|
81
|
+
Wire.onReceive(ReceiveMassage);
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
Wire.begin(0x05);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
void loop(){
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
//i2cでのデータ受け取り
|
102
|
+
|
103
|
+
void ReceiveMassage(int n){
|
22
104
|
|
23
105
|
|
24
106
|
|
@@ -32,11 +114,21 @@
|
|
32
114
|
|
33
115
|
int two = Wire.read();
|
34
116
|
|
35
|
-
Serial.print("recv2:
|
117
|
+
Serial.print("recv2: ");
|
36
118
|
|
37
119
|
Serial.println(two);
|
38
120
|
|
121
|
+
}
|
39
122
|
|
123
|
+
|
124
|
+
|
125
|
+
delay(50);
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
//////////////////////////////////////////////////
|
40
132
|
|
41
133
|
|
42
134
|
|