蓝牙收发
from pyb import UART
baudrate = 38400
uart = UART(1, baudrate)
串口对应GPIO
- UART(4) is on XA: (TX, RX) = (X1, X2) = (PA0, PA1)
- UART(1) is on XB: (TX, RX) = (X9, X10) = (PB6, PB7)
- UART(6) is on YA: (TX, RX) = (Y1, Y2) = (PC6, PC7)
- UART(3) is on YB: (TX, RX) = (Y9, Y10) = (PB10, PB11)
- UART(2) is on: (TX, RX) = (X3, X4) = (PA2, PA3)
uart.init(baudrate, bits=8, parity=None, stop=1, *, timeout=1000, flow=None, timeout_char=0, read_buf_len=64)
- baudrate:波特率
- bits:数据位,7/8/9
- parity:校验,None, 0 (even) or 1 (odd)
- stop:停止位,1/2
- flow:流控,可以是 None, UART.RTS, UART.CTS or UART.RTS | UART.CTS
- timeout:读取一个字节的超时时间(ms)
- timeout_char:两个字节之间超时时间
uart.write()
uart.read([num_of_bytes])
PWM
motor = Timer(5, freq=2000).channel(3, Timer.PWM, pin=Pin.board.X3)
Timer(nclock, freq)
Timer.channel(channel, mode, pin)
这里的参数参考第一张图
motor.pulse_width_percent(50)
从 0 到 50