Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use raspberry pie Qt to develop interface program to control GPIO

2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to use raspberry pie Qt development interface program to control GPIO, for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Using Qt to develop interface program

Preface

Qt is a cross-platform C++ graphical user interface application development framework developed by Qiqu Technology in 1991. It can be used to develop both GUI programs and non-GUI programs, such as console tools and servers. Qt is an object-oriented framework that uses special code generation extensions (called meta-object compilers (Meta Object Compiler, moc)) and some macros that are easy to extend and allow component programming. In 2008, Qiqiu Technology was acquired by Nokia, and QT became a programming language tool of Nokia. In 2012, Qt was acquired by Digia. In April 2014, the cross-platform integrated development environment Qt Creator 3.1.0 was officially released, realizing full support for iOS, adding plug-ins such as WinRT and Beautifier, abandoning the GDB debugging support without Python interface, integrating the Clang-based CumberCure + code module, and adjusting the Android support, so as to achieve full support for iOS, Android and WP.

Qt is a cross-platform C++ graphical user interface application framework developed by Qiqu Technology in 1991. It provides application developers with all the functions they need to build an art graphical user interface. Qt is easy to extend and allows real component programming. Basically, Qt is the same type of thing as graphical interface libraries such as Motif,Openwin,GTK on X Window and MFC,OWL,VCL,ATL on the Windows platform.

To put it simply, you can write a program that can be easily ported to other platforms with Qt, and basically recompile the program.

Install Qt on raspberry pie

Use the following command to install

Sudo apt-get install qt4-dev-tools

Sudo apt-get install qtcreator

Since installing Qt requires downloading more than 200m files from the network, first of all, raspberry pie has to be connected to the network, and secondly, it may take a long time to install, please wait patiently.

After installation, click Menu in the upper left corner of the desktop. If you can see the Qt program icon shown in the following figure, it means that Qt has been installed successfully.

Qt configuration

To use Qt for the first time, you need to configure the tool chain. Go to the menu Tools- > Options- > Build&Run.

Click the Add button in the upper right corner and select GCC

Select the paths for the compiler and debugger as shown below

New Qt Test Project

After the new project is completed, the whole framework of the program has been set up. Let's try to compile the program directly.

There is no problem with compiling. Let's expand the Forms file directory on the left, double-click the mainwindow.ui file, and then add two buttons to this interface, each of which controls the output level of one pin of the raspberry pie, as shown in the following figure:

On the right to modify the name of the button control, while modifying the file displayed by the button, select a button control, right-click, select Go to slot.., in the pop-up dialog box and then select Clicked () function, Qt will automatically connect a signal and slot, while automatically adding this slot function in the mainwindow.cpp file, we can write button click events inside.

We now complete the initialization of GPIO in the constructor, then complete the GPIO high and low level output control in each button click event function, and then compile the program again, resulting in the following problems:

According to the hint, we know that it is because the wiringPi-related function was not found during the link, so we need to introduce this library when connecting. The operation mode is very simple, just add the library to the .pro file, as shown in the following figure:

Then compile again, normally it will be compiled successfully here, enter the project directory, we will find a folder with a long name, which is some intermediate files generated by Qt when compiling, of course, the executable file generated by our compilation is also inside, the name is the same as the working name, open the console and use the cd command to enter the directory. And then use the

Sudo. / gpio_led

You can run the program, and the running effect of the program is shown below:

Click the next two buttons to see if you control the GPIO.0 pin of the raspberry pie to output high and low levels.

Project and source code download:

Http://www.embed-net.com/forum.php?mod=attachment&aid=NDA2fDM1MTBiNmQ3fDE0NzA0MzMyMjd8MHwxNDI%3D

This is the answer to the question about how to use the raspberry pie Qt development interface program to control GPIO. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report