jetson nano使用PCA9685驱动舵机

1.导入smbus模块:sudo apt-get install python-smbus
2.导入i2c库:sudo apt-get install i2c-tools
3.导入adafruit库:sudo pip3 install adafruit-circuitpython-lis3dh
sudo pip3 install adafruit-circuitpython-motor
pip3 install adafruit-circuitpython-servokit
4.硬件接线:
SCL ——接Nano 引脚第5脚(GEN2_I2C_SCL)
SDA ——接Nano 引脚第3脚(GEN2_I2C_SDA)
jetson nano与驱动板接好电源,驱动板接好外界电源,电机与驱动板的线也接好

5.python程序:
import time
from board import SCL, SDA
import busio
from adafruit_motor import servo
from adafruit_pca9685 import PCA9685

i2c = busio.I2C(SCL, SDA)

pca = PCA9685(i2c)
pca.frequency = 50

#7号口输出PWM 500-2500us对应0-180度,程序就可以改成500和2500
servo7 = servo.Servo(pca.channels[7],min_pulse=500, max_pulse=2500)

#舵机旋转度
servo7.angle = 0
time.sleep(2)
servo7.angle = 90
time.sleep(2)

pca.deinit()

你可能感兴趣的:(ubuntu)