logo

大佬们 请问要怎么通过uart串口向主板发送浮点型数据

2022-03-21 13:20
P
rm4a

大佬们 请问要怎么通过uart串口向主板发送浮点型数据

2022-03-21 22:24
I
网红小智智 星瞳科技
import time
from pyb import UART
import struct
# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 19200)

while(True):
    p = 3.1415
    uart.write(struct.pack('<f', p))#发送小端,float,4字节
    uart.write(struct.pack('<d', p))#发送小端,double,8字节
    time.sleep_ms(1000)

参考:https://docs.python.org/zh-cn/3/library/struct.html

2022-03-22 12:49
P
rm4a

@kidswong999 谢谢大佬