MicroPython用A4988控制步进电机(代码)

有关A4988的资料可自行百度或参考这篇文章步进电机驱动A4988

下面直接看代码

from pyb import Pin, Timer

p_out1 = Pin('X3', Pin.OUT_PP)     # DIR接X3 
p_out1.high()

p_out2 = Pin('X4', Pin.OUT_PP)	    # MS1,MS2,MS3对应X4,X5,X6,都取高电平,即16细分
p_out2.high()
p_out3 = Pin('X5', Pin.OUT_PP)
p_out3.high()
p_out4 = Pin('X6', Pin.OUT_PP)
p_out4.high()

tm2 = Timer(2, freq=100)
tm3 = Timer(5, freq=200)    # 选择定时器5,频率200hz(决定速度)
led3 = tm2.channel(1, Timer.PWM, pin=Pin.cpu.A15)
led3.pulse_width_percent(50)    #亮灯led3
a4 = tm3.channel(1, Timer.PWM, pin=Pin.cpu.A0)  # 选择通道1和定时器5对应引脚A0
a4.pulse_width_percent(50)   # 占空比50%。STEP接X1即A0

A4988引脚图
MicroPython用A4988控制步进电机(代码)_第1张图片

你可能感兴趣的:(MicroPython用A4988控制步进电机(代码))