[code][1]我有一个grovepi来连接树莓派上的grove pi振动传感器。我已经使用以下命令在我的树莓派上下载了 Groove 软件:
$cd /home/pi/Desktop
$ sudo git clone https://github.com/DexterInd/GrovePi
$ cd /home/pi/Desktop/GrovePi/Script
$ sudo chmod +x install.sh
$ sudo ./install.sh
$ sudo pip install grovepi"
在此之后,我重新启动了我的树莓派,然后当我进入文件夹时:
$cd/home/pi/Desktop/GrovePi/Software/Python
$sudo python grove_piezo_vibration_sensor.py
我收到以下错误:
Trceback (most recent call last):
File "grove_piezo_vibration_sensor.py", line 49, in <module>
print(grovepi.analogRead(piezo))
File "/home/pi/Desktop/GrovePi/Software/Python/grovepi.py", line 227, in analogRead
return number[1] * 256 +number[2]
TypeError: 'int' object has no attribute '__getitem__'
我使用的代码是:
import time
import grovepi
# Connect the Grove Piezo Vibration Sensor to analog port A0
# OUT,NC,VCC,GND
piezo = 0
grovepi.pinMode(piezo,"INPUT")
while True:
try:
# When vibration is detected, the sensor outputs a logic high signal
print grovepi.analogRead(piezo)
time.sleep(.5)
except IOError:
print "Error"
你能告诉我我做错了什么吗?谢谢!