python - Raspberry Pi - 访问 0x40 : Check your I2C address 时出错

标签 python linux raspberry-pi

我尝试在我的 Raspberry Pi 上运行这个 Python 伺服脚本。我从这里得到了这个代码:

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

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)

我尝试了这个解决方案,但没有帮助。

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

enter image description here

enter image description here

接下来我可以尝试什么?

最佳答案

首先,您不想每次都以 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

您需要在启动时添加 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

现在,如果您在图表中看到除了点以外的任何内容(像以前一样),请检查您的接线。 如果您看到某些内容,那就是伺服驱动器的地址。

关于python - Raspberry Pi - 访问 0x40 : Check your I2C address 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24342085/

相关文章:

python - 如何强制 Altair 在特定轴上对热图(矩形)进行排序?

python - 选择数组中的值

c++ - 如何链接到共享库的旧版本

go - 如何用golang直接画到树莓派屏幕上

python - Raspberry Pi 上的 VoIP 服务器/客户端

jquery - AJAX 的 Django ORM 问题

python - 我的 SVG 图像未加载

linux - 如何将存档的所有对象包含在共享对象中?

php - 关于托管的 XDebug - 安全性?

c - SysGCC 工具链在 sysroot 中找不到文件