Advantages and Challenges of Python Programming in Embedded Systems

Python is an object-oriented high-level language that was first introduced in 1991, and it has a wide range of applications from system utility operations to Internet scripting and database access.
Currently, the field of artificial intelligence is rapidly developing, especially machine learning technologies that have been widely applied in various domains, such as: data mining, gaming, medical testing, etc.
Traditional AI applications rely on the large storage capacity and high-performance computing capabilities of cloud servers to function properly.
However, in recent years, there may be more than 300 million devices connected to the Internet, resulting in a massive influx of data that puts enormous pressure on the network bandwidth and storage capacity of servers.
In addition to server pressure issues, there are also concerns about privacy and trust with the cloud computing model. Hence, the concept of edge intelligence has been proposed.

Advantages and Challenges of Python Programming in Embedded Systems

As the complexity of embedded systems continues to increase, traditional C/C++ languages are becoming increasingly difficult to design and maintain systems, the emergence of the Python language provides a more flexible and efficient embedded programming solution.
Since the execution process of Python requires the use of an interpreter, it results in poor real-time performance. However, programming Python on microcontrollers is still in its infancy.
Research on improving Python’s execution efficiency is limited, so it is necessary to draw on the research results from the desktop system programming field to enhance Python’s performance.
The embedded Python programming environment refers to the development environment where the Python programming language is applied to embedded devices.
The virtual machine framework generally consists of three parts: the application, the virtual machine core components, and the hardware abstraction driver components.

Advantages and Challenges of Python Programming in Embedded Systems

The application is the Python program or application running in the virtual machine environment, mainly including the Python code written by developers and related libraries and modules, which interact with the hardware abstraction driver components through the virtual machine core components and execute on embedded devices.
The virtual machine core components convert bytecode instructions into calls to hardware abstraction driver components and provide necessary support at runtime.
The hardware abstraction driver components convert requests from the virtual machine core components into low-level hardware operations to enable applications to access hardware resources.
Currently, Zerynth and PyMite are embedded Python programming environments implemented using virtual machine frameworks.
Zerynth is a Python development platform based on a virtual machine framework, whose core component is a Python virtual machine specifically designed for embedded systems.

Advantages and Challenges of Python Programming in Embedded Systems

This virtual machine supports multi-threading and provides interfaces for users to program in Python and C.
Additionally, Zerynth also provides a browser-based integrated development environment called ZerynthStudio, which can run on Windows, Linux, and Mac.
However, when using Zerynth, it is necessary to embed ZerynthVM into the MCU chip and use ZerynthStudio to compile the written application into bytecode and download it to the MCU chip.
Since Zerynth is developed specifically for certain embedded hardware platforms, it requires the use of hardware supported by Zerynth, which limits its flexibility and portability.
PyMite is a lightweight Python programming environment, but the development and maintenance of this programming environment have been discontinued, and due to the lack of updates and support, it may have security vulnerabilities, compatibility issues, and functional limitations.
Furthermore, due to the very few hardware functions provided by the PyMite virtual machine and the difficulty of accessing them, the applicable scenarios for PyMite are relatively limited.

Advantages and Challenges of Python Programming in Embedded Systems

An interpreter is a language processor that reads Python code and interprets and executes it line by line into machine-executable instructions.
The interpreter does not need to compile the entire program code into a binary file, but parses and executes the code line by line at runtime.
Therefore, the interpreter has advantages such as a short development cycle, easy implementation, good readability, and convenient debugging.
In the programming environment under the interpreter framework, MicroPython is an interpreter that supports Python programming on MCUs, which can run on embedded systems with limited hardware resources.
It supports most of the Pytkm3 functions and can write uniquely functional applications with a small amount of Flash and RAM space.
However, due to the characteristic of the interpreter executing while interpreting, programs written in MicroPython may not have high real-time performance.
For applications with high real-time requirements, this may bring certain limitations.

Advantages and Challenges of Python Programming in Embedded Systems

Additionally, the MicroPython interpreter integrates many libraries and functionalities required for embedded system development.
This makes it impossible to trim the software, leading to larger storage space usage, and due to the integration of numerous functions, it also reduces the freedom of hardware selection.
The virtual machine framework and the interpreter framework are both technologies used to implement embedded Python programming environments, each with its
own advantages and disadvantages. The virtual machine framework has higher real-time performance and scalability but requires larger storage space and hardware costs.
The interpreter framework has advantages such as simplicity, short development cycles, and low memory consumption, but it has lower real-time performance and occupies more storage space.
In recent years, with the rise of the Internet of Things and intelligence, the application of embedded systems has become increasingly widespread, and the design of embedded devices has become more complex.

Advantages and Challenges of Python Programming in Embedded Systems

Compared to traditional C/C++ programming environments, the Python language has more concise, easy-to-understand, and user-friendly syntax characteristics, which makes Python increasingly popular in the field of embedded programming.
Although some foreign research on compilation environments has made some progress, there are still several issues when using Python for programming in embedded systems:
Memory Limitations
Embedded devices typically have limited memory resources, therefore, software trimming is required to reduce the size of the interpreter or virtual machine.
However, due to the need for interpreters and virtual machines to highly integrate components such as low-level hardware drivers and bytecode parsers, the space for software trimming is very small.
As a result, even after software trimming, the storage space occupied by the interpreter and virtual machine on small-capacity microcontrollers is still large.

Advantages and Challenges of Python Programming in Embedded Systems

Hardware Limitations
In embedded system design, hardware design is a crucial step.
From chip selection to the choice and integration of peripheral hardware, hardware design needs to consider multiple factors to ensure that a hardware system with excellent performance, low power consumption, reasonable cost, and stable reliability is designed.
Currently widely used Zerynth and MicroPython have certain limitations in hardware design.
The hardware design provided by Zerynth is designed and maintained by its developers, users can only develop using officially supported hardware devices, which limits the freedom and flexibility of users.
Although MicroPython is open-source, its interpreter project is quite complex and requires a deep understanding and adaptation of both hardware and software, making it difficult to port to unsupported chips.

Advantages and Challenges of Python Programming in Embedded Systems

Real-Time Issues
Since Python requires interpretation at runtime, this incurs certain overhead, especially in resource-constrained embedded devices.
Therefore, the execution speed of Python programs may be limited, failing to meet real-time requirements. Zerynth and MicroPython are both embedded Python interpreters based on the principle of Python bytecode.
They use a Python virtual machine to interpret Python code rather than compiling it into machine code. Therefore, running Python code requires an additional parsing process, which adds some time overhead.

Leave a Comment

×