树莓派_GPIO引脚操作_wiringPi的安装与使用

1.简介wiringPi

wiringPi安装好这个库后可以直接调用函数配置和控制GPIO功能

下图中左边是wiringPi封装好后的引脚,右边是树莓派本身的引脚(bcm2835库也使用它)

树莓派_GPIO引脚操作_wiringPi的安装与使用_第1张图片


还有一张图可以参考:

树莓派_GPIO引脚操作_wiringPi的安装与使用_第2张图片


2.树莓派中安装wiringPi方法:

mkdir temp
cd temp
wget http://project-downloads.drogon.net/files/wiringPi.tgz
tar xf wiringPi.tgz
cd wiringPi/wiringPi/
make
make install

测试LED的程序:

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
 
int main (int argc,char* argv[])
{
  if (argc < 2) {
    printf("Usage example: ./led 4 \n");
    return 1;
  }
  int pinNumber = atoi(argv[1]);
 
  if (-1 == wiringPiSetup()) {
    printf("Setup wiringPi failed!");
    return 1;
  }
 
  pinMode(pinNumber, OUTPUT); // set mode to output 
  while(1) {
    digitalWrite(pinNumber, 1); // output a high level 
    delay(800);
    digitalWrite(pinNumber, 0); // output a low level 
    delay(800);
  }
 
  return 0;
}


3.相关问题

使用wiringPi的程序进行测试编译时出现了如下问题:

/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_write_byte'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_read_byte'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_write_byte_data'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_write_word_data'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_read_word_data'
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../libwiringPi.so:undefined reference to `i2c_smbus_read_byte_data'
collect2: ld returned 1 exit status


网上少个相关资料,发现是少装了库的原因:

需要安装这几个库: i2c-tools,libi2c-dev ,python-smbus

执行命令 sudo apt-get install libi2c-dev ,会自动安装这三个。

然后重新编译就可以了。

make clean

sudo make uninstall


make

sudo make install

之后就能正常编译了,别忘了最后要加连接动态库的选项  -l wiringPi




你可能感兴趣的:(树莓派,GPIO,wiringPi)