树莓派gpio

http://www.eeboard.com/bbs/thread-6930-1-1.html

http://www.codelast.com/?p=5232

安装git-core

sudoapt-getinstallgit-core

下载winringPi库

gitclonegit://git.drogon.net/wiringPi

参考https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/

可能需要apt-getintstalllibi2c-dev

i2c-tools,libi2c-dev,python-smbus

参考http://blog.csdn.net/liang890319/article/details/8643069

否则报错

/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_byte'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_byte'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_byte_data'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_write_word_data'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_word_data'
/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../libwiringPi.so: undefined reference to `i2c_smbus_read_byte_data'

编译和安装库

cdwiringPi

./build

写了一段简单的测试代码:
/********** test.c ***************/
#include <wiringPi.h>
#include <stdlib.h>

int main()
{
    int i;

    if( wiringPiSetup() == -1 )
        exit( 1 );

    pinMode( 0, OUTPUT ); 
    pinMode( 1, OUTPUT ); 
    pinMode( 2, OUTPUT ); 
    pinMode( 3, OUTPUT ); 

    for(i = 0; i < 40; i++)
    {
        digitalWrite( i % 4, HIGH );
        delay( 200 );
        digitalWrite( i % 4, LOW );
        delay( 200 );
    }

    return 0;
}
/********** test.c ***************/

编译&执行:
cc -o test test.c -L/usr/local/lib -lwiringPi
sudo ./test

相关推荐