编程语言
首页 > 编程语言> > nRF52832-Bluefruit52学习之MicroPython开发(6)-- 16路PWM驱动PCA9685(I2C)

nRF52832-Bluefruit52学习之MicroPython开发(6)-- 16路PWM驱动PCA9685(I2C)

作者:互联网

nRF52832技术交流群:680723714
       nRF52832-Bluefruit52核心板详细介绍
https://blog.csdn.net/solar_Lan/article/details/88688451
       MicroPython固件持续更新下载,请加QQ群:680723714,群名:Bluefruit52官方技术群
       nRF52832板子的MicroPython学习Wiki请浏览地址
https://www.afantor.cc/mpy/html/nrf52/quickref.html


I2C驱动应用

nRF52832有两个硬件I2C模块,Bluefruit52板子I2C连接引脚为:

SDA---P0_25

SCL---P0_26

I2C的Python API接口函数:

from machine import Pin, I2C

# construct an I2C bus
i2c = I2C(0, scl=Pin(26), sda=Pin(25))

i2c.scan()
i2c.start()
i2c.stop()

i2c.readfrom(0x3a, 4)   # read 4 bytes from slave device with address 0x3a
i2c.writeto(0x3a, '12') # write '12' to slave device with address 0x3a

buf = bytearray(10)     # create a buffer with 10 bytes
i2c.writeto(0x3a, buf)  # write the given buffer to the slave

PCA9685模块原理图

I2C驱动PCA9685的API接口函数:

from machine import I2C,Pin
from pca9685 import PCA9685

i2c = I2C(0,scl=Pin(26),sda=Pin(25))
pca = PCA9685(i2c,address=0x40)  #new a pca object.

pca.freq(freq=50)   #set freq = 50Hz

pca.reset() #reset PCA9685 register.
pca.pwm(0,1,0) 

pca.duty(0,90,invert=False)



二次封装PWM驱动舵机API函数接口:

from machine import I2C,Pin
from servo import Servos

i2c = I2C(0,scl=Pin(26),sda=Pin(25))
servo = Servos(i2c,address=0x40)  #new a servo object.

servo.position(0,90) #set servo run to position(range:0~180).
servo.release()    #release servo.

 

标签:MicroPython,i2c,Pin,servo,16,PCA9685,pca,I2C
来源: https://blog.csdn.net/solar_Lan/article/details/90733050