简体   繁体   English

编写GPIO Raspberry PI 2 B +

[英]Write GPIO Raspberry PI 2 B+

I am new to Raspberry Pi. 我是Raspberry Pi的新手。 I need to read and write to the GPIO pins on the Raspberry Pi. 我需要读取和写入Raspberry Pi上的GPIO引脚。 I am trying to do this operation in php, python, and the command line. 我试图在php,python和命令行中执行此操作。 Do I need to download any kind of library to do this in php, python, or command line? 我是否需要下载任何类型的库才能在php,python或命令行中执行此操作?

No, controlling GPIOs from userspace is a feature provided by the operating system. 不,从用户空间控制GPIO是操作系统提供的功能。 You just need to write a number to the GPIO value "file" thats provided by the kernel. 您只需要在内核提供的GPIO值“文件”中写入一个数字。 It is located under /sys/class/gpio/gpio<number>/value . 它位于/sys/class/gpio/gpio<number>/value This should give you a kickstart . 这应该会给你一个kickstart There they show how its done on the BeagleBoard with the shell but it is a general concept and it doesnt matter which language you use. 在那里,他们展示了如何使用shell在BeagleBoard上完成它,但它是一般概念,并且无论您使用哪种语言都无关紧要。

In python you can use the GPIO library 在python中,您可以使用GPIO库

Generally in unix devices are represented as files, so you can open a file in /dev/ and read/write to the devices. 通常在unix设备中表示为文件,因此您可以在/ dev /中打开文件并对设备进行读/写。

You might get more detailed help on https://raspberrypi.stackexchange.com/ 您可以获得有关https://raspberrypi.stackexchange.com/的更详细帮助

Besides sysfs , the virtual filesystem that allows root to directly read from and write to GPIO pins by echo to or cat from various files in the /sys/class/gpio/ folder (as already mentioned) there are libraries available to do so. 此外sysfs的虚拟文件系统,允许root直接从读取和写入GPIO引脚echocat从各种文件在/sys/class/gpio/文件夹(前面已经提到)有可用这么做库。 Two noteworthy examples are: 两个值得注意的例子是:

  1. wiringPi library provides a cli command gpio to be used by non-privileged users for direct access. wiringPi库提供了一个cli命令gpio ,供非特权用户用于直接访问。

  2. pigs utility, part of the pigpio library also offers comprehensive control of the GPIO pins from the command line (see pigpio for download of source, installation procedures and excellent application examples). pigs实用程序, pigpio库的一部分还提供了从命令行对GPIO引脚的全面控制(请参阅pigpio以获取源代码,安装过程和优秀应用示例)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM