Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Raspberry PI-访问0x40时出错:检查I2C地址_Python_Linux_Raspberry Pi - Fatal编程技术网

Python Raspberry PI-访问0x40时出错:检查I2C地址

Python Raspberry PI-访问0x40时出错:检查I2C地址,python,linux,raspberry-pi,Python,Linux,Raspberry Pi,我尝试在我的raspberry PI上运行这个python伺服脚本。我从这里得到了这个密码 python伺服脚本 #!/usr/bin/python from Adafruit_PWM_Servo_Driver import PWM import time # =========================================================================== # Example Code # ========================

我尝试在我的raspberry PI上运行这个python伺服脚本。我从这里得到了这个密码

python伺服脚本

#!/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)
我尝试这个解决方案,但没有帮助


请给出建议。

首先,您不希望每次都以root用户身份登录:只需在需要时放置sudo并键入密码即可

第二:i2c总线配置不正确或接线错误。i2cdetect命令没有看到任何附加内容。 您已安装smbus和i2ctools,但是否已将i2c-bcm2708从黑名单中删除? 您需要键入:

sudo nano /etc/modprobe.d/raspi-blacklist.conf
并在线路i2c-dev和i2c-bcm2708上添加a

发件人:

致:

然后,您需要在启动时为i2c添加模块

sudo nano /etc/modules
并将这两行添加到文件末尾:

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
现在,如果你像以前一样在图表中看到除了点以外的任何东西,检查你的接线。 如果您看到了什么,那就是伺服驱动器的地址。

可能更适合于。
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