教育和學習︰ Up《grade》【七中】

後來谷歌聽聞人家說可以用

/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:~git clone https://github.com/emutex/RPi.GPIO Cloning into 'RPi.GPIO'... remote: Counting objects: 930, done. remote: Total 930 (delta 0), reused 0 (delta 0), pack-reused 930 Receiving objects: 100% (930/930), 580.47 KiB | 116.00 KiB/s, done. Resolving deltas: 100% (582/582), done. Checking connectivity... done. up@up-UP-CHT01:~ cd RPi.GPIO/
up@up-UP-CHT01:~/RPi.GPIOls CHANGELOG.txt                    debian_wheezy  make_deb     RPi       test create_gpio_user_permissions.py  INSTALL.txt    MANIFEST.in  setup.py debian_jessie                    LICENCE.txt    README.txt   source up@up-UP-CHT01:~/RPi.GPIO python3 setup.py build
……
up@up-UP-CHT01:~/RPi.GPIOsudo python3 setup.py install [sudo] password for up:  running install running build running build_py running build_ext running install_lib creating /usr/local/lib/python3.5/dist-packages/RPi copying build/lib.linux-x86_64-3.5/RPi/__init__.py -> /usr/local/lib/python3.5/dist-packages/RPi copying build/lib.linux-x86_64-3.5/RPi/_GPIO.cpython-35m-x86_64-linux-gnu.so -> /usr/local/lib/python3.5/dist-packages/RPi creating /usr/local/lib/python3.5/dist-packages/RPi/GPIO copying build/lib.linux-x86_64-3.5/RPi/GPIO/__init__.py -> /usr/local/lib/python3.5/dist-packages/RPi/GPIO byte-compiling /usr/local/lib/python3.5/dist-packages/RPi/__init__.py to __init__.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/RPi/GPIO/__init__.py to __init__.cpython-35.pyc running install_egg_info Writing /usr/local/lib/python3.5/dist-packages/RPi.GPIO-0.6.3_ubi1.egg-info 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()
... 
>>>