2024-09-26 17:58:28 发布
网友
如何使用覆盆子Pi和Python连接Adafruit_PCA9685-I2C?
你可以使用Raspberry pi和python一次单独运行16个伺服电机。我使用reconnect\u io\u func()函数,该函数将检查是否与Raspberry pi连接,如果没有,则将继续尝试连接,直到成功连接。然后将伺服电机的运行值
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一次单独运行16个伺服电机。我使用reconnect\u io\u func()函数,该函数将检查是否与Raspberry pi连接,如果没有,则将继续尝试连接,直到成功连接。然后将伺服电机的运行值
相关问题 更多 >
编程相关推荐