Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
en:c1_tinkering [2015/04/30 16:09] codewalker |
en:c1_tinkering [2016/02/25 15:28] brian.kim [Linux] |
||
---|---|---|---|
Line 184: | Line 184: | ||
//------------------------------------------------------------------------------------------------------------ | //------------------------------------------------------------------------------------------------------------ | ||
//------------------------------------------------------------------------------------------------------------ | //------------------------------------------------------------------------------------------------------------ | ||
+ | </file> | ||
+ | |||
+ | == Python example == | ||
+ | * [[https://github.com/hardkernel/WiringPi2-Python|WiringPi2-Python repository for ODROID]] | ||
+ | **Prerequisites**: You must have //python-dev// and //python-setuptools// installed If you manually rebuild the bindings with swig-python wiringpi.i | ||
+ | |||
+ | 1. Get/setup WiringPi 2 for Python repository | ||
+ | <code> | ||
+ | # git clone https://github.com/hardkernel/WiringPi2-Python.git | ||
+ | # cd WiringPi2-Python | ||
+ | # git submodule init | ||
+ | # git submodule update | ||
+ | </code> | ||
+ | |||
+ | 2. Build & install | ||
+ | <code> | ||
+ | # sudo python setup.py install | ||
+ | </code> | ||
+ | |||
+ | 3. Run the example source code | ||
+ | <file python example-led.py> | ||
+ | #!/usr/bin/python | ||
+ | import wiringpi2 as wpi | ||
+ | import time | ||
+ | |||
+ | leds = [24, 23, 22, 21, 14, 13, 12, 3, 2, 0, 7, 1, 4, 5, 6, 10, 26, 11, 27] | ||
+ | |||
+ | wpi.wiringPiSetup() | ||
+ | |||
+ | # GPOI pin setup | ||
+ | for x in leds: | ||
+ | wpi.pinMode(x, 1) | ||
+ | wpi.digitalWrite(x, 0) | ||
+ | |||
+ | adc_unit = 4095 / len(leds) | ||
+ | while True: | ||
+ | time.sleep(0.05) | ||
+ | |||
+ | # Read the adc value | ||
+ | adcValue = wpi.analogRead(0) | ||
+ | |||
+ | # Set the LEDs | ||
+ | ledPos = (adcValue * len(leds) * 1000) / 1024 | ||
+ | ledPos = len(leds) - (ledPos / 1000) | ||
+ | |||
+ | for x in leds: | ||
+ | wpi.digitalWrite(x, 0) | ||
+ | |||
+ | for x in xrange(ledPos): | ||
+ | wpi.digitalWrite(leds[x], 1) | ||
</file> | </file> | ||
Line 411: | Line 461: | ||
</code> | </code> | ||
- | wiringPi의 "/dev/mem"을 open 하여 mmap을 사용하는 방식으로 만들려고 하였으니 "/dev/mem"은 root가 아니면 접근을 제한하도록 되어 있어서 불가능합니다. | + | Korean: wiringPi의 "/dev/mem"을 open 하여 mmap을 사용하는 방식으로 만들려고 하였으니 "/dev/mem"은 root가 아니면 접근을 제한하도록 되어 있어서 불가능합니다. |
jni의 library에는 root 권한을 줄 방법이 없습니다. | jni의 library에는 root 권한을 줄 방법이 없습니다. | ||
- | + | English: It was impossible to access the /dev/mem in the Android platform because only root can access it. | |
+ | There is no way to add a root permission to the JNI library. | ||