In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use C language to operate raspberry pie GPIO". In daily operation, I believe many people have doubts about how to use C language to operate raspberry pie GPIO. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use C language to operate raspberry pie GPIO"! Next, please follow the editor to study!
The first step is to install the GPIO library.
Cd / tmpwget https://project-downloads.drogon.net/wiringpi-latest.debsudo dpkg-I wiringpi-latest.deb
Address link 4B
Http://wiringpi.com/wiringpi-updated-to-2-52-for-the-raspberry-pi-4b/
Step 2: open the GPIO settings
Open GPIO and study. You can open it all.
Save and restart.
The third step is to find a picture of GPIO
Then find a GPIO picture of raspberry pie and write the code against the GPIO diagram.
Look at the WiringPi number corresponding to GPIO in the figure above.
The fourth step is to write code
This is the code name for the GPIO used in the code. Put the code on.
Set GPIO17 and GPIO18 to flicker alternately.
# include # define uchar unsigned char#define uint unsigned int#define LedPinRed 0#define LedPinGreen 1 void ledInit () {softPwmCreate (LedPinRed,0100); softPwmCreate (LedPinGreen,10100);} void ledColorSet (uchar r_val, uchar g_val) {softPwmWrite (LedPinRed,r_val); softPwmWrite (LedPinGreen,g_val);} int main () {int I = 0; if (wiringPiSetup () = = 1) {printf ("Setup wiringPi failed!") Return 1;} ledInit (); while (1) {ledColorSet (0xffJ 0x00); delay (500); ledColorSet (0x00 needle 0xff); delay (500);} return 0;}
The functions in the wiringPi library can be viewed in the documentation, where the functions are clearly written.
Step 5, compile and execute
-lwiringPi is a linked wiringPi library
-lpthread link thread library
The last step is to execute. / led
Gcc testLED.c-o led-lwiringPi-lpthread
Extraneous remarks
If you use vim to write code, it is actually very painful for beginners, so vscode is recommended.
My own environment, using ssh link raspberry pie using vscode to edit the code, and then compile and execute. Vscode now supports remote ssh editing code
At this point, the study on "how to use C language to operate raspberry pie GPIO" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.