본문 바로가기
RaspberryPi

[Raspberry Pi] Raspberry Pi 4B wiring pi를 통한 GPIO 제어

by TYB 2024. 2. 1.
반응형
pi@pi08:~/gpio.d $ git clone https://github.com/WiringPi/WiringPi.git

pi@pi08:~/gpio.d $ cp WiringPi/examples/blink.c .
pi@pi08:~/gpio.d $ ls
blink.c  for_ledkey.sh  for_led.sh  gpio  gpiokey  gpiokey.c  gpioled.c  WiringPi

 

pi@pi08:~/gpio.d $ cd WiringPi/

pi@pi08:~/gpio.d/WiringPi $ ./build

 

blink.c를 들고와서 핀번호만 바꿔서 돌려보자~

 

 // LED Pin - wiringPi pin 0 is BCM_GPIO 17.

wiring pi와 broadcom gpio는 배열이 다름

pi@pi08:~/gpio.d $ vi blink.c
     21  *    You should have received a copy of the GNU Lesser General Public License
     22  *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
     23  ***********************************************************************
     24  */
     25
     26 #include <stdio.h>
     27 #include <wiringPi.h>
     28
     29 // LED Pin - wiringPi pin 0 is BCM_GPIO 17.
     30
     31 #define LED 22
     32
     33 int main (void)
     34 {
     35   printf ("Raspberry Pi blink\n") ;
     36
     37   wiringPiSetup () ;
     38   pinMode (LED, OUTPUT) ;
     39
     40   for (;;)
     41   {
     42     digitalWrite (LED, HIGH) ;  // On
     43     delay (500) ;               // mS
     44     digitalWrite (LED, LOW) ;   // Off
     45     delay (500) ;
     46   }
     47   return 0 ;
     48 }

 

이전 글에서 쉘 명령어 2개를 사용해서 setup하던 것이 여기에서는 pinMode(LED,OUTPUT); 한줄로 됨.

 

라이브러리 링크해서 컴파일을 하려면

 

-l은 link 그 뒤에 붙여서 라이브러리 명 쳐주면 됨.
gcc blink.c -o blink -lwiringPi

 

돌려보면? => 안되죠? 라즈베리 이미지 버전 문제 혹은 build 할때의 문제로 추정됨.

로 생각되구여..

 

pi@pi08:~/gpio.d $ ./blink
Raspberry Pi blink
Oops: Unable to determine board revision from /proc/cpuinfo
 -> No "Hardware" line
 ->  You'd best google the error to find out why.

 


pi@pi08:~/gpio.d/WiringPi $ ./build clean
wiringPi:   [Clean]
DevLib:     [Clean]
gpio:       [Clean]
Examples:   [Clean]
Gertboard:  [Clean]
PiFace:     [Clean]
Quick2Wire: [Clean]
PiGlow:     [Clean]
scrollPhat: [Clean]
Deb:
pi@pi08:~/gpio.d/WiringPi/ WiringPi $ vi wiringPi.c

 

768 769 주석처리하고 다시 빌드

pi@pi08:~/gpio.d/WiringPi/wiringPi $ cd ..
pi@pi08:~/gpio.d/WiringPi $ ./build
wiringPi Build script
=====================


WiringPi Library
[UnInstall]
[Compile] wiringPi.c
[Compile] wiringSerial.c
[Compile] wiringShift.c
[Compile] piHiPri.c
[Compile] piThread.c
[Compile] wiringPiSPI.c
[Compile] wiringPiI2C.c
[Compile] softPwm.c
[Compile] softTone.c
[Compile] mcp23008.c
[Compile] mcp23016.c
[Compile] mcp23017.c
[Compile] mcp23s08.c
[Compile] mcp23s17.c
[Compile] sr595.c
[Compile] pcf8574.c
[Compile] pcf8591.c
[Compile] mcp3002.c
[Compile] mcp3004.c
[Compile] mcp4802.c
[Compile] mcp3422.c
[Compile] max31855.c
[Compile] max5322.c
[Compile] ads1115.c
[Compile] sn3218.c
[Compile] bmp180.c
[Compile] htu21d.c
[Compile] ds18b20.c
[Compile] rht03.c
[Compile] drcSerial.c
[Compile] drcNet.c
[Compile] pseudoPins.c
[Compile] wpiExtensions.c
[Link (Dynamic)]
[Install Headers]
[Install Dynamic Lib]

WiringPi Devices Library
[UnInstall]
[Compile] ds1302.c
[Compile] maxdetect.c
[Compile] piNes.c
[Compile] gertboard.c
[Compile] piFace.c
[Compile] lcd128x64.c
[Compile] lcd.c
[Compile] scrollPhat.c
[Compile] piGlow.c
[Link (Dynamic)]
[Install Headers]
[Install Dynamic Lib]

GPIO Utility
[Compile] gpio.c
[Compile] readall.c
[Link]
[Install]
chown: warning: '.' should be ':': ‘root.root’

All Done.

NOTE: To compile programs with wiringPi, you need to add:
    -lwiringPi
  to your compile line(s) To use the Gertboard, MaxDetect, etc.
  code (the devLib), you need to also add:
    -lwiringPiDev
  to your compile line(s).

 

 

다시 컴파일하고 실행시키기~

pi@pi08:~/gpio.d $ gcc blink.c -o blink -lwiringPi
pi@pi08:~/gpio.d $ ./blink
Raspberry Pi blink


잘 깜빡거리는거 확인 가능합니다.!!! b

 

pi@pi08:~/gpio.d $ gpio readall

 

gpio readall 명령어를 쳐주면

BCM이랑 wPi(wiring pi)에서 제공하는 pin번호가 대조되어서 나옴.

반응형