在Raspberry pi Python中连接Adafruit_PCA9685- I2C接口
Connect Adafruit_PCA9685- I2C interface in Raspberry pi Python
如何使用 Raspberry Pi 和 Python 连接 Adafruit_PCA9685- I2C?
您可以使用 Raspberry pi 和 python.I 一次单独使用 16 个伺服电机 运行 reconnect_io_func() 函数将检查是否与 raspberry pi 连接,如果没有则继续尝试连接直到成功 connect.Then 将是 运行 伺服电机值
from __future__ import division
import Adafruit_PCA9685
def reconnect_io_func():
try:
pwm = Adafruit_PCA9685.PCA9685()
return pwm
except Exception as error:
if "Remote I/O error" in (error):
reconnect_io = True
while reconnect_io:
try:
# print("while Error: "+str(error))
pwm = Adafruit_PCA9685.PCA9685()
# print(pwm)
reconnect_io = False
return pwm
except Exception as error:
# print((error))
reconnect_io = True
servo_min = 150 # Min pulse length out of 4096
servo_max = 600 # Max pulse length out of 4096
pwm = reconnect_io_func()
pwm.set_pwm_freq(60)
if __name__ == '__main__':
pwm.set_pwm(0, 0, 420)
pwm.set_pwm(1, 0, 420)
pwm.set_pwm(2, 0, 307)
pwm.set_pwm(3, 0, 420)
pwm.set_pwm(4, 0, 307)
pwm.set_pwm(5, 0, 307)
pwm.set_pwm(6, 0, 307)
pwm.set_pwm(7, 0, 307)
pwm.set_pwm(8, 0, 0)
# print (" i am here")
如何使用 Raspberry Pi 和 Python 连接 Adafruit_PCA9685- I2C?
您可以使用 Raspberry pi 和 python.I 一次单独使用 16 个伺服电机 运行 reconnect_io_func() 函数将检查是否与 raspberry pi 连接,如果没有则继续尝试连接直到成功 connect.Then 将是 运行 伺服电机值
from __future__ import division
import Adafruit_PCA9685
def reconnect_io_func():
try:
pwm = Adafruit_PCA9685.PCA9685()
return pwm
except Exception as error:
if "Remote I/O error" in (error):
reconnect_io = True
while reconnect_io:
try:
# print("while Error: "+str(error))
pwm = Adafruit_PCA9685.PCA9685()
# print(pwm)
reconnect_io = False
return pwm
except Exception as error:
# print((error))
reconnect_io = True
servo_min = 150 # Min pulse length out of 4096
servo_max = 600 # Max pulse length out of 4096
pwm = reconnect_io_func()
pwm.set_pwm_freq(60)
if __name__ == '__main__':
pwm.set_pwm(0, 0, 420)
pwm.set_pwm(1, 0, 420)
pwm.set_pwm(2, 0, 307)
pwm.set_pwm(3, 0, 420)
pwm.set_pwm(4, 0, 307)
pwm.set_pwm(5, 0, 307)
pwm.set_pwm(6, 0, 307)
pwm.set_pwm(7, 0, 307)
pwm.set_pwm(8, 0, 0)
# print (" i am here")