Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
en:c1_tinkering [2015/11/23 12:20] odroid [Android] |
en:c1_tinkering [2015/12/02 16:19] 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 | ||
+ | |||
+ | 0. Get/setup WiringPi library (//If you already installed WiringPi library, skip this step.//) | ||
+ | <code> | ||
+ | # git clone https://github.com/hardkernel/wiringPi.git | ||
+ | # cd wiringPi | ||
+ | # sudo ./build | ||
+ | </code> | ||
+ | 1. Get/setup WiringPi 2 for Python repository | ||
+ | <code> | ||
+ | # git clone https://github.com/hardkernel/WiringPi2-Python.git | ||
+ | # cd WiringPi2-Python | ||
+ | </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 / adc_unit | ||
+ | for x in leds: | ||
+ | wpi.digitalWrite(x, 0) | ||
+ | |||
+ | for x in xrange(ledPos): | ||
+ | wpi.digitalWrite(leds[x], 1) | ||
</file> | </file> | ||