树莓派下安装PCA9685的python驱动程序
2016-12-08 09:24
211 查看
树莓派下安装PCA9685的python驱动程序
# Adafruit Python PCA9685
Python code to use the PCA9685 PWM servo/LED controller with a Raspberry Pi or BeagleBone black.
#使用树莓派或者BeagleBone black 的Python 源码 驱动PCA9685 输出PWM波控制舵机(伺服电机)/LED灯
## Installation#安装配置
To install the library from source (recommended) run the following commands on a Raspberry Pi or other Debian-based OS system:
#从源码库安装,在树莓派或者其他Debian-based系统上运行以下指令
sudo apt-get install git build-essential python-dev
cd ~
git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git
cd Adafruit_Python_PCA9685
sudo python setup.py install
#完成 以下部分为不带例子程序安装方法
Alternatively you can install from pip with:
sudo pip install adafruit-pca9685
Note that the pip install method **won't** install the example code.
# Adafruit Python PCA9685
Python code to use the PCA9685 PWM servo/LED controller with a Raspberry Pi or BeagleBone black.
#使用树莓派或者BeagleBone black 的Python 源码 驱动PCA9685 输出PWM波控制舵机(伺服电机)/LED灯
## Installation#安装配置
To install the library from source (recommended) run the following commands on a Raspberry Pi or other Debian-based OS system:
#从源码库安装,在树莓派或者其他Debian-based系统上运行以下指令
sudo apt-get install git build-essential python-dev
cd ~
git clone https://github.com/adafruit/Adafruit_Python_PCA9685.git
cd Adafruit_Python_PCA9685
sudo python setup.py install
#完成 以下部分为不带例子程序安装方法
Alternatively you can install from pip with:
sudo pip install adafruit-pca9685
Note that the pip install method **won't** install the example code.
#以下为python源程序 #输入通道与角度。即可选通并使该通道的舵机转动到相应的角度 from __future__ import division #导入 __future__ 文件的 division 功能函数(模块、变量名....) #新的板库函数 //= import time # Import the PCA9685 module. import Adafruit_PCA9685 #导入Adafruit_PCA9685模块 # Uncomment to enable debug output. #import logging #logging.basicConfig(level=logging.DEBUG) #调试打印日志输出 # Initialise the PCA9685 using the default address (0x40). pwm = Adafruit_PCA9685.PCA9685() #把Adafruit_PCA9685.PCA9685()引用地址赋给PWM标签 # Alternatively specify a different address and/or bus: #pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2) #2^12精度 角度转换成数值 #angle输入的角度值(0--180) #pulsewidth高电平占空时间(0.5ms--2.5ms) #/1000将us转换为ms #20ms时基脉冲(50HZ) #pulse_width=((angle*11)+500)/1000; //将角度转化为500(0.5)<-->2480(2.5)的脉宽值(高电平时间) angle=180时 pulse_width=2480us(2.5ms) #date/4096=pulse_width/20 ->有上pulse_width的计算结果得date=4096*( ((angle*11)+500)/1000 )/20 -->int date=4096((angle*11)+500)/20000; def set_servo_angle(channel, angle): #输入角度转换成12^精度的数值 date=4096*((angle*11)+500)/20000 #进行四舍五入运算 date=int(4096*((angle*11)+500)/(20000)+0.5) pwm.set_pwm(channel, 0, date) # Set frequency to 50hz, good for servos. pwm.set_pwm_freq(50) print('Moving servo on channel x, press Ctrl-C to quit...') while True: # Move servo on channel O between extremes. channel=int(input('pleas input channel:')) angle=int(input('pleas input angle:')) set_servo_angle(channel, angle) #time.sleep(1)
相关文章推荐
- 在树莓派2或树莓派B+上安装Python和OpenCV的教程
- 树莓派高级GPIO库,wiringpi2 for python使用笔记(一)安装
- 树莓派pca9685舵机驱动板python驱动
- 树莓派3 安装vim8.0 编译python2支持
- 树莓派安装MySQL并关联Python
- 在树莓派(Raspberry Pi)上编译安装更新版本的Python
- 树莓派python安装requests库
- centOS中安装python-mysqldb(python与Mysql之间的驱动程序)
- 在树莓派B+上编译安装opencv 3.1.0 for both python
- 转载:树莓派安装Python-OpenCV
- 树莓派安装OpenCV后的示例小程序Python
- linux 树莓派下 python安装scipy
- 如何在树莓派上安装python和GPIO库
- 在树莓派(Debian系统)上安装python软件包pymssql
- 树莓派,PCA9685 pwm控制
- 树莓派安装mysql数据库并且通过python来进行存储操作
- 树莓派 - 2 Python - a 包的安装和查看
- 树莓派安装Python-OpenCV
- 树莓派python入门(1):树莓派系统安装与初次连接
- 树莓派安装Python-OpenCV