-
Notifications
You must be signed in to change notification settings - Fork 88
/
camera_i2c
executable file
·265 lines (244 loc) · 6.26 KB
/
camera_i2c
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/sh
# Setup GPIO and I2C ports for raspicam
# Broadcom GPIO numbers used here
# http://elinux.org/RPi_HardwareHistory#Board_Revision_History
rev=`cat /proc/cpuinfo | grep Revision | awk '{print substr($NF,length($NF)-5,6)}'`
kernel=`uname -r | head --bytes 1`
echo "setting GPIO for board revsion: $rev"
case $rev in
# Old revision code encodings first
'0002'|'0003')
echo "B Rev1 - I2C 1 on GPIOs 2 & 3. GPIOs 5 & 27 for LED and power"
if [ "$kernel" = "4" ]
then
# i2c on these pins
raspi-gpio set 0 ip
raspi-gpio set 0 a0
raspi-gpio set 1 ip
raspi-gpio set 1 a0
fi
#shutdown
raspi-gpio set 27 op dh
#LED
raspi-gpio set 5 op dh
#
echo "Use 'raspiraw -y 1' to communicate with the sensor"
;;
'0004'|'0005'|'0006'|'000d'|'000e'|'000f')
echo "B Rev2 - I2C 0 on GPIOs 0 & 1. GPIOs 5 & 21 for LED and power"
# i2c on these pins
if [ "$kernel" = "4" ]
then
raspi-gpio set 0 ip
raspi-gpio set 0 a0
raspi-gpio set 1 ip
raspi-gpio set 1 a0
fi
#shutdown
raspi-gpio set 21 dh
#LED
raspi-gpio set 5 dh
;;
'0010'|'0012'|'0013'|'1041')
echo "A+, B+, B2, B2 (2837), and Zero (not W) all revisions - I2C 0 on GPIOs 28 & 29. GPIOs 32 & 41 for LED and power"
if [ "$kernel" = "4" ]
then
# i2c can be on pins 0 and 1, so make sure they are not set to alt0
raspi-gpio set 0 ip
raspi-gpio set 1 ip
# i2c on these pins
raspi-gpio set 28 ip
raspi-gpio set 28 a0
raspi-gpio set 29 ip
raspi-gpio set 29 a0
fi
#shutdown
raspi-gpio set 41 dh
#LED
raspi-gpio set 32 dh
;;
'0011'|'0014')
echo "Compute Module/ CM3 - I2C 0 on GPIO 0 & 1. GPIOs 2 & 3 for LED and power"
echo "Warning: This is just a default setting for cam1."
echo "Download dt-blob.bin from https://www.raspberrypi.org/documentation/hardware/computemodule/dt-blob-cam1.bin and place it in /boot/."
echo "For cable connection, see https://www.raspberrypi.org/documentation/hardware/computemodule/cmio-camera.md"
if [ "$kernel" = "4" ]
then
# i2c can be on pins 28 and 29, so make sure they are not set to alt0
raspi-gpio set 28 ip
raspi-gpio set 29 ip
# i2c on these pins
raspi-gpio set 0 ip
raspi-gpio set 0 a0
raspi-gpio set 1 ip
raspi-gpio set 1 a0
fi
# shutdown
raspi-gpio set 3 out
raspi-gpio set 3 dh
# LED
raspi-gpio set 2 out
raspi-gpio set 2 dh
;;
*)
# New format revision encodings
board_type=`cat /proc/cpuinfo | grep Revision | awk '{print substr($NF,length($NF)-2,2)}'`
case $board_type in
'02'|'03'|'04'|'09')
echo "A+, B+, B2, B2 (2837), and Zero (not W) all revisions - I2C 0 on GPIOs 28 & 29. GPIOs 32 & 41 for LED and power"
if [ "$kernel" = "4" ]
then
# i2c can be on pins 0 and 1, so make sure they are not set to alt0
raspi-gpio set 0 ip
raspi-gpio set 1 ip
# i2c on these pins
raspi-gpio set 28 ip
raspi-gpio set 28 a0
raspi-gpio set 29 ip
raspi-gpio set 29 a0
fi
#shutdown
raspi-gpio set 41 dh
#LED
raspi-gpio set 32 dh
;;
'0c')
echo "PiZero W - I2C 0 on GPIO 28 & 29. GPIOs 40 & 44 for LED and power"
if [ "$kernel" = "4" ]
then
# i2c can be on pins 0 and 1, so make sure they are not set to alt0
raspi-gpio set 0 ip
raspi-gpio set 1 ip
# i2c on these pins
raspi-gpio set 28 ip
raspi-gpio set 28 a0
raspi-gpio set 29 ip
raspi-gpio set 29 a0
fi
# shutdown
raspi-gpio set 44 dh
# LED
raspi-gpio set 40 dh
;;
'0a')
echo "Compute Module/ CM3 - I2C 0 on GPIO 0 & 1. GPIOs 2 & 3 for LED and power"
echo "Warning: This is just a default setting for cam1."
echo "Download dt-blob.bin from https://www.raspberrypi.org/documentation/hardware/computemodule/dt-blob-cam1.bin and place it in /boot/."
echo "For cable connection, see https://www.raspberrypi.org/documentation/hardware/computemodule/cmio-camera.md"
if [ "$kernel" = "4" ]
then
# i2c can be on pins 28 and 29, so make sure they are not set to alt0
raspi-gpio set 28 ip
raspi-gpio set 29 ip
# i2c on these pins
raspi-gpio set 0 ip
raspi-gpio set 0 a0
raspi-gpio set 1 ip
raspi-gpio set 1 a0
fi
# shutdown
raspi-gpio set 3 out
raspi-gpio set 3 dh
# LED
raspi-gpio set 2 out
raspi-gpio set 2 dh
;;
'08'|'0d'|'0e')
echo "Raspberry Pi3B / Pi3B+ / 3A"
# https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=120702&start=100
# Pins 44&45 Alt1=i2c0, alt2=i2c1
if [ "$kernel" = "4" ]
then
# i2c0 can be on pins 0 and 1, so make sure they are not set to alt0
raspi-gpio set 0 ip
raspi-gpio set 1 ip
raspi-gpio set 28 ip
raspi-gpio set 29 ip
# i2c on these pins
raspi-gpio set 44 ip
raspi-gpio set 44 a1
raspi-gpio set 45 ip
raspi-gpio set 45 a1
fi
#shutdown
# you need this one: https://github.com/6by9/rpi3-gpiovirtbuf
#raspi-gpio set 41 1
`dirname $0`/rpi3-gpiovirtbuf s 133 1
#LED
#raspi-gpio set 32 1
;;
'11')
echo "4B(1G/2G/4G/8G)"
# https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=120702&start=100
# Pins 44&45 Alt1=i2c0, alt2=i2c1
# i2c0 can be on pins 0 and 1, so make sure they are not set to alt0
if [ "$kernel" = "4" ]
then
# Do NOT alter 28&29 as they are used by the ethernet PHY.
raspi-gpio set 0 ip
raspi-gpio set 1 ip
# i2c on these pins
raspi-gpio set 44 ip
raspi-gpio set 44 a1
raspi-gpio set 45 ip
raspi-gpio set 45 a1
fi
#shutdown
# you need this one: https://github.com/6by9/rpi3-gpiovirtbuf
#raspi-gpio set 41 1
`dirname $0`/rpi3-gpiovirtbuf s 133 1
#LED
#raspi-gpio set 32 1
;;
'12')
echo "PiZero2W"
# Pins 44&45 Alt1=i2c0, alt2=i2c1
# i2c0 can be on pins 0 and 1, so make sure they are not set to alt0
if [ "$kernel" = "4" ]
then
# Do NOT alter 28&29 as they are used by the ethernet PHY.
raspi-gpio set 0 ip
raspi-gpio set 1 ip
# i2c on these pins
raspi-gpio set 44 ip
raspi-gpio set 44 a1
raspi-gpio set 45 ip
raspi-gpio set 45 a1
fi
#shutdown
raspi-gpio set 40 dh
# No LED line.
;;
'13')
# Pi400
echo "Failed: Pi400 doesn't have a camera connector"
;;
'14')
# CM4
echo "CM4 - assume CAM1 on 44&45"
if [ "$kernel" = "4" ]
then
# i2c can be on pins 44 and 45, so make sure they are not set to alt0
raspi-gpio set 44 ip
raspi-gpio set 45 ip
# i2c on these pins
raspi-gpio set 0 ip
raspi-gpio set 0 a0
raspi-gpio set 1 ip
raspi-gpio set 1 a0
fi
# shutdown
`dirname $0`/rpi3-gpiovirtbuf s 133 1
;;
*)
echo "Failed: don't know how to set GPIO for this board! Type is $board_type"
;;
esac
;;
esac
if [ "$kernel" = "4" ]
then
echo "Use i2c-0 for the sensor (-y 0)"
else
echo "Use i2c-10 for the sensor (-y 10)"
fi