Maix Bit (K210) Nanny Level Getting Started Tutorial---Environment Construction

Maix Bit (K210) Quick Start Series - Environment Construction

Maix Bit (K210) Nanny Level Getting Started Tutorial—Basic Use of Peripherals

Maix Bit (K210) Nanny Level Getting Started Tutorial - Cloud Training of Self-Training Model

这是K210快速上手系列文章,主要内容是,设备连接,环境准备,运行第一个程序

Prerequisites for reading the article: Python foundation , K210 uses Micropython script syntax, so it needs some python foundation, if you don’t have python foundation, you can learn it first.



1. Introduction

1. What is K210?

K210 is a 64-bit dual-core RISC-V CPU with hardware FPU, convolution accelerator, FFT, and Sha256; we use MaixPy (Micropython ported to K210 project), so learning requires python foundation.

2. What is Maix Bit?

Maix Bit is a minimal system version based on K210, all system pins are drawn out, it is recommended for beginners, mainly because it is cheap.
Official website purchase link
insert image description here

3. What can MaixPy do?

As mentioned above, we use MaixPy to operate the K210 chip, and MaixPy uses Micropython syntax. From Micropython, we can know that our operation is performed using python. The syntax of python is simple and easy to use. Therefore, projects based on MaixPy can be used quickly, and the syntax is easy to understand.

We have understood that MaixPy is simple and easy to use, so what can it do?

MaixPy supports conventional MCU operation + AI hardware acceleration + microphone array algorithm , and has a high computing power (up to 1TOPS computing power core module), which is suitable for applications in the AIOT field. In other words, it can do MCU things, such as ADC, GPIO, PWM and other operations, it can also do image recognition, it can run YOLO algorithm, face recognition, etc., it can also do sound processing, filter sound waves, etc. The most important thing about using MaixPy is that it is easy and fast to use, which is its biggest advantage.

Of course, you can not use it, you can use C language for development, just use the official SDK.
K210 official SDK

4. Simply feel the convenience and quick use of MaixPy

Ordinary MUC uses C language to operate I2C (based on STM32 HAL library)

// I2C初始化

#include "i2c.h"

I2C_HandleTypeDef hi2c1;

void MX_I2C1_Init(void)
{
    
    
  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 400000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c1.Init.OwnAddress1 = 0;
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c1.Init.OwnAddress2 = 0;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  {
    
    
    Error_Handler();
  }

}

void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
{
    
    

  GPIO_InitTypeDef GPIO_InitStruct = {
    
    0};
  if(i2cHandle->Instance==I2C1)
  {
    
    

    __HAL_RCC_GPIOB_CLK_ENABLE();

    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    __HAL_RCC_I2C1_CLK_ENABLE();
  }
}

void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
{
    
    

  if(i2cHandle->Instance==I2C1)
  {
    
    

    __HAL_RCC_I2C1_CLK_DISABLE();

    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);

    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_7);
  }
}

Maix Bit operates I2C

# 内容来自官网文档
from machine import I2C                          # 导入内置库
# I2C初始化
i2c = I2C(I2C.I2C0, freq=100000, scl=28, sda=29) # 定义一个I2C对象, 使用I2C0, 频率100kHz,SCL引脚是IO28, SDA 引脚是IO29
devices = i2c.scan()                             # 调用函数扫描设备
print(devices)                                   # 打印设备

Using Python, you can initialize I2C and use it, while C language requires a lot of statements, which can be said to be very convenient.

2. Maix bit hardware

1. Basic hardware needed for Maix bit

Motherboard + 2.4 inch screen + camera + data cable + memory card + card reader

Note: The official standard equipment does not have a memory card, data cable and card reader . You need to buy it yourself on the official website.
insert image description here
This is the official recommended standard equipment:
insert image description here

2. Maix bit hardware wiring

Note, do not power on before connecting the wires. The wiring attention has been marked in the figure below, just connect as shown in the figure.
insert image description here

There is one thing that needs to be paid attention to: screws and nuts need to be installed at both ends of the bottom of the camera, and the bottom of the camera cannot touch the chip , otherwise the chip may be burned.

insert image description here

3. Test Maix Bit hardware

After installation, you can power on and test. The test mainly tests whether the camera and screen are normal or not (the SD card does not need to be installed at this time)

Power on normally at the beginning
insert image description here
Press the RESET button and then quickly press the BOOT button for a period of time to enter the test phase,
the test can twist the camera head, here you can focus manually.
insert image description here

3. Environmental preparation

1. github accelerator

This is necessary , because we need to visit github to download the source code, and domestic access to github is generally slow without using an accelerator, or even inaccessible. Here, an accelerator is recommended, the most important thing is that it is free and easy to operate.

insert image description here

accelerator link

Accelerator basic use, click the exe file to run, and then click Settings
insert image description here

Select the GITHUB acceleration option, then save the settings
insert image description here
and click to restart the backend to access github normally
insert image description here

2. Driver installation

The driver used by the new version of Maix Bit is CH552, just install the new version, no need to install the ch340 ch341 driver

Driver download link

insert image description here
Driver installation: After decompression, right click and select install
insert image description here
insert image description here

Driver installation reference article

3. Firmware download

We can know from the beginning of testing the board that there is already a default firmware, but the requirements are different and the firmware used is different. We need to learn how to download firmware.

