2016年2月23日 星期二

wiringPi in raspberry



安裝

sudo apt-get install git-core
sudo apt-get update
sudo apt-get upgrade
git clone git://git.drogon.net/wiringPi
cd wiringPi
git pull origin
cd wiringPi
./build

pin  圖:
   wiringPi  定義的腳位和RPI的腳位不一樣...舉個例子....

GPIO14 (Txd) ->  wiringPi  15

所以這裡要特別注意





  • Pins 171819 and 20: (BCM_GPIO 28, 29, 30 and 31) These are additional GPIO pins on the Rev. 2 board.

sample code:

#include <wiringPi.h>
int main (void)
{
  int pin_num = 0;
  wiringPiSetup () ;
  pinMode (pin_num, OUTPUT) ;
  for (;;)
  {
    digitalWrite (pin_num, HIGH) ; delay (500) ;
    digitalWrite (pin_num,  LOW) ; delay (500) ;
  }
  return 0 ;
}
 then to compile and run, you would enter:
gcc -Wall -o blink blink.c -lwiringPi
sudo ./blink

如果線有接對....應該會亮了....

Reference : http://wiringpi.com/

沒有留言:

張貼留言