好记性不如铅笔头

linux, 操作系统, 树莓派

树莓派学习笔记:wiringPi初学

最近想学习下【 wiringPi 】这个库,据大牛们说这个库很不错,源码非常好。这里备份下最简单的安装和使用。

下载和安装:

官网给了非常详细的文档:【 http://wiringpi.com/download-and-install/ 】。

基本上按照文档来就OK了,如果有其他的需求,可以看下下载下的【 INSTALL 】文件,如下:

How to install wiringPi
=======================

The easiest way is to use the supplied 'build' script:

  ./build

that should do a complete install or upgrade of wiringPi for you.

That will install a dynamic library.

Some distributions do not have /usr/local/lib in the default LD_LIBRARY_PATH. To
fix this, you need to edit /etc/ld.so.conf and add in a single line:

  /usr/local/lib

then run the ldconfig command.

  sudo ldconfig

If you want to install a static library, you may need to do this manually:

  cd wiringPi
  make static
  sudo make install-static


To un-install wiringPi:

  ./build uninstall

Gordon Henderson

projects@drogon.net
https://projects.drogon.net/

使用:

gpio工具的使用方法:

pi@raspberrypi ~/wiringPi/wiringPi-f18c8f7 $ gpio -v
gpio version: 2.13
Copyright (c) 2012-2013 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

This Raspberry Pi is a revision 2 board.
pi@raspberrypi ~/wiringPi/wiringPi-f18c8f7 $ gpio
Usage: gpio -v
       gpio -h
       gpio [-g|-1] [-x extension:params] ...
       gpio [-p] <read/write/wb> ...
       gpio <read/write/aread/awritewb/pwm/clock/mode> ...
       gpio readall/reset
       gpio unexportall/exports
       gpio export/edge/unexport ...
       gpio wfi <pin> <mode>
       gpio drive <group> <value>
       gpio pwm-bal/pwm-ms 
       gpio pwmr <range> 
       gpio pwmc <divider> 
       gpio load spi/i2c
       gpio i2cd/i2cdetect
       gpio gbr <channel>
       gpio gbw <channel> <value>

Demo:

helloWiringPi.c:

#include <wiringPi.h>

int main(void)
{
	int cnt = 10;
	wiringPiSetup();
	pinMode(0,OUTPUT);
	
	for(cnt = 10; cnt > 0; cnt--)
	{
		digitalWrite (0, HIGH) ; delay (500);  
		digitalWrite (0,  LOW) ; delay (500);  
	}
	return 0;
}

编译方式:

gcc -Wall -o helloWiringPi helloWiringPi.c -lwiringPi

使用方法:

sudo ./helloWiringPi

 

Leave a Reply

5 − 2 =

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据