当前位置:网站首页>Thousands of sails pass by the side of the sunken boat, and thousands of trees spring before the diseased tree
Thousands of sails pass by the side of the sunken boat, and thousands of trees spring before the diseased tree
2022-06-22 07:01:00 【Mrli0530】
One 、 routine
1. Serial routines
import time
from fpioa_manager import fm
from machine import UART
#************************* A serial port 1 Parameters *******************************
fm.register(32, fm.fpioa.UART1_TX, force=True)
fm.register(33, fm.fpioa.UART1_RX, force=True)
uart_1 = UART(UART.UART1, 115200, 8, 0, 0, timeout=1000, read_buf_len=4096)
####********************** A serial port 2 Parameters ********************
fm.register(34, fm.fpioa.UART2_TX, force=True)
fm.register(35, fm.fpioa.UART2_RX, force=True)
uart_2 = UART(UART.UART2, 9600, 8, 0, 0, timeout=1000, read_buf_len=4096)
while(1):
#*********** receive **********#
read_data1 =str(uart_1.read())
if read_data1!='None':
print(read_data1)
read_data2 =str(uart_2.read())
if read_data2!='None':
print(read_data2)
#********* send out ***********#
uart_1.write("uart_1")
time.sleep_ms(1000)
uart_2.write("uart_2")
time.sleep_ms(1000)
You can pay proper attention to the stop bit when the serial port sends
2.I/O Use
FPIOA ( Field programmable IO array , Field Programmable Input and Output Array)
High speed GPIO:
High speed GPIO by GPIOHS, common 32 individual . It has the following characteristics :
Configurable input and output signals
Every IO With independent interrupt source
Interrupt supports edge trigger and level trigger
Every IO Can be assigned to FPIOA On 48 One of the pins
Configurable pull-down menu , Or high resistance
Universal GPIO:
Universal GPIO common 8 individual , It has the following characteristics :
8 individual IO Use an interrupt source
Configurable input and output signals
Configurable trigger IO Total interruption , Edge trigger and level trigger
Every IO Can be assigned to FPIOA On 48 One of the pins
PULL: GPIO Up and down mode
• GPIO.PULL_UP Pull up
• GPIO.PULL_DOWN The drop-down
• GPIO.PULL_NONE Neither pull up nor pull down
1. Input usage
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(17,fpioa.GPIOHS0)
key = GPIO(GPIO.GPIOHS0,GPIO.IN)
while 1:
print(key.value())
2. Output usage
from Maix import FPIOA
from Maix import GPIO
fpioa = FPIOA()
fpioa.set_function(18,fpioa.GPIOHS1)
led2 = GPIO(GPIO.GPIOHS1,GPIO.OUT)
while(1):
led2.value(0)
Two 、image and LCD
1. Image clipping
face_cut1 = img.cut(X, Y, W, H)# The shear zone
face_cuta = face_cut1.resize(224, 224)# Transform image size
a=face_cuta.pix_to_ai()# Convert to a format acceptable to the microcontroller
lcd.display(face_cut1,oft=(0,0))# stay LCD Show
del (face_cuta2)# Release
2. Writing Chinese characters
Official display connection 


