Difference between revisions of "WiringPi-Python for RK3399"
From FriendlyELEC WiKi
(updated by API) |
|||
Line 1: | Line 1: | ||
[[WiringPi-Python for RK3399/zh|查看中文]] | [[WiringPi-Python for RK3399/zh|查看中文]] | ||
− | + | ==wiringPi for Python简介== | |
+ | wiringPi for Python是wiringPi的Python语言扩展,用于在Python程序中操作GPIO/I2C/SPI库/UART/PWM等硬件资源,功能非常强大。<br /> | ||
+ | FriendlyELEC移植的wiringPi for Python现已支持FriendlyELEC-RK3399平台,目前支持[[NanoPi M4]]、[[NanoPi NEO4]]、和[[NanoPC-T4]]开发板。<br /> | ||
+ | <br /> | ||
+ | 当前提供的WiringPi版本:2.44<br /> | ||
+ | WiringPi项目主页: http://wiringpi.com<br /> | ||
+ | <br /> | ||
+ | wiringPi的C语言版本,请前往这里查看: [[WiringPi for RK3399/zh]]<br /> | ||
+ | |||
+ | ==支持的OS== | ||
+ | * FriendlyCore | ||
+ | * FriendlyDesktop | ||
+ | |||
+ | ==支持的开发板== | ||
+ | * NanoPC T4 | ||
+ | * NanoPi M4 | ||
+ | * NanoPi NEO4 | ||
+ | |||
+ | ==wiringPi for Python在T4/M4/NEO4上的安装== | ||
+ | 通过ssh,或者串口终端进入开发板的命令行,然后根据你所用的Python版本,在命令行下安装: <br /> | ||
+ | ===Python3安装方法=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | 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:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py3.6-linux-aarch64.egg | ||
+ | easy_install wiringpi-2.44.4-py3.6-linux-aarch64.egg | ||
+ | </syntaxhighlight> | ||
+ | ===Python2安装方法=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | 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:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py2.7-linux-aarch64.egg | ||
+ | easy_install-2.7 wiringpi-2.44.4-py2.7-linux-aarch64.egg | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==wiringPi for Python示例== | ||
+ | 将一个[[Matrix - LED]]通过连接至开发板,引脚的连接对应如下:<br /> | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | |Matrix-LED || T4/M4/NEO4开发板 | ||
+ | |- | ||
+ | |S || Pin7 | ||
+ | |- | ||
+ | |V || Pin4 | ||
+ | |- | ||
+ | |G || Pin6 | ||
+ | |} | ||
+ | |||
+ | 接下来我们用wiringPi实现一个LED闪烁的例子, <br /> | ||
+ | 在代码中使用数字7来操作Pin7这个引脚: <br /> | ||
+ | |||
+ | === Python语言示例 === | ||
+ | 创建一个python源文件: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | vi led.py | ||
+ | </syntaxhighlight> | ||
+ | 然后键入如下代码: | ||
+ | <syntaxhighlight lang="python"> | ||
+ | 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) | ||
+ | </syntaxhighlight> | ||
+ | 运行: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | python3 led.py | ||
+ | </syntaxhighlight> | ||
+ | 看到LED灯一闪一闪的,就表示成功了,如果你使用的是python2,请将python3改成python2。 | ||
+ | |||
+ | |||
+ | === C语言的示例 === | ||
+ | 请前往这里查看: [[WiringPi for RK3399/zh]] | ||
+ | |||
+ | ==更新日志== | ||
+ | ===2018-11-10=== | ||
+ | 首次发布 |
Revision as of 06:02, 14 November 2018
Contents
1 wiringPi for Python简介
wiringPi for Python是wiringPi的Python语言扩展,用于在Python程序中操作GPIO/I2C/SPI库/UART/PWM等硬件资源,功能非常强大。
FriendlyELEC移植的wiringPi for Python现已支持FriendlyELEC-RK3399平台,目前支持NanoPi M4、NanoPi NEO4、和NanoPC-T4开发板。
当前提供的WiringPi版本:2.44
WiringPi项目主页: http://wiringpi.com
wiringPi的C语言版本,请前往这里查看: WiringPi for RK3399/zh
2 支持的OS
- FriendlyCore
- FriendlyDesktop
3 支持的开发板
- NanoPC T4
- NanoPi M4
- NanoPi NEO4
4 wiringPi for Python在T4/M4/NEO4上的安装
通过ssh,或者串口终端进入开发板的命令行,然后根据你所用的Python版本,在命令行下安装:
4.1 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:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py3.6-linux-aarch64.egg easy_install wiringpi-2.44.4-py3.6-linux-aarch64.egg
4.2 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:8888/wiringpi/friendlyelec-rk3399/wiringpi-2.44.4-py2.7-linux-aarch64.egg easy_install-2.7 wiringpi-2.44.4-py2.7-linux-aarch64.egg
5 wiringPi for Python示例
将一个Matrix - LED通过连接至开发板,引脚的连接对应如下:
Matrix-LED | T4/M4/NEO4开发板 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
接下来我们用wiringPi实现一个LED闪烁的例子,
在代码中使用数字7来操作Pin7这个引脚:
5.1 Python语言示例
创建一个python源文件:
vi led.py
然后键入如下代码:
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)
运行:
python3 led.py
看到LED灯一闪一闪的,就表示成功了,如果你使用的是python2,请将python3改成python2。
5.2 C语言的示例
请前往这里查看: WiringPi for RK3399/zh
6 更新日志
6.1 2018-11-10
首次发布