这次准备的作品是准备用迪文屏做核酸检测登记站的作品,首先要解决的是串口通讯的问题,今天抽空熟悉一下开发板,学习了一下K210的基本操作:
首先是学习串口的IO配置,首先在官网找到资料:machine.UART - Sipeed Wiki
根据其他网友的资料结合写了测试的代码如下:
import sensor, image, time, lcd
from machine import UART, Timer
from fpioa_manager import fm
fm.register(6,fm.fpioa.UART1_RX, force=True) #rx为开发板的6
fm.register(7,fm.fpioa.UART1_TX, force=True) #tx为开发板的7
uart = UART(UART.UART1, 460800, read_buf_len=4096) #初始化460800
uart.write('start...') #开机发送一行字符
lcd.init(freq=15000000)
sensor.reset() # Reset and initialize the sensor. It will
# run automatically, call sensor.run(0) to stop
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
while(True):
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
lcd.display(img) # Display on LCD
#print(clock.fps()) # Note: MaixPy's Cam runs about half as fast when connected
# to the IDE. The FPS should increase once disconnected.
if uart.any():
read_data = uart.read() #读取数据
if read_data:
uart.write(read_data) #把读取的数据返回
print(read_data) #在终端打印出来
因为我想尽可能的得到最好适应迪文屏的波特率,我这里只适配到最高460800的速度。虽然961200也可以,但是好象迪文屏不支持这个波特率。