a: firmware body

Generally, there are several types of firmware, we need to download the latest and most complete one

Firmware download link
Download the 15th one here, the 15th is the default one when you get the board. There are descriptions and references for different versions of firmware in readme.txt
insert image description here

b: Install firmware software

To install the firmware, we need to use the kflash_gui software, just download the latest one. Here you need to visit github, remember to use the accelerator to accelerate (there is an accelerator download and use above)

kflash_gui download link
insert image description here

c: install firmware

Select the firmware to download. The version I downloaded here is V0.6.2, which is the same as the default firmware version, so the screen display is the same as the screen display during the test.
Port selection: the one with USB
Other options can be defaulted
insert image description here

3.mpfs serial tool

We need to connect with the development board, and the driver CH552 we installed is the serial port driver, through which we can communicate with the serial port on the development board.

With the driver, you also need a tool to send data to the driver, which is a serial port tool, here use mpfs, use the command line to download

a.mpfs serial tool download

命令:pip install mpfshell-lite	

insert image description here

b.mpfs connection serial port

Enter the command mpfs to see what serial ports are available and operate

命令:mpfs

insert image description here

Use open COMX to connect to the corresponding serial port

命令:open

Here my COM9 is the serial port where the Maix Bit is located (there is an output prompt, USB Serial Port), and the command line enters open COM9 to connect to the development board
insert image description here

The first command:
hello world
insert image description here

命令:exec print

4. Common serial port tool use

Here it is recommended to use MobaXterm, which can directly use the serial port to connect to the development board. Using a common serial port tool is equivalent to using the python command line, similar to using the python command line on the PC side, there are >>> and the python syntax can be used on the connection

Similar to the picture below
insert image description here

MobaXterm download link, free download is enough

After installation, connect to our development board, here COM9 is the port of the development board, the baud rate is 115200
insert image description here
insert image description here

After connecting to the development board, >>> will be used, and we can directly use python syntax to operate

You can print things directly by using print, and you can also use help() to view the above operations

insert image description here

5. Solve the problem that the serial port tool cannot be connected

a: The firmware is not flashed

Solution 1: Refresh the firmware

b: The driver is not installed

Solution 2: It may be that the serial port driver is not installed properly or it is not a new version of Maix Bit, but an old version of CH340, CH341. Here you can view it by viewing the device manager

This is what it looks like after a successful installation, with a USB Serial Port (with a microphone, the new version of Maix Bit)
insert image description here

c: Python itself is running the program, generally there is an infinite loop in the boot.py file (the program that runs automatically after booting), and there is no sleep operation

The default program is like this. In this case, generally the IDE can connect to the serial port (for details on how to use the IDE to connect to the serial port, read the article below for details on how to use the IDE to connect to the development board). Cycle removal, sent to the boot.py file of the development board

insert image description here
The sending operation is as follows, remember to remove while True

insert image description here
Generally, after completing this, you can connect through mpfs

d: The serial port is occupied by an unknown process

Need to clear the registry or restart, generally clear the registry on it

The operation is as follows: open the command line, enter regedit
insert image description here
to find the directory: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter\Devices, and then delete the registry (delete the serial port of CH552 that has been installed, and you can view it in the device manager), here is COM9, right-click COM9, click delete, and then re-plug the USB

insert image description here

6. MaixPy IDE download

Download the latest exe file and install it to
download the IDE

The installation complete interface:
insert image description here

4. The first program

1. Use the serial debugging assistant to run the first program

Command reference used
We directly use the serial port debugging assistant to run the first program on the board

First of all, we need to create a py file in any location, the content:

print("hello world")

Get the py file location:
insert image description here

Switch the working directory of the serial debugging assistant to the directory where py was created just now:

命令:lcd C:\Users\13029\Desktop\Temp\Graduation_Design\MaixPy

Upload the file to the development board:

命令:put ts.py

Run the program:

命令:execfile ts.py

insert image description here

2. MaixPy IDE runs the first program

Comment out the default program, leaving only our print program, the program running here is one-time, and it will be gone after shutdown. Specifically, if you want to permanently store files on the development board and select a boot program, you can use mpfs or IDE to send files to the development board

# Hello World Example
#
# Welcome to the MaixPy IDE!
# 1. Conenct board to computer
# 2. Select board at the top of MaixPy IDE: `tools->Select Board`
# 3. Click the connect buttion below to connect board
# 4. Click on the green run arrow button below to run the script!
'''
import sensor, image, time, lcd

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.
'''
print("hello world")


Select the corresponding development board in the toolbar:
insert image description here

Use the IDE to connect the serial port:
insert image description here
After the connection is successful, click the green run button, the development board will run the program in the IDE, and output the corresponding information in the debugging assistant. Will output hello world and firmware information

insert image description here

Four. Summary

So far, we have successfully used the Maix Bit board, but the more troublesome thing is to build the development environment. After setting up the environment, we can run our first program through the serial port debugging assistant or IDE

5. References

Introduction to MaixPy Documentation
MaixPy Featured Article
Maix Bit Data Download
Maix Bit Getting Started Video
K210 Official SDK
Sipeed Open Source Community
Functions and methods for processing data efficiently.

Guess you like

Origin blog.csdn.net/weixin_46185705/article/details/128590343