Home  >  Article  >  Backend Development  >  Is micropython suitable for development?

Is micropython suitable for development?

anonymity
anonymityOriginal
2019-06-13 14:51:053720browse

MicroPython has become popular in the domestic programming community recently. What is the reason why it is so popular? Is it because it has powerful functions and is open source under the Mit license?

The origin of Micropython is due to Damien George, a great computer engineer. Damien George uses Python for work every day. One day he came up with a bold idea: Can Python be used to control a microcontroller? What about operating robots?

So is micropython suitable for development?

Is micropython suitable for development?

The Python language itself is an easy-to-use scripting language. Some non-computer major enthusiasts choose Python language as their introductory language. , but it has a fly in the ointment (why China and the United States do not participate in the World Cup), it cannot implement some low-level operations, and is inconspicuous in the hardware field. Therefore, Damien George spent 6 months to build MicroPython. This is the origin of MicroPyhton.

MicroPython is based on ANSIC, and its syntax is basically the same as Python3. It has an independent parser, compiler, virtual machine and class library. Currently it supports 32-bit based ARM processors, such as STM32F401, STM32F405, and STM32F407.

The following comparisons were made using the three languages ​​​​of assembly, C, and MicroPython to illustrate whether micropython is suitable for development?

1. Compilation environment

Before writing programs in C language and assembly language, you need to download the compilation environment. However, Micropython does not require any compilation environment. You only need to insert the U port of the development board into the computer. A drive letter can appear on the computer, just like inserting a U disk. Then open the U disk and edit main.py directly with Notepad. The comfort of it is that MicroPython does not require any tools and environments. Any text tool can be used with just one development board. It can be developed and compiled, and you can give it a nickname - pocket programming computer. . . The best one in China is the TPYBoard v102 development board. If you are interested, you can learn more about it. It has complete information and video learning materials, which is quite good. That’s how I got into it.

2. Operation difficulty

The basic operation of assembly language is simple, but it is relatively difficult to achieve complex project goals. The code is lengthy and debugging is difficult; C language has statements and a large number of libraries Functions are simpler than assembly; MicroPython has more library functions than C, and the code format is not only simpler. With the support of the library, many functions and methods do not need to be written by yourself. You can just import xx directly. The class library import is ok. In the past, it took five or six lines of code to light a lamp, but now it only takes one line of code to light up the LED, so easy.

3. Program structure

Assembly language generally uses a jump structure. Whether it is a subroutine call, a loop or a random jump, in theory, the jump method is used to interrupt the operation or force an exit. The operation of the program segment requires precise control of the stack push, and the requirements are very strict; the C language generally uses a loop structure or a sequential structure, and there is no need to jump around to execute the program. The interrupt operation will automatically push the stack without human intervention. When timing requirements are high, assembly can be embedded to improve efficiency; MciroPython can use the C program structure or the thread structure. The thread structure requires strict and reasonable allocation of thread working time without conflicts, and good control of resources. , resources cannot be wasted by idle threads. In theory, multi-threads can run more efficiently. Although a single core can only run a single thread at the same time, it is synchronized from a macro perspective. It can effectively reduce the program when time requirements are not strict. difficulty of writing.

4. Writing method

When assembly does not use macros, the instructions usually directly operate the unit, which requires memorizing a large number of data unit uses, and due to the large number of program lines (possibly (will reach one or two thousand lines), you need to look back and forth through the program code, and the entire writing process is relatively cumbersome. And because they are all 8-bit units, complex data operations need to be completed by nesting C language; any variables used in C language need to be defined first. Compared with not having to memorize variable names, the overall structure is clear and most programming software has jumps. The subroutine function makes it very convenient to find program blocks. There are a large number of finished header files containing various commonly used functions, which reduces the writing of complex program codes; MicroPython inherits the writing advantages of C and does not require pre-definition or any end symbols. You only need to change the line to continue writing. But pay attention to the use of the Tab key in some special circumstances.

5. Readability

The assembly itself is difficult to read because there are few marks and the units are directly manipulated. The visual structure is not only two columns of code but also requires constant jumps, so it is difficult to read. It’s very difficult; the simple operation codes in C language are relatively clear, but for complex ones, you have to find methods within methods. Many complex codes have to be found by yourself, which makes people feel very headache; MicroPython has better readability than C , and because many special symbols have been cancelled, the overall feeling is relatively clear. Many methods are written separately in separate libraries and can be called directly. Each function has a separate class library, which seems extremely convenient and clear at a glance.

The above is the detailed content of Is micropython suitable for development?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn