後來谷歌聽聞人家說可以用
/mraa
Linux Library for low speed IO Communication in C with bindings for C++, Python, Node.js & Java. Supports generic io platforms, as well as Intel Edison, Intel Joule, Raspberry Pi and many more. http://mraa.io
libmraa – Low Level Skeleton Library for Communication on GNU/Linux platforms
Libmraa is a C/C++ library with bindings to Java, Python and JavaScript to interface with the IO on Galileo, Edison & other platforms, with a structured and sane API where port names/numbering matches the board that you are on. Use of libmraa does not tie you to specific hardware with board detection done at runtime you can create portable code that will work across the supported platforms.
The intent is to make it easier for developers and sensor manufacturers to map their sensors & actuators on top of supported hardware and to allow control of low level communication protocol by high level languages & constructs.
Installing on Ubuntu
Here is a PPA for installing on ubuntu: https://launchpad.net/~mraa/+archive/ubuntu/mraa
sudo add-apt-repository ppa:mraa/mraa sudo apt-get update sudo apt-get install libmraa1 libmraa-dev libmraa-java python-mraa python3-mraa node-mraa mraa-tools
Running MRAA tools or applications on Ubuntu systems requires elevated permissions (e.g. run with sudo
).
的哩!彷彿文件讀來不習慣呦?
Welcome to mraa’s documentation!
Libmraa is a C/C++ library with bindings to Python, Javascript and Java to interface with the I/O on Galileo, Edison & other platforms, with a structured and sane API where port names/numbering matches the board that you are on. Use of libmraa does not tie you to specific hardware with board detection done at runtime you can create portable code that will work across the supported platforms.
The intent is to make it easier for developers and sensor manufacturers to map their sensors & actuators on top of supported hardware and to allow control of low level communication protocol by high level languages & constructs.
………
不得已只能自己編譯 ubilinux 之
/RPi.GPIO
RPi.GPIO for UP UP^2 board
This package provides a class to control the GPIO on a Raspberry Pi, ported to work on the UP board hardware. Note that this module is unsuitable for real-time or timing critical applications. This is because you can not predict when Python will be busy garbage collecting. It also runs under the Linux kernel which is not suitable for real time applications - it is multitasking O/S and another process may be given priority over the CPU, causing jitter in your program. If you are after true real-time performance and predictability, buy yourself an Arduino http://www.arduino.cc ! Note that the current release does not support SPI, I2C, hardware PWM or serial functionality on the RPi yet. This is planned for the near future - watch this space! One-wire functionality is also planned. Although hardware PWM is not available yet, software PWM is available to use on all channels. For examples and documentation, visit http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/
勒★
up@up-UP-CHT01:~ cd RPi.GPIO/ up@up-UP-CHT01:~/RPi.GPIO python3 setup.py build …… up@up-UP-CHT01:~/RPi.GPIO cd
初步驗證 OK 也◎
up@up-UP-CHT01:~$ python3 Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import RPi.GPIO as GPIO >>> import time >>> ledPin = 4 >>> GPIO.setmode(GPIO.BCM) >>> GPIO.setup(ledPin, GPIO.OUT) >>> try: ... while 1: ... GPIO.output(ledPin, GPIO.HIGH) ... time.sleep(0.5) ... GPIO.output(ledPin, GPIO.LOW) ... time.sleep(0.5) ... except KeyboardInterrupt: ... GPIO.cleanup() ... >>>