Python is a cross platform computer programming language. As an object-oriented dynamic type language, it was originally designed to write automatic scripts (shells). With the continuous updating of versions and the addition of new language functions, it is more and more used in the development of independent and large-scale projects

1)。 brief introduction

With the popularity of Python in the field of Internet artificial intelligence, we gradually feel the convenience of Python development. Based on the embedded ARM platform, this paper introduces the use of python with pyqt5 module to develop graphical applications.

The arm platform demonstrated in this paper comes from the apalis imx6 ARM embedded platform based on NXP imx6 ARM processor of toradex.

2. Preparation

a)。 The core version of apalis imx6q arm, together with the carrier board of apalis evaluation board, connects the debugging serial port uart1 (carrier board X29) to the development host to facilitate debugging. For more information about apalis imx6 cooperating with apalis evaluation board, please refer to datasheet and development guide.

b)。 The default Linux BSP of apalis imx6q does not include python, QT and other support, so it needs to be recompiled.

。/ Based on toradex Linux BSP release v2.8

。/ Refer here to build an openembedded compilation environment, and then adapt the following patch, which is used to adapt the libsoc required by this test to Python 3.

。/ Modify the build / conf / local.conf file and add the required components


#IMAGE_ INSTALL_ append = “ python3 python3-pip python3-libsoc python3-pyqt5 rng-tools ”


。/ Add Qt5 support in the standard image BB file by adapting the patch below

。/ Recompile image


$ bitbake -k angstrom-qt5-lxde-image


。/ The newly generated image is located in the directory deploy / images / apalis-imx6 / and updated to the apalis imx6 module by referring to the instructions here

3)。 Python GPIO interrupt test program

a)。 First of all, we do not include a graphical interface. We use Python to complete a simple GPIO interrupt test program. This program calls libsoc to complete GPIO control. For the use and description of libsoc, please refer to here.

b)。 The hardware connection configuration of apalis evaluation board is as follows: X4 gpio05 (mxm3_ 11) The GPIO number in the corresponding system is 170, which is used as key input; X4 GPIO06(MXM3_ 13) The GPIO number in the corresponding system is 169, which is used as the output driver led.

X4 GPIO05 《-》 X34 SW5

X4 GPIO06 《-》 X34 LED1

c)。 Please refer to the following source code, respectively, to achieve the blocking mode and non blocking mode interrupt, the corresponding function is to turn on and off the LED lights by pressing the button alternately.

。/ Blocking mode

//The main function is used as the main function to turn on gpios and set the initialization state to high-level output; test_ interrupt_ The handler function is used to implement interrupt response, and GPIO is used_ in.wait_ for_ Interrupt is blocking interrupt, capture interrupt will continue, after capture interrupt do simple anti touch processing.

。/ Non blocking mode

//The main function is used as the main function to turn on gpios and set the initialization state to high-level output; In addition, GPIO is used in the main function_ in.start_ interrupt_ The handler enables the corresponding interrupt to be non blocking; At the end of the main function, the keyboard input is received by while to exit the application; gpio_ in.wait_ for_ Interrupt is still used as an interrupt processing function to interrupt and drive the LED state to change.

d)。 Copy the Python code directly to apalis imx6, and the test results are as follows:

。/ In blocking mode, the last step is to exit the program by pressing ctrl-c


[email protected] -imx6:~# 。/ gpiotest_

The LED iniTIal status is ON

The LED turns OFF

interrupt TImes is 1

The LED turns ON

interrupt times is 2

^Clibsoc-gpio-debug: Interrupted system call

Traceback (most recent call last):

File “。/ gpiotest_”, line 54, in

main(gpio_ input_ id, gpio_ output_ id)

File “。/ gpiotest_”, line 45, in main

test_ interrupt_ handler(gpio_ in, gpio_ out)

File “。/ gpiotest_”, line 12, in test_ interrupt_ handler

gpio_ in.wait_ for_ interrupt(-1)

File “/usr/lib/python3.5/site-packages/libsoc/”, line 118, in wait_ for_ interrupt

if api.libsoc_ gpio_ wait_ interrupt(self._ gpio, timeout) != 0:



。/ In non blocking mode


[email protected] -imx6:~# 。/ gpiotest_

The LED initial status is ON

please enter ‘Q’ to quit

The LED turns OFF

The LED turns ON

The LED turns OFF


Do you really want to quit? yes or no


[email protected] -imx6:~#


4)。 Using pyqt5 to realize GPIO interrupt program of graphical interface

a)。 The hardware configuration and connection are consistent with the above test scenario.

b)。 In order to facilitate the development of pyqt5 interface, first create the following QWidget project UI interface through qtcreator

How to use Python to develop embedded ARM interface

//The qframe box on the right side of the LED status and qlabe are used to display the current status of the LED

//The “turn on” and “turn off” push buttons are used to control the LED status through the interface, and the “exit” push button is used to exit the program

。/ The final UI source code reference is as follows, copy the corresponding mainwindow.ui file to the same path of apalis imx6 Python application

c)。 The source code reference is as follows:

The description is as follows:

。/ Class application window is used to realize Qt5 interface and related key operation

//First, the UI file mainwindow.ui is loaded by loadui function, then the interface display is initialized, and the corresponding processing program of each key is connected

//Finally, start a new qthread thread, self. Thread, which is used to deal with the external GPIO key interrupt, connect the new thread feedback signal processing program, and finally start the new thread

//The ledstatuschange function is used to process the LED status change signal fed back by the new thread and synchronously change the display status of the interface

// Button_ On_ Click and button_ Off_ The clicked function is used to change the LED GPIO output and interface display according to the click of the interface key

// Button_ Exit_ The clicked and closeevent functions are used to handle exit programs, including the exit of child threads

。/ Class gpiointerrupt is used to process GPIO interrupt, change led GPIO output and feedback led status change to the interface main program

//First, define the feedback signal and initialize the GPIO pin

//The run function is basically the code of the blocking mode Python application in Chapter 3 above, so I won’t repeat it here

d)。 The test results are as follows:


[email protected] -imx6:~# 。/ gpiotest_

The LED initial status is ON

set LOW

set HIGH

The LED turns OFF

button clicked for setting LOW

The LED turns ON

button clicked for setting HIGH

[email protected] -imx6:~#


How to use Python to develop embedded ARM interface

5)。 summary

As shown in the above example, using Python and pyqt5 is very convenient to create an embedded interface application example. Compared with the traditional C language, it needs to configure the cross compiling environment when starting up. The whole process is faster and more convenient. At the same time, its running efficiency is acceptable when implementing relatively simple control. In addition, python can integrate a large number of components to facilitate development, It simplifies the process of embedded application development in the fields of machine vision and artificial intelligence.

Source: China electronic network

Leave a Reply

Your email address will not be published. Required fields are marked *