Difference between revisions of "RPi.GPIO : NanoPi NEO/NEO2/Air GPIO Programming with Python"

From FriendlyELEC WiKi
Jump to: navigation, search
(支持RPi.GPIO_NP的开发板型号及固件列表)
(updated by API)
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==RPi.GPIO_NP简介==
+
[[RPi.GPIO : NanoPi NEO/NEO2/Air GPIO Programming with Python/zh|查看中文]]
  
为了更方便地用python来控制GPIO,NanoPi NEO/NEO2的Ubuntu core系统中已经预装了RPi.GPIO。<br />
+
==Introduction to RPi.GPIO_NP==
RPi.GPIO是 RaspberryPi 知名的python类库,其作用主要是用来控制GPIO,我们将它移植到了 NanoPi NEO/NEO2上,并给它起了一个名字叫:RPi.GPIO_NP。<br />
+
RPi.GPIO_NP的接口基本遵循原作RPi.GPIO,所以你可以参考RPi.GPIO的文档:https://pypi.python.org/pypi/RPi.GPIO。<br />
+
  
==RPi.GPIO_NP安装==
+
For users to easily access GPIO with python FriendlyElec integrated RPi.GPIO in the FriendlyCore images for the NanoPi H3/H5.<br/>
 +
RPi.GPIO is a famous library in python for Raspberry Pi. FriendlyElec ported it to the NanoPi H3/H5's FriendlyCore images and renamed it as RPi.GPIO_NP.<br/>
 +
Most RPi.GPIO_NP's APIs are the same as those of RPi.GPIO and you can refer to https://pypi.python.org/pypi/RPi.GPIO for more details.<br/>
  
RPi.GPIO_NP已经预装在 2017/06/05 之后的 Ubuntu core系统中,无需安装。
+
==Install RPi.GPIO_NP==
 +
The RPi.GPIO_NP library is integrated in all the FriendlyCore images that are and will be released after June 5, 2017. Therefore for images released after this date no installation is needed.<br />
 +
Source code:https://github.com/friendlyarm/RPi.GPIO_NP
  
==支持RPi.GPIO_NP的开发板型号及固件列表==
+
==Code Sample with RPi.GPIO_NP==
下表中列出了当前已支持RPi.GPIO_NP的开发板型号,以及对应的固件文件,固件文件位于下载链接的officail-ROMs目录: <br />
+
Here is code sample on how to access a NanoPi NEO2. A [[Matrix - LED]] is connected to a NanoPi NEO2 in the following hardware setup:<br />
 
+
::{| class="wikitable"
+
|-
+
|开发板型号||固件文件名||下载地址1||下载地址2
+
|-
+
|NanoPi NEO2|| nanopi-neo2_ubuntu-core-xenial_4.11.0_YYYYMMDD.img.zip||[https://pan.baidu.com/s/1eRDbeG6 百度盘] ||[https://www.mediafire.com/folder/ah4i6w029912b/NanoPi-NEO2 MediaFire]  
+
|-
+
|NanoPi NEO||nanopi-neo_ubuntu-core-xenial_4.11.0_YYYYMMDD.img.zip||[http://pan.baidu.com/s/1boQFxN5 百度盘]||[https://www.mediafire.com/folder/n5o8ihvqhnf6s/Nanopi-NEO MediaFire]
+
|-
+
|NanoPi NEO Air||nanopi-neo-air_ubuntu-core-xenial_4.11.0_YYYYMMDD.img.zip||[https://pan.baidu.com/s/1kUMRucf 百度盘]||[https://www.mediafire.com/folder/sr5d0qpz774cs/NanoPi-NEO_Air MediaFire]
+
|}
+
 
+
==RPi.GPIO_NP示例==
+
以NanoPi  NEO2为例,将一个[[Matrix - LED]]通过连接至NanoPi  NEO2,像下图这样:<br />
+
 
[[File:WiringNP-LED-Demo.jpg|frameless|300px|WiringNP-LED-Demo]]<br />
 
[[File:WiringNP-LED-Demo.jpg|frameless|300px|WiringNP-LED-Demo]]<br />
其中,引脚的连接对应如下:<br />
+
Pin Connection:<br />
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|Matrix-LED || NanoPi M1
+
|Matrix-LED || NanoPi NEO2
 
|-
 
|-
 
|S    || Pin7
 
|S    || Pin7
Line 38: Line 26:
 
|}
 
|}
  
接下来我们用Python实现一个LED闪烁的例子, <br />
+
The code sample shows how to make an LED blink in Python<br />
在代码中使用数字7来操作Pin7这个引脚,即引脚的编号直接使用物理编号: <br />
+
Pin 7 is accessed in this code sample:<br />
  
=== Python语言示例 ===
+
===Code Sample in Python===
创建一个Python源文件:
+
Create a source file in Python:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
vi led.py
 
vi led.py
 
</syntaxhighlight>
 
</syntaxhighlight>
然后键入如下代码:
+
Type in the following lines:
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
#!/usr/bin/env python
 
#!/usr/bin/env python
Line 61: Line 49:
 
         time.sleep(1)
 
         time.sleep(1)
 
</syntaxhighlight>
 
</syntaxhighlight>
运行led.py:
+
Run led.py:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
chmod +x led.py
 
chmod +x led.py
 
sudo ./led.py
 
sudo ./led.py
 
</syntaxhighlight>
 
</syntaxhighlight>
看到LED灯一闪一闪的,就表示成功了。
+
The LED module will blink if you do everything right.
 +
 
 +
==Update Log==
 +
===June-7-2017===
 +
* Released English Version

Latest revision as of 07:33, 31 March 2023

查看中文

1 Introduction to RPi.GPIO_NP

For users to easily access GPIO with python FriendlyElec integrated RPi.GPIO in the FriendlyCore images for the NanoPi H3/H5.
RPi.GPIO is a famous library in python for Raspberry Pi. FriendlyElec ported it to the NanoPi H3/H5's FriendlyCore images and renamed it as RPi.GPIO_NP.
Most RPi.GPIO_NP's APIs are the same as those of RPi.GPIO and you can refer to https://pypi.python.org/pypi/RPi.GPIO for more details.

2 Install RPi.GPIO_NP

The RPi.GPIO_NP library is integrated in all the FriendlyCore images that are and will be released after June 5, 2017. Therefore for images released after this date no installation is needed.
Source code:https://github.com/friendlyarm/RPi.GPIO_NP

3 Code Sample with RPi.GPIO_NP

Here is code sample on how to access a NanoPi NEO2. A Matrix - LED is connected to a NanoPi NEO2 in the following hardware setup:
WiringNP-LED-Demo
Pin Connection:

Matrix-LED NanoPi NEO2
S Pin7
V Pin4
G Pin6

The code sample shows how to make an LED blink in Python
Pin 7 is accessed in this code sample:

3.1 Code Sample in Python

Create a source file in Python:

vi led.py

Type in the following lines:

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
PIN_NUM = 7
 
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.OUT)
while True:
        GPIO.output(PIN_NUM,True)
        time.sleep(1)
        GPIO.output(PIN_NUM,False)
        time.sleep(1)

Run led.py:

chmod +x led.py
sudo ./led.py

The LED module will blink if you do everything right.

4 Update Log

4.1 June-7-2017

  • Released English Version