Difference between revisions of "WiringPi-Python for RK3399"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
 
(2 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
<br />
 
<br />
 
Current version: 2.44<br />
 
Current version: 2.44<br />
WiringPi项目主页: http://wiringpi.com<br />
+
WiringPi's home page: http://wiringpi.com<br />
 
<br />
 
<br />
wiringPi的C语言版本,请前往这里查看: [[WiringPi for RK3399/zh]]<br />
+
There is a C version too and here is the reference link: [[WiringPi for RK3399]]<br />
  
==支持的OS==
+
==Supported OS==
 
* FriendlyCore
 
* FriendlyCore
 
* FriendlyDesktop
 
* FriendlyDesktop
  
==支持的开发板==
+
==Supported Boards==
 
* NanoPC T4
 
* NanoPC T4
* NanoPi M4
+
* NanoPi M4/M4v2/M4B
 
* NanoPi NEO4
 
* NanoPi NEO4
  
==wiringPi for Python在T4/M4/NEO4上的安装==
+
==Install WiringPi for Python on T4/M4/NEO4==
通过ssh,或者串口终端进入开发板的命令行,然后根据你所用的Python版本,在命令行下安装: <br />
+
Log in a board(T4/M4/NEO4) via SSH and run the following commands:<br />
===Python3安装方法===
+
===Install WiringPi in Python3===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
apt install git python-dev python-setuptools python3-dev python3-setuptools swig
 
apt install git python-dev python-setuptools python3-dev python3-setuptools swig
Line 28: Line 28:
 
cd setuptools-33.1.1
 
cd setuptools-33.1.1
 
python3 setup.py install
 
python3 setup.py install
wget http://112.124.9.243:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py3.6-linux-aarch64.egg
+
wget http://112.124.9.243/wiringpi/rk3399/wiringpi-2.44.4-py3.6-linux-aarch64.egg
 
easy_install wiringpi-2.44.4-py3.6-linux-aarch64.egg
 
easy_install wiringpi-2.44.4-py3.6-linux-aarch64.egg
 
</syntaxhighlight>
 
</syntaxhighlight>
===Python2安装方法===
+
 
 +
===Install WiringPi in Python2===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
wget https://pypi.io/packages/source/s/setuptools/setuptools-33.1.1.zip
 
wget https://pypi.io/packages/source/s/setuptools/setuptools-33.1.1.zip
Line 37: Line 38:
 
cd setuptools-33.1.1
 
cd setuptools-33.1.1
 
python2 setup.py install
 
python2 setup.py install
wget http://112.124.9.243:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py2.7-linux-aarch64.egg
+
wget http://112.124.9.243/wiringpi/rk3399/wiringpi-2.44.4-py2.7-linux-aarch64.egg
 
easy_install-2.7 wiringpi-2.44.4-py2.7-linux-aarch64.egg
 
easy_install-2.7 wiringpi-2.44.4-py2.7-linux-aarch64.egg
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==wiringPi for Python示例==
+
==Code Samples Using wiringPi for Python==
将一个[[Matrix - LED]]通过连接至开发板,引脚的连接对应如下:<br />
+
Connect a [[Matrix - LED]] module to your board and make sure the hardware setting is as follows:<br />
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|Matrix-LED || T4/M4/NEO4开发板
+
|Matrix-LED || T4/M4/NEO4
 
|-
 
|-
 
|S    || Pin7
 
|S    || Pin7
Line 54: Line 55:
 
|}
 
|}
  
接下来我们用wiringPi实现一个LED闪烁的例子, <br />
+
Here is a code sample showing how to make an LED blink using wiringPi,<br />
在代码中使用数字7来操作Pin7这个引脚: <br />
+
In the code sample '7' stands for 'Pin7':<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 the following lines:
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
 
import wiringpi as wpi
 
import wiringpi as wpi
Line 76: Line 77:
 
     time.sleep(1)
 
     time.sleep(1)
 
</syntaxhighlight>
 
</syntaxhighlight>
运行:
+
Run:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
python3 led.py  
 
python3 led.py  
 
</syntaxhighlight>
 
</syntaxhighlight>
看到LED灯一闪一闪的,就表示成功了,如果你使用的是python2,请将python3改成python2。
+
If everything is correct you will observe that the LED blinks. Note: if you use Python2 instead of Python3 make changes in the above commands accordingly.
 
+
  
=== C语言的示例 ===
+
===Code Sample in C===
请前往这里查看: [[WiringPi for RK3399/zh]]
+
Here is the reference link: [[WiringPi for RK3399/zh]]
  
==更新日志==
+
==Update Log==
===2018-11-10===
+
===November-14-2018===
首次发布
+
* Released English Version

Latest revision as of 06:49, 6 September 2023

查看中文

1 Introduction to WiringPi for Python

The wiringPi for Python utility is an implementation of wiringPi in Python. It can be used in Python programs to access hardware such as GPIO/I2C/SPI/UART/PWM etc. It is a popular and powerful utility.
FriendlyELEC has ported the wiringPi for Python utility for all existing FriendlyELEC-RK3399 based boards: NanoPi M4, NanoPi NEO4 and NanoPC-T4.

Current version: 2.44
WiringPi's home page: http://wiringpi.com

There is a C version too and here is the reference link: WiringPi for RK3399

2 Supported OS

  • FriendlyCore
  • FriendlyDesktop

3 Supported Boards

  • NanoPC T4
  • NanoPi M4/M4v2/M4B
  • NanoPi NEO4

4 Install WiringPi for Python on T4/M4/NEO4

Log in a board(T4/M4/NEO4) via SSH and run the following commands:

4.1 Install WiringPi in Python3

apt install git python-dev python-setuptools python3-dev python3-setuptools swig
wget https://pypi.io/packages/source/s/setuptools/setuptools-33.1.1.zip
unzip setuptools-33.1.1.zip
cd setuptools-33.1.1
python3 setup.py install
wget http://112.124.9.243/wiringpi/rk3399/wiringpi-2.44.4-py3.6-linux-aarch64.egg
easy_install wiringpi-2.44.4-py3.6-linux-aarch64.egg

4.2 Install WiringPi in Python2

wget https://pypi.io/packages/source/s/setuptools/setuptools-33.1.1.zip
unzip setuptools-33.1.1.zip
cd setuptools-33.1.1
python2 setup.py install
wget http://112.124.9.243/wiringpi/rk3399/wiringpi-2.44.4-py2.7-linux-aarch64.egg
easy_install-2.7 wiringpi-2.44.4-py2.7-linux-aarch64.egg

5 Code Samples Using wiringPi for Python

Connect a Matrix - LED module to your board and make sure the hardware setting is as follows:

Matrix-LED T4/M4/NEO4
S Pin7
V Pin4
G Pin6

Here is a code sample showing how to make an LED blink using wiringPi,
In the code sample '7' stands for 'Pin7':

5.1 Code Sample in Python

Create a source file in Python:

vi led.py

Type the following lines:

import wiringpi as wpi
import time
 
wpi.wiringPiSetup()
wpi.pinMode(7, 1)
 
while True:
    wpi.digitalWrite(7, 1)
    time.sleep(1)
    wpi.digitalWrite(7, 0)
    time.sleep(1)

Run:

python3 led.py

If everything is correct you will observe that the LED blinks. Note: if you use Python2 instead of Python3 make changes in the above commands accordingly.

5.2 Code Sample in C

Here is the reference link: WiringPi for RK3399/zh

6 Update Log

6.1 November-14-2018

  • Released English Version