Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.
Python is pre-installed in the pcDuino Ubuntu image released after 20130531.
The sample python code can be downloaded from:
https://github.com/pcduino/python-pcduino
ubuntu@ubuntu:~$ git clone https://github.com/pcduino/python-pcduino Cloning into 'python-pcduino'... remote: Counting objects: 81, done. remote: Compressing objects: 100% (43/43), done. remote: Total 81 (delta 30), reused 76 (delta 30) Unpacking objects: 100% (81/81), done. ubuntu@ubuntu:~$
Let’s look around, and what’s inside:
ubuntu@ubuntu:~/python-pcduino$ ls -R .: README.md Samples pcduino setup.py ./Samples: blink_led ./Samples/blink_led: blink_led.py gpio ./Samples/blink_led/gpio: __init__.py __init__.pyc ./pcduino: __init__.py adc.py exceptions.py gpio.py pinmap.py pwm.py
Let’s look at the sample project blink_led. We install Linker kit LED module on D2 on Linker based shield.
The python code is shown below:
ubuntu@ubuntu:~/python-pcduino/Samples/blink_led$ more blink_led.py #!/usr/bin/env python # blink_led.py # gpio test code for pcduino ( http://www.pcduino.com ) # import gpio import time led_pin = "gpio2" def delay(ms): time.sleep(1.0*ms/1000) def setup(): gpio.pinMode(led_pin, gpio.OUTPUT) def loop(): while(1): gpio.digitalWrite(led_pin, gpio.HIGH) delay(200) gpio.digitalWrite(led_pin, gpio.LOW) delay(100) def main(): setup() loop() main()
To execute the code, we run the following command:
ubuntu@ubuntu:~/python-pcduino/Samples/blink_led$ python blink_led.py
We can observe Linker LED module blinking.
Leave a Reply
You must be logged in to post a comment.