Raspberry Pi入门-第二部分-GPIO(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/pi/getting-started-with-raspberry-pi-part-ii-gpio-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2746 个词 阅读量 0Raspberry Pi入门-第二部分-GPIO(译文)
原文地址:https://www.codeproject.com/Articles/1151670/Getting-Started-with-Raspberry-Pi-Part-II-GPIO
原文作者:Hussain Patel
译文由本站 robot-v1.0 翻译
前言
*In this article, we would be discussing about the Raspberry Pi - GPIO (General Purpose Input Output) Pins *
在本文中,我们将讨论Raspberry Pi-GPIO(通用输入输出)引脚
- 下载文章(Download article) 注意(Note):请您投票并提供评论.(: Request you to please vote and provide comments.)
介绍(Introduction)
在我以前的文章中-(In my previous article -) Raspberry Pi入门(Getting Started with Raspberry Pi) ,我们讨论了GPIO(通用输入输出).在本文中,我们将详细讨论GPIO引脚,Pi板上每个引脚的功能以及GPIO编号.(, we talked about GPIO (General Purpose Input Output). In this article, we will discuss more about the GPIO pins, function of each pin on the Pi board and GPIO numbering.)
入门(Getting Started)
Raspberry Pi(微型计算机)与其他计算机之间的主要区别是GPIO(通用输入输出)引脚(请参见图1).(The main difference between a Raspberry Pi (tiny computer) and other computers is the GPIO (General Purpose Input Output) pins (see Figure 1).)
图1(Figure 1)台式计算机是通用的,即它们具有标准的输入和输出(文件,键盘,鼠标,触摸,打印,屏幕等),并且它们从固定输入中获取信息,对其进行处理并将结果返回给标准输出.这意味着普通的计算机/机器没有与传感器和执行器之类的电子设备连接的接口,这是Raspberry pi(微型计算机)的GPIO引脚发挥重要作用并使Raspberry Pi与其他计算机不同的地方.(Desktop computers are UBIQUITIOUS, i.e., they have a standard input and output (files, keyboard, mouse, touch, print, screen, etc.) and they take information from fixed input, process it and give the results back to the standard output. This means a normal computer / machine does not have an interface to connect with electronic devices like sensor and actuators, this is where the Raspberry pi (tiny computers) GPIO pins play an important role and make Raspberry Pi different from other computers.) Pi的GPIO引脚从板的顶部伸出.这些引脚充当Raspberry pi与物理世界之间的接口.这些引脚用于与其他电路(例如传感器,执行器,扩展板和自定义电路)进行通信(输入/输出).(The Pi has GPIO pins that stick out from the top of the board. These pins act as an interface between the Raspberry pi and the physical world. These pins are used to communicate (both input / output) with other circuitry such as sensors, actuators, extension boards and custom circuits.)
了解引脚(Understanding the Pins)
如上图2所示,GPIO引脚根据Raspberry Pi模型而有所不同.以前的型号有26针,而最新的型号-Raspberry Pi 2 Model B和Raspberry Pi 3 Model B都有40针.(As seen in Figure 2 above, the GPIO pins vary based on the Raspberry Pi model. The previous models have 26 pins and latest models - Raspberry Pi 2 Model B and Raspberry Pi 3 Model B both have 40 Pins.)
图2(Figure 2)为了保持向后兼容性,以前的型号的前26个引脚在新的Raspberry pi型号中仍具有相同的功能(请参见图3).(To maintain backward compatibility, the first 26 pins from previous models still have the same functionality in the new Raspberry pi models (See Figure 3).)
图3(Figure 3)如图4所示,Raspberry pi上的每个引脚都有一个功能要做,还分配了一个替代功能.您可以考虑将这些引脚用作开关,这些开关具有功能/备用功能,并且可以打开或关闭.除了常规功能/标准I/O引脚(GPIO)以外,这些引脚还具有其他功能:(As seen in Figure 4, each pin on the Raspberry pi has a function to do and also an alternate function assigned. You can consider these pins like switches which have a function / Alternate function to do and which can be turned on or off. Apart from the regular function / standard I/O pins (GPIO), the alternate functions these pins have are)GND(地),SPI(串行外围接口总线),I2C(内部集成电路),电源引脚和UART(通用异步接收器/发送器)引脚.(GND (ground), SPI (Serial Peripheral Interface Bus), I2C (inter integrated circuits), power pins and UART (Universal asynchronous receiver /transmitter) pins.)
GPIO编号(GPIO Numbering)
如GPIO引脚图上方的图4所示,它看起来非常复杂和令人困惑,并且没有简单的方法来记住每个引脚,在使用它们时,您需要将打印的参考表保留在顶部.(As seen in Figure 4 above the GPIO pins diagram it seems to be pretty complex and confusing and there is no easy way to remember each of the pins, you need to keep a printed reference sheet on top when using them.)
图4(Figure 4)有一个解决方案,在Raspberry Pi世界中,引用Pin时使用两种不同的编号方案.(There is a solution to this problem and in the Raspberry Pi world, there are two different numbering schemes used when referencing Pins.)
- 使用BCM(Using the BCM)– Broadcom芯片特定的引脚号–示例(– Broadcom chip-specific pin number – example)**GPIO10,GPIO23,GPIO24,(GPIO10, GPIO23, GPIO24,)**等等(etc.)
- 物理编号(Physical numbering)–每个数字均基于引脚的物理位置. ((– where each number is based on the physical position of the pin. ()垂直握住Raspberry Pi,使引脚垂直位于您的第一行,然后从左上方开始将其作为引脚1,将下一个引脚作为2在第一行中进行计数,将低于1的引脚视为3,将低于2的引脚视为4,依此类推(Hold the Raspberry Pi up facing you vertically with the pins on the right side, then start counting from top left as pin 1 and next pin as 2 on the first row and the pin below 1 as 3 and below 2 as 4 and so on)).().)
图5图6(Figure 5 Figure 6)注意(Note):您可以自由使用上述任何GPIO编号系统,但在程序(如Python或C#)中调用GPIO引脚时,您的代码应引用将要使用的编号系统之一.(: You are free to use any of the above GPIO numbering systems, but while invoking the GPIO pins in programs (like Python or C#), your code should reference one of the numbering systems you are going to use.) Python程序中的示例–代码如下所示:(Example in a Python program – code looks like this:)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.OUT)
GPIO.BOARD
–是物理编号系统,并且(– is the physical numbering system and) GPIO.BCM
是Broadcom号码系统.(is the Broadcom number system.)
在下一篇文章中,我们将讨论每种Raspberry Pi模型的区别以及优缺点.(In the next article, we will talk about the difference in each of the Raspberry Pi models and the pros and cons.)
如果您不懂上述代码,请不要担心.我们将在以后的文章中了解所有相关信息.(Don’t worry if you don’t understand the above code. We will learn all about it in future articles.)
**重要警告(Important Warning)**:(:)在直接通过线(称为跨接电缆)连接设备时,请注意GPIO引脚-如果这些线连接到错误的引脚,可能会损坏Pi板,因此在将线直接连接到引脚之前,请仔细阅读说明.(You have to be careful when connecting devices, the GPIO pins directly with wires (called jumper cables)- if these wires are connected to wrong pins, it might damage the Pi board, so please read the instructions carefully before connecting wires directly to the pins.)
我强烈建议使用面包板–您可以在面包板上创建虚拟电路,然后仅连接到Pi上所需的引脚.我还建议使用"分支电路"将Raspberry Pi与面包板连接.一端的分支板连接到Raspberry Pi,另一端连接到面包板.(I would highly recommend using a Breadboard – where you can create the dummy circuits on the breadboard and then connect only to the required pins on the Pi. I would also recommend using a “breakout circuit” to connect the Raspberry Pi with breadboard. One end breakout board is connected to the Raspberry Pi and the other end into the breadboard.)
本文发表在我的网站上–(This article was published on my website –) 侯赛因帕特尔(hussainpatel) .(.)
参考文献(References)
- 微软物联网(Microsoft IoT)
- raspberrypi.org(Raspberry Pi Org) 在下一篇文章中,我们将讨论面包板并制作第一个电路.(In the next article, we would talk about Breadboard and make our first circuit.) 希望这可以帮助.请留下您的意见和反馈.(Hope this helps. Please leave your comments and feedback.) 学习愉快!制作愉快!(Happy learning! Happy making!)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
Raspberry 新闻 翻译