Then add it to the program by yourself , The shortcut is as follows :
Copy the following one by one
LCD knowledge
lcd.init(type=1, freq=15000000, color=lcd.BLACK, invert = 0, lcd_type = 0)
invert: LCD Reverse color display
lcd.rotation(dir);dir: Value range [0,3], from 0 To 3 Rotate clockwise
lcd.display(img, oft=(x, y))
3、 ... and 、 Tips
1.python How to write for loop ?
for i in range(0,90):# loop 90 Time
2. Knowledge about arrays
Take the minimum value of the array and know the number of
#**** Calculate the minimum distance ****#
x=[a,b,c,d,f]
aa=[a,b,c,d,f]
# Go to 0 The operation is stupid , Can directly if x=0: pass
for z in x:
if 0 in x:
x.remove(0)
zz=int(min(x))
a6=aa.index(zz)
collection 100 And get the mode , Very practical, must see !!!
# First define 100 individual 0, Silly , It can be used for To write , I am lazy .
e_1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
# use d_4 This variable adds itself to assign a value 100 Time , The whole is written in if else Inside the loop , Last reset
if d_4<100:
e_1[d_4]=r[2]
d_4=d_4+1
else:
print(max(e_2, default=' The list is empty. ', key=lambda v: e_2.count(v))) # This sentence is the cream.
e_1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Four 、 works
One 、 Face recognition
1. Face detection
Model address :
https://cn.dl.sipeed.com/MAIX/MaixPy/model
Program :
import sensor,image,lcd
import KPU as kpu
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)
sensor.set_vflip(1)
sensor.set_auto_gain(1,50)
sensor.run(1)
lcd.init(freq=15000000)
lcd.rotation(0)
task = kpu.load(0x300000) # You need to put the model (face.kfpkg) In the flash address 0x300000
# task = kpu.load("/sd/face.kmodel")# Put the model in SD In the card .
# Model tracing parameters
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
# initialization yolo2 The Internet
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
while(True):
img = sensor.snapshot()
code = kpu.run_yolo2(task, img)# function yolo2 The Internet
if code:
for i in code:
print(i)
a = img.draw_rectangle(i.rect())
a = lcd.display(img)
a = kpu.deinit(task)# Uninitialize
Identify how many faces are in a picture ( most 10 individual )
import sensor,image,lcd
import KPU as kpu
#**************** Camera parameter settings ************#
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_hmirror(0)
sensor.set_vflip(0)
sensor.set_auto_gain(1,200)
sensor.run(1)
lcd.init(freq=15000000)
lcd.rotation(0)
#**************** Neural network parameters ************#
task = kpu.load(0x300000) # You need to put the model (face.kfpkg) In the flash address 0x300000
# task = kpu.load("/sd/face.kmodel")# Put the model in SD In the card .
# Model tracing parameters
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
# initialization yolo2 The Internet
a = kpu.init_yolo2(task, 0.3, 0.3, 5, anchor)
#**************** Defining variables ****************#
e_1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
e_2=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
z=z_1=z_2=0
d_1=d_2=0
b_1=b_2=0
#*************** Region I image clipping *************#
def quyu1():
global z_1
global d_1
global b_1
face_cut1 = img.cut(0, 0, 160, 120)# The shear zone
a = lcd.display(face_cut1,oft=(0,0))
face_cuta1 = face_cut1.resize(320, 240)# Transform image size
face_cuta1.pix_to_ai()# Convert to a format acceptable to the microcontroller
code = kpu.run_yolo2(task, face_cuta1)# function yolo2 The Internet
if code:
for i in code:
#print("1 District :",i.objnum())
if d_1<50:
e_1[d_1]=i.objnum()
d_1=d_1+1
else:
z_1=int(max(e_1))
print("1 District :",z_1)
b_1=1
a = img.draw_rectangle(int(i.x()/2),int(i.y()/2),int(i.w()/2),int(i.h()/2))
del (face_cuta1)# Release
del (face_cut1)# Release
#*************** Region 2 image clipping *************#
def quyu2():
global z_2
global d_2
global b_2
face_cut2 = img.cut(160, 0, 160, 120)# The shear zone
a = lcd.display(face_cut2,oft=(160,0))
face_cuta2 = face_cut2.resize(320, 240)# Transform image size
face_cuta2.pix_to_ai()# Convert to a format acceptable to the microcontroller
code = kpu.run_yolo2(task, face_cuta2)# function yolo2 The Internet
if code:
for i in code:
a = img.draw_rectangle(i.rect())
if d_2<50:
print(" Looping detection , The first :",d_2," Time ")
e_2[d_2]=i.objnum()
d_2=d_2+1
else:
z_2=int(max(e_2))
print("2 District :",z_2)
b_2=1
del (face_cuta2)# Release
del (face_cut2)# Release
#*************** Main circulation *******************#
while(True):
img = sensor.snapshot()
quyu1()
#*********dier****************
quyu2()
if b_1==1 and b_2==1:
z=z_1+z_2
print(" The total number of :",z)
z=z_1=z_2=0
d_1=d_2=0
b_1=b_2=0
e_1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
e_2=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
a = kpu.deinit(task)# Uninitialize
边栏推荐
- [anomaly detection] malware detection: mamadroid (dnss 2017)
- Golang calls sdl2, plays PCM audio, and reports an error signal arrived during external code execution.
- [internship] cross domain problems
- Correspondence between pytorch and torchvision
- 【GAN】SAGAN ICML‘19
- In depth analysis of 20million OP events stolen by optimization (including code)
- 【GAN】SentiGAN IJCAI’18 Distinguished Paper
- Access to control objects in JS
- Tpflow v6.0.6 official release
- Self supervised learning for general out of distribution detection AAAI '20
猜你喜欢

QT connect to Alibaba cloud using mqtt protocol

leetcode:面试题 08.12. 八皇后【dfs + backtrack】
![[write CPU by yourself] implementation of exception related instructions](/img/79/f2d5e04cfe60e8ae6ea735787ae88b.jpg)
[write CPU by yourself] implementation of exception related instructions

Introduction to 51 Single Chip Microcomputer -- the use of Keil uvision4

Single cell literature learning (Part3) -- dstg: deconvoluting spatial transcription data through graph based AI

Xh_CMS渗透测试文档

Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things

一个算子在深度学习框架中的旅程

Introduction and use of cookies

Theory and application of naturallanguageprocessing
随机推荐
圣杯布局和双飞翼布局的区别
Sharing the strongest summer vacation plan of ape tutoring: the summer vacation plan is the same as learning and playing
Common evaluation indicators of recommended system: ndcg, recall, precision, hit rate
Introduction and use of cookies
Great progress in code
iframe框架,,原生js路由
Fundamentals of neural network (notes, for personal use)
Advanced usage of setting breakpoints during keil debugging
如何才能有效缓解焦虑?看看猿辅导怎么说
Pdf to picture implementation
Wildfire stm32f407zgt6 learning notes beginner level chapter basic knowledge points
PIP for source changing and accelerated downloading
Tpflow V6.0.6 正式版发布
matlab 实现中值滤波
[anomaly detection] malware detection: mamadroid (dnss 2017)
Single cell literature learning (Part3) -- dstg: deconvoluting spatial transcription data through graph based AI
Py's optbinning: introduction, installation and detailed introduction of optbinning
关于solidity的delegatecall的坑
Custom implementation of bind method in JS
Introduction to 51 Single Chip Microcomputer -- minimum system of single chip microcomputer