你给的信息太少,先给出实物连接的照片,电机的供电可能有问题。
还有代码。

from pyb import Pin, Timer
inverse_left=False #change it to True to inverse left wheel
inverse_right=False #change it to True to inverse right wheel
ain1 = Pin('P0', Pin.OUT_PP)
ain2 = Pin('P1', Pin.OUT_PP)
bin1 = Pin('P2', Pin.OUT_PP)
bin2 = Pin('P3', Pin.OUT_PP)
ain1.low()
ain2.low()
bin1.low()
bin2.low()
pwma = Pin('P7')
pwmb = Pin('P8')
tim = Timer(4, freq=1000)
ch1 = tim.channel(1, Timer.PWM, pin=pwma)
ch2 = tim.channel(2, Timer.PWM, pin=pwmb)
ch1.pulse_width_percent(0)
ch2.pulse_width_percent(0)
def run(left_speed, right_speed):
if inverse_left==True:
left_speed=(-left_speed)
if inverse_right==True:
right_speed=(-right_speed)
if left_speed < 0:
ain1.low()
ain2.high()
else:
ain1.high()
ain2.low()
ch1.pulse_width_percent(abs(left_speed))
if right_speed < 0:
bin1.low()
bin2.high()
else:
bin1.high()
bin2.low()
ch2.pulse_width_percent(abs(right_speed))


这是电机图片,电机供电应该是没问题的,我把线这样插上去,转动轮子,mv板会亮灯,说明电路是通的

你上图的程序,保存成car.py,
还有一个pid.py和main.py。
你在ide里面运行的应该是main.py的内容
d@kidswong999 我先保存的car.py,pid.py和main.py,然后不行,于是我就改成了只测试电机的代码,就是car.run(100),结果还是不行,我在ide里面运行的时候小车不动,脱机运行也不动。
- 你需要用电压表测量各个引脚的电压。
- 你的电机供电有没有问题
好的吧,谢谢哦,我先去测试
@kidswong999 我测试了,那个输出口,,电机的马达那里没有信号是怎么回事呢?
那谁知道,可能是线没接好,可能是openmv没输出
我又试了下。用20v的没信号,用2v的就有微弱信号
@kidswong999 我又试了下。用20v的没信号,用2v的就有微弱信号
看你的电机驱动板有假焊,接触不良
就有信号就没信号输出,2v@一切皆有可能 假焊也不可能刚好那么巧啊,而且用20v
你需要看tb6612的每一个引脚的电平,对照一下真值表
@kidswong999 真值表是零正转,1反转
所以呢?
和真值表对照了吗?
或者说
你直接用杜邦线给tb6612电平,会不会转
@kidswong999 直接 给电平要转,我把代码改成了这样
from pyb import Pin, Timer
inverse_left=False #change it to True to inverse left wheel
inverse_right=False #change it to True to inverse right wheel
p0 = Pin('P0', Pin.OUT_PP)
p1 = Pin('P1', Pin.OUT_PP)
p2 = Pin('P2', Pin.OUT_PP)
p3 = Pin('P3', Pin.OUT_PP)
p0.low()
p1.low()
p2.low()
p3.low()
pwma = Pin('P7')
pwmb = Pin('P8')
tim = Timer(4, freq=1000)
ch1 = tim.channel(1, Timer.PWM, pin=pwma)
ch2 = tim.channel(2, Timer.PWM, pin=pwmb)
ch1.pulse_width_percent(0)
ch2.pulse_width_percent(0)
def run(left_speed, right_speed):
if inverse_left==True:
left_speed=(-left_speed)
if inverse_right==True:
right_speed=(-right_speed)
if left_speed < 0:
p0.value(0)
p1.value(1)
else:
p0.value(1)
p1.value(0)
ch1.pulse_width_percent(abs(left_speed))
if right_speed < 0:
p2.value(0)
p3.value(1)
else:
p2.value(1)
p3.value(0)
ch2.pulse_width_percent(abs(right_speed))
这样可以吗?
@kidswong999 直接用杜邦线会转,我把怎么和真值表对照啊?就看高低电平和真值表是否对应吗?还有怎么用杜邦线和驱动连线呀?拜托了,,弄了这么久都还没弄好,,唉
老哥 问题解决了么 我的情况跟你一样