2014-06-21 74 views
0

我嘗試在我的樹莓派上運行這個python伺服腳本。我得到這個代碼從這裏Raspberry PI - 訪問0x40時出錯:檢查你的I2C地址

https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/blob/master/Adafruit_PWM_Servo_Driver/Servo_Example.py

蟒蛇伺服腳本

#!/usr/bin/python 

from Adafruit_PWM_Servo_Driver import PWM 
import time 

# =========================================================================== 
# Example Code 
# =========================================================================== 

# Initialise the PWM device using the default address 
# bmp = PWM(0x40, debug=True) 
pwm = PWM(0x40, debug=True) 

servoMin = 150 # Min pulse length out of 4096 
servoMax = 600 # Max pulse length out of 4096 

def setServoPulse(channel, pulse): 
    pulseLength = 1000000     # 1,000,000 us per second 
    pulseLength /= 60      # 60 Hz 
    print "%d us per period" % pulseLength 
    pulseLength /= 4096      # 12 bits of resolution 
    print "%d us per bit" % pulseLength 
    pulse *= 1000 
    pulse /= pulseLength 
    pwm.setPWM(channel, 0, pulse) 

pwm.setPWMFreq(60)      # Set frequency to 60 Hz 
while (True): 
    # Change speed of continuous servo on channel O 
    pwm.setPWM(0, 0, servoMin) 
    time.sleep(1) 
    pwm.setPWM(0, 0, servoMax) 
    time.sleep(1) 

我嘗試這個解決辦法,但沒有幫助。

https://learn.adafruit.com/downloads/pdf/adafruit-16-channel-servo-driver-with-raspberry-pi.pdf

enter image description here enter image description here

請指點。

+0

可能更適合http://raspberrypi.stackexchange.com。 – milancurcic

回答

0

首先,您不希望每次都以root身份登錄:只需在需要時輸入sudo並鍵入密碼即可。

第二:您的i2c總線配置不正確或接線錯誤。 命令i2cdetect沒有看到任何附件。 你已經安裝了smbus和i2ctools,但是你是否已經從黑名單中刪除了i2c-bcm2708? 您需要鍵入:

sudo nano /etc/modprobe.d/raspi-blacklist.conf 

,並添加#到線I2C-dev的和I2C-bcm2708。

來自:

blacklist i2c-dev 
blacklist i2c-bcm2708 

到:

#blacklist i2c-dev 
#blacklist i2c-bcm2708 

比你需要在啓動時

sudo nano /etc/modules 

這兩行添加模塊I2C和增加的結束file:

i2c-bcm2708 
i2c-dev 

現在你可以手動加載這些模塊與命令

sudo modprobe i2c-bcm2708 
sudo modprobe i2c-dev 

現在再次鍵入:

sudo i2cdetect -y 0 #if you have a rev1 board 

sudo i2cdetect -y 1 #if you have a rev2 board 

現在,如果你看到的圖表中任何東西,但點(像以前一樣),檢查你的接線。 如果您看到某些東西,那就是伺服驅動器的地址。

+0

我先試試.. –

+0

它不工作。 –