reference: http://wiringpi.com/reference/setup/

There are four ways to initialise wiringPi.

wiringPi库提供了四种方法(函数)用来初始化wiringPi。

  • int wiringPiSetup (void) ;
  • int wiringPiSetupGpio (void) ;
  • int wiringPiSetupPhys (void) ;
  • int wiringPiSetupSys (void) ;

One of the setup functions must be called at the start of your program or your program will fail to work correctly. You may experience symptoms from it simply not working to segfaults and timing issues.

当你编程的时候必须在开头调用这四个设置函数中的一个,否则你的程序将运行不了。你可能经历过像简单的不能工作,段错误,定时问题这样的一些症状。

NotewiringPi version 1 returned an error code if these functions failed for whatever reason. Version 2 returns always returns zero. After discussions and inspection of many programs written by users of wiringPi and observing that many people don’t bother checking the return code, I took the stance that should one of the wiringPi setup functions fail, then it would be considered a fatal program fault and the program execution will be terminated at that point with an error message printed on the terminal.

注意:对于wiringPi 的V1版本,如果这些设置函数调用失败,不管什么原因,它将会返回一个错误代码。

  • If you want to restore the v1 behaviour, then you need to set the environment variable: WIRINGPI_CODES (to any value, it just needs to exist)

The differences between the setup functions are as follows:

  • wiringPiSetup (void) ;

This initialises wiringPi and assumes that the calling program is going to be using thewiringPi pin numbering scheme. This is a simplified numbering scheme which provides a mapping from virtual pin numbers 0 through 16 to the real underlying Broadcom GPIO pin numbers. See the pins page for a table which maps the wiringPi pin number to the Broadcom GPIO pin number to the physical location on the edge connector.

This function needs to be called with root privileges.

  • wiringPiSetupGpio (void) ;

This is identical to above, however it allows the calling programs to use the Broadcom GPIO pin numbers directly with no re-mapping.

As above, this function needs to be called with root privileges, and note that some pins are different from revision 1 to revision 2 boards.

  • wiringPiSetupPhys (void) ;

Identical to above, however it allows the calling programs to use the physical pin numberson the P1 connector only.

As above, this function needs to be called with root priviliges.

  • wiringPiSetupSys (void) ;

This initialises wiringPi but uses the /sys/class/gpio interface rather than accessing the hardware directly. This can be called as a non-root user provided the GPIO pins have been exported before-hand using the gpio program. Pin numbering in this mode is the native Broadcom GPIO numbers – the same as wiringPiSetupGpio() above, so be aware of the differences between Rev 1 and Rev 2 boards.

Note: In this mode you can only use the pins which have been exported via the /sys/class/gpio interface before you run your program. You can do this in a separate shell-script, or by using the system() function from inside your program to call the gpioprogram.

Also note that some functions have no effect when using this mode as they’re not currently possible to action unless called with root privileges. (although you can use system() to callgpio to set/change modes if needed)

RPI学习--wiringPi_setups的更多相关文章

  1. RPI学习--wiringpi_API

    reference: https://projects.drogon.net/raspberry-pi/wiringpi/functions/ Functions (API) Some of the ...

  2. RPI学习--WebCam_mplayer

    1,安装mplayer $ sudo apt-get install mplayer 2,运行 $ sudo mplayer tv:// 有时会秀逗,绿屏,多试几下就好了,情况未知

  3. RPI学习--环境搭建_无线网络的连接

    这里不讨论无线网卡的驱动问题,假设内核已经支持了该网卡. 发现命令行下添加无线网络比较麻烦,于是利用图形桌面的工具(WiFi Config)先配置好,在回到字符终端,发现网络已经配置好了 查看内网ip ...

  4. RPI学习--环境搭建_默认启动桌面/终端修改

    参见:http://elinux.org/RPi_raspi-config 首次运行Raspbian会自动进入设置,往后也可以重新进入设置: $ sudo raspi-config 选项3 Enabl ...

  5. RPI学习--webcam_用fswebcam抓取图片

    若 ls /dev 下没有video0,可以参考http://www.cnblogs.com/skynext/p/3644873.html,更新firmware 1,安装fswebcam: sudo ...

  6. RPI学习--环境搭建_更新firmware

    (用以解决USB摄像头不识别的状况) rpi-update是老外开发的一个更新树莓派firmware的工具 $ sudo apt-get update  $ sudo apt-get install ...

  7. RPI学习--环境搭建_刷卡+wiringPi库安装

    1,镜像地址 http://www.raspberrypi.org/downloads/ 2,Windows下刷写工具 Win32 Disk Imager 3,安装wiringPi库 (这里在连网状态 ...

  8. RPI学习--环境搭建_串口连接

    有两种, 一种是通过MAX2323芯片连接的串口,要接VCC为芯片供电. 另一种是通过PL2302芯片连接的USB,可不接VCC,用电脑USB口为芯片供电. 下面以通过MAX2323方式为例. 1,V ...

  9. nanopi NEO2 学习笔记 3:python 安装 RPi.GPIO

    如果我要用python控制NEO2的各种引脚,i2c 或 spi ,RPi.GPIO模块是个非常好的选择 这个第三方模块是来自树莓派的,好像友善之臂的工程师稍作修改移植到了NEO2上,就放在 /roo ...

随机推荐

  1. shell远程执行命令

    ssh主要参数说明 -l 指定登入用户 -p 设置端口号 -f 后台运行,并推荐加上 -n 参数 -n 将标准输入重定向到 /dev/null,防止读取标准输入 -N 不执行远程命令,只做端口转发 - ...

  2. Fedora 防火墙关闭与开启

    重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off   或者 /sbin/chkconfig --level 2345 iptable ...

  3. hiho_1059_string matching content length

    题目大意 两个字符串strA和strB(长度最大为2100),他们中按照顺序有一些公共的子串,且公共子串的长度大于等于3,否则不认为是合法的,比如 abcdef 和 abcxcdef, 按照顺序有合法 ...

  4. windows截屏

    #ifndef _CAPTURESCREEN_H #define _CAPTURESCREEN_H #include <windows.h> class CaptureScreen { p ...

  5. STM8s窗口看门狗

    看看窗口看门狗的框图 从图里看出产生复位信号有2个方式: 1 WDGCR寄存器的T6 由1变0,也就是从此寄存器的值从0x40变成0x3F会产生复位信号: 2 当寄存器WDGCR的值大于WDGWR的时 ...

  6. css读书笔记4:字体和文本

    字体属性网页中的字体有3个来源:1.用户机器中安装的字体:2.保存在第三方网站上的字体.可以使用link标签把它们链接到页面中:3.保存在子集的web服务器上的字体.可以使用@font-face规则随 ...

  7. DispatcherServlet

    <servlet> <servlet-name>chapter2</servlet-name> <servlet-class>org.springfra ...

  8. 使用XIB实现一个简单view

    技术处女贴 欢迎来探讨 转帖请注明出处 http://www.cnblogs.com/andy-zhou/p/4962135.html 微信: @Andy 1. AppDelegate AppDele ...

  9. 20145218 《Java程序设计》第三周学习总结

    20145218 <Java程序设计>第三周学习总结 教材学习内容总结 定义类 编写程序要产生对象就要先定义类.类是对象的设计图,对象是类的实例.类定义时使用class关键词,建立实例时, ...

  10. ubuntu 系统出错一览

    1.系统升级出错:打开终端输入:sudo apt-get install -f