Development board: K210 AIRV R3 version widora
Development environment: MaixPy IDE silicon speed home
Required reference sites:
https://cn.maixpy.sipeed.com/zh/api_reference/Maix/fpioa.html
https://cn.maixpy.sipeed.com/zh/api_reference/Maix/gpio.html
https://cn.maixpy.sipeed.com/zh/api_reference/machine/uart.html
New file _5uart.py
The code uses the timer TIM in the previous section to modify it
Call the serial port, and call the GPIO management
from machine import UART
from fpioa_manager import fm
Look at the schematic
WIFI serial port corresponds to IO6 and IO7
Refer to the above code modification
fm.register(6,fm.fpioa.UART2_TX)
fm.register(7,fm.fpioa.UART2_RX)
uart_wifi = UART(UART.UART2, 115200, 8, None, 1, timeout=1000, read_buf_len=4096)
uart: UART.UART2 #Use serial port 2
Baud rate is 115200, 8 is data bit, parity check, stop bit 1
tiimeout timeout acceptance time is 1000ms
Accept cache size is 4096
Send function
uart_wifi.write("AT\r\n")
Accept function
read_data = uart_wifi.read()
To realize the function:
K210 sends AT to computer
K210 accepts the command sent by the computer to K210, judges the accepted characters, turns on and off the LED light
code show as below
import utime
from Maix import FPIOA
from Maix import GPIO
from machine import UART
from fpioa_manager import fm
fpioa = FPIOA()
fpioa.set_function(17,fpioa.GPIOHS0)
fpioa.set_function(18,fpioa.GPIOHS1)
led1 = GPIO(GPIO.GPIOHS0,GPIO.OUT)
led2 = GPIO(GPIO.GPIOHS1,GPIO.OUT)
led1.value(0)
led2.value(0)
fm.register(6,fm.fpioa.UART2_TX)
fm.register(7,fm.fpioa.UART2_RX)
uart_wifi = UART(UART.UART2, 115200, 8, None, 1,
timeout=1000, read_buf_len=4096)
uart_wifi.write("AT\r\n")
while(1):
read_data = uart_wifi.read()
if(read_data != None):
print(read_data)
if(read_data == b'A'):
led1.value(1)
elif (read_data ==b'a'):
led1.value(0)
After typing the code, connect to the development board and click to run
phenomenon:
Open the serial port assistant, select the port of WIFI (my side is COM3, and COM4 is the serial port of K210, I will not move him)
Click Run on MAIXPY IDE, it will send the AT character to COM3 (if not sent, cancel the operation again and run again)
In the serial port assistant, send a string, K210 will receive all
Send A, you can see the LED of K210 will light up
Sending other characters will not affect the LED light
When sending a, the LED light will be extinguished