首页 技术 正文
技术 2022年11月18日
0 收藏 471 点赞 2,969 浏览 2719 个字

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)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857